Skip to content

Commit

Permalink
修复中文显示不全的问题
Browse files Browse the repository at this point in the history
完成中英文双语支持。
  • Loading branch information
cloudhu committed Nov 18, 2024
1 parent 2ac72dd commit af82268
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 62 deletions.
19 changes: 9 additions & 10 deletions assets/configs/duolingo.csv
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ Shield,防护盾,Shield,护盾
Level,玩家等级,Level,等级
Speed,移动速度,Speed,速度
Time,计时单位,Time,时间
Weapon,武器,Weapon,武器
Weapon,武器,Weapon,武器装备
Passive,被动,Passive,被动效果
Consumable,消耗,Consumable,消耗品
AutoCannonDes,自动炮描述,Rapidly fires bullets towards the target.,自动向目标快速发射子弹
BlastLaserDes,镭射炮,Always hits. Deals low damage.,镭射光子炮可以百分百命中目标,但是伤害较低。
ChainLaser,链击镭射光,ChainLaser,链式镭射炮
AutoCannon,自动炮描述,AutoCannon,自动追踪炮
BlastLaser,镭射炮,BlastLaser,镭射光子炮
Chain Laser,链击镭射光,Chain Laser,链式镭射炮
Auto Cannon,自动炮描述,Auto Cannon,自动追踪炮
Blast Laser,镭射炮,Blast Laser,镭射光子炮
ChainLaserDes,链击镭射光,Shoots a laser that jumps to nearby enemies.,发射激光,命中后跳向目标附近的敌人,对群体目标造成少量伤害。
Emp,电磁脉冲(electromagnetic pulse),Emp,电磁脉冲
EM Pulsar,电磁脉冲(electromagnetic pulse),EM Pulsar,电磁脉冲
EmpDes,电磁脉冲(electromagnetic pulse),Creates a shockwave around you that deals damage to enemies.,在你周围制造冲击波,对敌人造成伤害。
MineLauncher,地雷陷阱,MineLauncher,太空地雷
Mine Launcher,地雷陷阱,Mine Launcher,太空地雷
MineLauncherDes,地雷陷阱,Drops mines that explode when enemies are in close proximity.,投下地雷,当敌人靠近时爆炸。
PierceLaser,Pierce Laser,PierceLaser,激光镭射
Pierce Laser,Pierce Laser,Pierce Laser,激光镭射
PierceLaserDes,穿透攻击镭射激光,Shoots a heavy damaging laser that pierces through enemies.,发射强烈的破坏性激光穿透敌人。
RocketLauncher,火箭攻击,RocketLauncher,火箭导弹
Rocket Launcher,火箭攻击,Rocket Launcher,火箭导弹
RocketLauncherDes,火箭攻击,Shoots a seeking missile that explodes on impact.,发射一枚追踪导弹并在撞击时爆炸。
ShrapnelCannon,Shrapnel Cannon,ShrapnelCannon,弹片加农炮
Shrapnel Cannon,Shrapnel Cannon,Shrapnel Cannon,弹片加农炮
ShrapnelCannonDes,Shrapnel Cannon,Shoots a spray of bullets in a cone towards the target.,向目标射出锥形的子弹喷雾。
ArmorDes,描述,Increase armor by 25.,增加25护甲。
Crit,暴击率属性,Crit,暴击率
Expand All @@ -44,7 +44,6 @@ FireRate,属性,FireRate,发射频率
FireRateDes,描述,Increase turret fire rate by 10%.,增加炮塔射速:10%。
Magnet,属性,Magnet,磁吸
MagnetDes,描述,Increase range and speed of experience magnetism.,增加磁力吸收经验的范围和速度。
ShieldRecharge,属性,ShieldRecharge,护盾充能
ShieldRechargeDes,描述,Decrease shield hit and regeneration cooldown.,减少护盾充能回复冷却时间。
SpeedDes,移动速度,Increase engine power and max speed.,增加发动机功率和最大转速。
HealDes,描述,Restore 50 armor or shields.,恢复50个护甲或护盾。
Expand Down
4 changes: 2 additions & 2 deletions src/gameplay/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use crate::gameplay::upgrade::PlayerUpgrades;
use crate::screens::AppState;
use crate::ship::engine::Engine;
use crate::ship::turret::{FireRate, TurretClass};
use crate::theme::language::Localize;
use crate::util::Colour;
use bevy::prelude::*;
use crate::theme::localize::Localize;

