From 08f086bfc4244b5f3cf2de0a42fdfded9acbd243 Mon Sep 17 00:00:00 2001 From: poly000 <1348292515@qq.com> Date: Mon, 25 Mar 2024 19:41:21 +0800 Subject: [PATCH] localize difficulty name in save menu (#263) --- src/data/builtin/builtin_data/locale/en.json | 4 +- src/data/builtin/builtin_data/locale/jp.json | 4 +- src/i18n.rs | 7 +-- src/menu/mod.rs | 52 +++++++++----------- 4 files changed, 31 insertions(+), 36 deletions(-) diff --git a/src/data/builtin/builtin_data/locale/en.json b/src/data/builtin/builtin_data/locale/en.json index 9c5285c..ffc076c 100644 --- a/src/data/builtin/builtin_data/locale/en.json +++ b/src/data/builtin/builtin_data/locale/en.json @@ -40,7 +40,9 @@ "title": "Select Difficulty", "easy": "Easy", "normal": "Normal", - "hard": "Hard" + "hard": "Hard", + "difficulty_name": "Difficulty: {difficulty}", + "unknown": "(unknown)" }, "coop_menu": { "title": "Select Number of Players", diff --git a/src/data/builtin/builtin_data/locale/jp.json b/src/data/builtin/builtin_data/locale/jp.json index 271a964..cd70025 100644 --- a/src/data/builtin/builtin_data/locale/jp.json +++ b/src/data/builtin/builtin_data/locale/jp.json @@ -40,7 +40,9 @@ "title": "難易度選択", "easy": "簡単", "normal": "普通", - "hard": "難しい" + "hard": "難しい", + "difficulty_name": "難易度: {difficulty}", + "unknown": "(未知)" }, "coop_menu": { "title": "プレイヤー数を選択", diff --git a/src/i18n.rs b/src/i18n.rs index 0306597..b933029 100644 --- a/src/i18n.rs +++ b/src/i18n.rs @@ -17,11 +17,7 @@ impl Default for Locale { Locale { code: "en".to_owned(), name: "English".to_owned(), - font: FontData { - path: String::new(), - scale: 1.0, - space_offset: 0.0 - }, + font: FontData { path: String::new(), scale: 1.0, space_offset: 0.0 }, strings: HashMap::new(), } } @@ -65,6 +61,7 @@ impl Locale { strings } + /// if the key does not exists, return the origin key instead pub fn t<'a: 'b, 'b>(&'a self, key: &'b str) -> &'b str { if let Some(str) = self.strings.get(key) { str diff --git a/src/menu/mod.rs b/src/menu/mod.rs index cf75aa3..b3ef1e0 100644 --- a/src/menu/mod.rs +++ b/src/menu/mod.rs @@ -594,23 +594,21 @@ impl Menu { graphics::draw_rect(ctx, bar_rect, Color::new(1.0, 1.0, 1.0, 1.0))?; } - + #[cfg(target_os = "android")] { - state - .font - .builder() - .x(self.x as f32 - 25.0) - .y(y) - .shadow(true) - .draw("<", ctx, &state.constants, &mut state.texture_set)?; - state - .font - .builder() - .x((self.x + self.width as isize) as f32 + 15.0) - .y(y) - .shadow(true) - .draw(">", ctx, &state.constants, &mut state.texture_set)?; + state.font.builder().x(self.x as f32 - 25.0).y(y).shadow(true).draw( + "<", + ctx, + &state.constants, + &mut state.texture_set, + )?; + state.font.builder().x((self.x + self.width as isize) as f32 + 15.0).y(y).shadow(true).draw( + ">", + ctx, + &state.constants, + &mut state.texture_set, + )?; } } MenuEntry::NewSave => { @@ -677,17 +675,17 @@ impl Menu { ); batch.draw(ctx)?; } else { - let mut difficulty_name: String = "Difficulty: ".to_owned(); - - match save.difficulty { - 0 => difficulty_name.push_str("Normal"), - 2 => difficulty_name.push_str("Easy"), - 4 => difficulty_name.push_str("Hard"), - _ => difficulty_name.push_str("(unknown)"), - } + let difficulty = match save.difficulty { + 0 => state.loc.t("menus.difficulty_menu.normal"), + 2 => state.loc.t("menus.difficulty_menu.easy"), + 4 => state.loc.t("menus.difficulty_menu.hard"), + _ => state.loc.t("menus.difficulty_menu.unknown"), + }; + let difficulty_name = + state.loc.tt("menus.difficulty_menu.difficulty_name", &[("difficulty", &difficulty)]); state.font.builder().position(self.x as f32 + 20.0, y + 10.0).draw( - difficulty_name.as_str(), + &difficulty_name, ctx, &state.constants, &mut state.texture_set, @@ -770,11 +768,7 @@ impl Menu { state: &mut SharedGameState, ) -> MenuSelectionResult { // the engine does 4 times more ticks during cutscene skipping - let max_anim_wait = if state.textscript_vm.flags.cutscene_skip() { - 32 - } else { - 8 - }; + let max_anim_wait = if state.textscript_vm.flags.cutscene_skip() { 32 } else { 8 }; self.anim_wait += 1; if self.anim_wait > max_anim_wait {