From af82268f92eb58e08ea20938a0ef40cc3a763a8b Mon Sep 17 00:00:00 2001 From: Cloud Hu Date: Mon, 18 Nov 2024 10:15:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=AD=E6=96=87=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E4=B8=8D=E5=85=A8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 完成中英文双语支持。 --- assets/configs/duolingo.csv | 19 ++++++----- src/gameplay/hud.rs | 4 +-- src/gameplay/selection.rs | 19 +++++++---- src/gameplay/upgrade.rs | 44 +++++++------------------- src/screens/title.rs | 1 - src/theme/interaction.rs | 3 +- src/theme/{localize.rs => language.rs} | 6 ++-- src/theme/mod.rs | 5 +-- src/theme/widgets.rs | 3 +- 9 files changed, 42 insertions(+), 62 deletions(-) rename src/theme/{localize.rs => language.rs} (99%) diff --git a/assets/configs/duolingo.csv b/assets/configs/duolingo.csv index 5d66611..2e07131 100644 --- a/assets/configs/duolingo.csv +++ b/assets/configs/duolingo.csv @@ -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,暴击率 @@ -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个护甲或护盾。 diff --git a/src/gameplay/hud.rs b/src/gameplay/hud.rs index 657ede8..f56f3cd 100644 --- a/src/gameplay/hud.rs +++ b/src/gameplay/hud.rs @@ -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) @@ -173,7 +173,7 @@ pub fn hud_system( mut q_child: Query<&mut Text>, level: Res, game_time: Res, - localize: Res + localize: Res, ) { if let Ok((engine, health, cargo, turrets)) = player_query.get_single() { // Loop over children and update display values diff --git a/src/gameplay/selection.rs b/src/gameplay/selection.rs index 98a69dc..9281564 100644 --- a/src/gameplay/selection.rs +++ b/src/gameplay/selection.rs @@ -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); @@ -90,7 +90,7 @@ fn setup_selection( mut menu_data: ResMut, player_level: Res, upgrades: Res, - localize: Res + localize: Res, ) { // Roll for options let options = match player_level.value { @@ -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(); @@ -154,7 +154,12 @@ fn cleanup(mut commands: Commands, mut menu_data: ResMut) { menu_data.0.clear(); } -fn button(parent: &mut ChildBuilder, fonts: &Res, upgrade: UpgradeEvent,localize:&Res) { +fn button( + parent: &mut ChildBuilder, + fonts: &Res, + upgrade: UpgradeEvent, + localize: &Res, +) { let type_text = match upgrade { UpgradeEvent::Weapon(_) => localize.get("Weapon"), UpgradeEvent::Passive(_) => localize.get("Passive"), @@ -165,7 +170,7 @@ fn button(parent: &mut ChildBuilder, fonts: &Res, upgrade: UpgradeEvent,l UpgradeEvent::Passive(_) => Colour::SHIELD, UpgradeEvent::Heal => Colour::GREEN, }; - println!(format!("{}", upgrade)); + // println!("{}",format!("{}", upgrade)); parent .spawn(( ButtonBundle { @@ -203,7 +208,7 @@ fn button(parent: &mut ChildBuilder, fonts: &Res, 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, @@ -219,7 +224,7 @@ fn button(parent: &mut ChildBuilder, fonts: &Res, 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, diff --git a/src/gameplay/upgrade.rs b/src/gameplay/upgrade.rs index 9b4a71a..316c380 100644 --- a/src/gameplay/upgrade.rs +++ b/src/gameplay/upgrade.rs @@ -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", } diff --git a/src/screens/title.rs b/src/screens/title.rs index 81db3ca..4ee7666 100644 --- a/src/screens/title.rs +++ b/src/screens/title.rs @@ -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; diff --git a/src/theme/interaction.rs b/src/theme/interaction.rs index fcf5bde..5a53db1 100644 --- a/src/theme/interaction.rs +++ b/src/theme/interaction.rs @@ -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::(); diff --git a/src/theme/localize.rs b/src/theme/language.rs similarity index 99% rename from src/theme/localize.rs rename to src/theme/language.rs index aa9236e..6d526d0 100644 --- a/src/theme/localize.rs +++ b/src/theme/language.rs @@ -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 diff --git a/src/theme/mod.rs b/src/theme/mod.rs index afa66d9..7586ee1 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -4,7 +4,7 @@ #![allow(dead_code)] pub mod interaction; -pub mod localize; +pub mod language; pub mod palette; mod widgets; @@ -12,6 +12,7 @@ mod widgets; pub mod prelude { pub use super::{ interaction::{InteractionPalette, OnPress}, + language::{Localize, LocalizeText}, palette as ui_palette, widgets::{Containers as _, Widgets as _}, }; @@ -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)); } diff --git a/src/theme/widgets.rs b/src/theme/widgets.rs index ae929f7..0d40f79 100644 --- a/src/theme/widgets.rs +++ b/src/theme/widgets.rs @@ -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 {