pub(super) fn plugin(app: &mut App) {
app.add_systems(OnEnter(AppState::InGame), setup_hud)
Expand Down Expand Up @@ -173,7 +173,7 @@ pub fn hud_system(
mut q_child: Query<&mut Text>,
level: Res<PlayerLevel>,
game_time: Res<GameTime>,
localize: Res<Localize>
localize: Res<Localize>,
) {
if let Ok((engine, health, cargo, turrets)) = player_query.get_single() {
// Loop over children and update display values
Expand Down
19 changes: 12 additions & 7 deletions src/gameplay/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use crate::gameplay::gamelogic::PlayerLevel;
use crate::gameplay::upgrade::{PlayerUpgrades, UpgradeEvent};
use crate::gameplay::GameState;
use crate::ship::turret::TurretClass;
use crate::theme::language::Localize;
use crate::util::Colour;
use bevy::prelude::*;
use rand::Rng;
use crate::theme::localize::Localize;

#[derive(Resource)]
struct SelectionData(pub Vec<Entity>);
Expand Down Expand Up @@ -90,7 +90,7 @@ fn setup_selection(
mut menu_data: ResMut<SelectionData>,
player_level: Res<PlayerLevel>,
upgrades: Res<PlayerUpgrades>,
localize: Res<Localize>
localize: Res<Localize>,
) {
// Roll for options
let options = match player_level.value {
Expand All @@ -114,7 +114,7 @@ fn setup_selection(
})
.with_children(|parent| {
for option in options {
button(parent, &fonts, option,&localize);
button(parent, &fonts, option, &localize);
}
})
.id();
Expand Down Expand Up @@ -154,7 +154,12 @@ fn cleanup(mut commands: Commands, mut menu_data: ResMut<SelectionData>) {
menu_data.0.clear();
}

fn button(parent: &mut ChildBuilder, fonts: &Res<Fonts>, upgrade: UpgradeEvent,localize:&Res<Localize>) {
fn button(
parent: &mut ChildBuilder,
fonts: &Res<Fonts>,
upgrade: UpgradeEvent,
localize: &Res<Localize>,
) {
let type_text = match upgrade {
UpgradeEvent::Weapon(_) => localize.get("Weapon"),
UpgradeEvent::Passive(_) => localize.get("Passive"),
Expand All @@ -165,7 +170,7 @@ fn button(parent: &mut ChildBuilder, fonts: &Res<Fonts>, upgrade: UpgradeEvent,l
UpgradeEvent::Passive(_) => Colour::SHIELD,
UpgradeEvent::Heal => Colour::GREEN,
};
println!(format!("{}", upgrade));
// println!("{}",format!("{}", upgrade));
parent
.spawn((
ButtonBundle {
Expand Down Expand Up @@ -203,7 +208,7 @@ fn button(parent: &mut ChildBuilder, fonts: &Res<Fonts>, upgrade: UpgradeEvent,l
});
parent.spawn(TextBundle {
text: Text::from_section(
format!("{}", upgrade),
localize.get(format!("{}", upgrade).as_str()),
TextStyle {
font: fonts.primary.clone(),
font_size: 24.0,
Expand All @@ -219,7 +224,7 @@ fn button(parent: &mut ChildBuilder, fonts: &Res<Fonts>, upgrade: UpgradeEvent,l
});
parent.spawn(TextBundle {
text: Text::from_section(
localize.get(&*upgrade.describe()),
localize.get(&upgrade.describe()),
TextStyle {
font: fonts.primary.clone(),
font_size: 14.0,
Expand Down
44 changes: 11 additions & 33 deletions src/gameplay/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,42 +75,20 @@ impl Display for UpgradeEvent {
impl UpgradeEvent {
pub fn describe(&self) -> String {
match self {
UpgradeEvent::Weapon(TurretClass::AutoCannon) => {
"AutoCannonDes"
}
UpgradeEvent::Weapon(TurretClass::AutoCannon) => "AutoCannonDes",
UpgradeEvent::Weapon(TurretClass::BlastLaser) => "BlastLaserDes",
UpgradeEvent::Weapon(TurretClass::ChainLaser) => {
"ChainLaserDes"
}
UpgradeEvent::Weapon(TurretClass::Emp) => {
"EmpDes"
}
UpgradeEvent::Weapon(TurretClass::MineLauncher) => {
"MineLauncherDes"
}
UpgradeEvent::Weapon(TurretClass::PierceLaser) => {
"PierceLaserDes"
}
UpgradeEvent::Weapon(TurretClass::RocketLauncher) => {
"RocketLauncherDes"
}
UpgradeEvent::Weapon(TurretClass::ShrapnelCannon) => {
"ShrapnelCannonDes"
}
UpgradeEvent::Weapon(TurretClass::ChainLaser) => "ChainLaserDes",
UpgradeEvent::Weapon(TurretClass::Emp) => "EmpDes",
UpgradeEvent::Weapon(TurretClass::MineLauncher) => "MineLauncherDes",
UpgradeEvent::Weapon(TurretClass::PierceLaser) => "PierceLaserDes",
UpgradeEvent::Weapon(TurretClass::RocketLauncher) => "RocketLauncherDes",
UpgradeEvent::Weapon(TurretClass::ShrapnelCannon) => "ShrapnelCannonDes",
UpgradeEvent::Passive(Passive::Armor) => "ArmorDes",
UpgradeEvent::Passive(Passive::Crit) => {
"CritDes"
}
UpgradeEvent::Passive(Passive::Experience) => {
"ExperienceDes"
}
UpgradeEvent::Passive(Passive::Crit) => "CritDes",
UpgradeEvent::Passive(Passive::Experience) => "ExperienceDes",
UpgradeEvent::Passive(Passive::FireRate) => "FireRateDes",
UpgradeEvent::Passive(Passive::Magnet) => {
"MagnetDes"
}
UpgradeEvent::Passive(Passive::ShieldRecharge) => {
"ShieldRechargeDes"
}
UpgradeEvent::Passive(Passive::Magnet) => "MagnetDes",
UpgradeEvent::Passive(Passive::ShieldRecharge) => "ShieldRechargeDes",
UpgradeEvent::Passive(Passive::Speed) => "SpeedDes",
UpgradeEvent::Heal => "HealDes",
}
Expand Down
1 change: 0 additions & 1 deletion src/screens/title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use crate::assets::{Fonts, Music};
use crate::audio::NextBgm;
use crate::config::GameConfig;
use crate::theme::localize::Localize;
use crate::{screens::AppState, theme::prelude::*};
use bevy::prelude::*;
use bevy::window::WindowMode;
Expand Down
3 changes: 1 addition & 2 deletions src/theme/interaction.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::assets::AudioAssets;
use crate::config::GameConfig;
use bevy::prelude::*;
use bevy_kira_audio::prelude::Volume;
use bevy_kira_audio::{Audio, AudioControl};
use bevy_kira_audio::prelude::*;

pub(super) fn plugin(app: &mut App) {
app.register_type::<InteractionPalette>();
Expand Down
6 changes: 3 additions & 3 deletions src/theme/localize.rs → src/theme/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ pub(super) fn plugin(app: &mut App) {
///
/// 1. Load from file
/// ```
/// use bevy::prelude::*;
/// //use bevy::prelude::*;
///
/// pub(super) fn plugin(app: &mut App) {
/// //pub(super) fn plugin(app: &mut App) {
/// //app.insert_resource(Localize::from_data(&std::fs::read_to_string("test.csv").unwrap()));
/// }
/// //}
/// ```
/// This way makes sure that the
/// resource will be completely initialized
Expand Down
5 changes: 3 additions & 2 deletions src/theme/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
#![allow(dead_code)]

pub mod interaction;
pub mod localize;
pub mod language;
pub mod palette;
mod widgets;

#[allow(unused_imports)]
pub mod prelude {
pub use super::{
interaction::{InteractionPalette, OnPress},
language::{Localize, LocalizeText},
palette as ui_palette,
widgets::{Containers as _, Widgets as _},
};
Expand All @@ -20,5 +21,5 @@ pub mod prelude {
use bevy::prelude::*;

pub(super) fn plugin(app: &mut App) {
app.add_plugins((localize::plugin, interaction::plugin));
app.add_plugins((language::plugin, interaction::plugin));
}
3 changes: 1 addition & 2 deletions src/theme/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
use bevy::{ecs::system::EntityCommands, prelude::*, ui::Val::*};

use crate::theme::localize::LocalizeText;
use crate::theme::{interaction::InteractionPalette, palette::*};
use crate::theme::{interaction::InteractionPalette, language::LocalizeText, palette::*};

/// An extension trait for spawning UI widgets.
pub trait Widgets {
Expand Down

0 comments on commit af82268

Please sign in to comment.