feat: localize difficulty name in save menu
This commit is contained in:
parent
9c95b20f5c
commit
a5930637c8
|
@ -40,7 +40,9 @@
|
||||||
"title": "Select Difficulty",
|
"title": "Select Difficulty",
|
||||||
"easy": "Easy",
|
"easy": "Easy",
|
||||||
"normal": "Normal",
|
"normal": "Normal",
|
||||||
"hard": "Hard"
|
"hard": "Hard",
|
||||||
|
"difficulty_name": "Difficulty: ",
|
||||||
|
"unknown": "(unknown)"
|
||||||
},
|
},
|
||||||
"coop_menu": {
|
"coop_menu": {
|
||||||
"title": "Select Number of Players",
|
"title": "Select Number of Players",
|
||||||
|
|
|
@ -40,7 +40,9 @@
|
||||||
"title": "難易度選択",
|
"title": "難易度選択",
|
||||||
"easy": "簡単",
|
"easy": "簡単",
|
||||||
"normal": "普通",
|
"normal": "普通",
|
||||||
"hard": "難しい"
|
"hard": "難しい",
|
||||||
|
"difficulty_name": "難易度: ",
|
||||||
|
"unknown": "(未知)"
|
||||||
},
|
},
|
||||||
"coop_menu": {
|
"coop_menu": {
|
||||||
"title": "プレイヤー数を選択",
|
"title": "プレイヤー数を選択",
|
||||||
|
|
|
@ -17,11 +17,7 @@ impl Default for Locale {
|
||||||
Locale {
|
Locale {
|
||||||
code: "en".to_owned(),
|
code: "en".to_owned(),
|
||||||
name: "English".to_owned(),
|
name: "English".to_owned(),
|
||||||
font: FontData {
|
font: FontData { path: String::new(), scale: 1.0, space_offset: 0.0 },
|
||||||
path: String::new(),
|
|
||||||
scale: 1.0,
|
|
||||||
space_offset: 0.0
|
|
||||||
},
|
|
||||||
strings: HashMap::new(),
|
strings: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,6 +61,7 @@ impl Locale {
|
||||||
strings
|
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 {
|
pub fn t<'a: 'b, 'b>(&'a self, key: &'b str) -> &'b str {
|
||||||
if let Some(str) = self.strings.get(key) {
|
if let Some(str) = self.strings.get(key) {
|
||||||
str
|
str
|
||||||
|
|
|
@ -7,6 +7,7 @@ use crate::framework::error::GameResult;
|
||||||
use crate::framework::graphics;
|
use crate::framework::graphics;
|
||||||
use crate::game::shared_game_state::{GameDifficulty, MenuCharacter, SharedGameState};
|
use crate::game::shared_game_state::{GameDifficulty, MenuCharacter, SharedGameState};
|
||||||
use crate::graphics::font::Font;
|
use crate::graphics::font::Font;
|
||||||
|
use crate::i18n::Locale;
|
||||||
use crate::input::combined_menu_controller::CombinedMenuController;
|
use crate::input::combined_menu_controller::CombinedMenuController;
|
||||||
use crate::menu::save_select_menu::MenuSaveInfo;
|
use crate::menu::save_select_menu::MenuSaveInfo;
|
||||||
|
|
||||||
|
@ -594,23 +595,21 @@ impl<T: std::cmp::PartialEq + std::default::Default + Clone> Menu<T> {
|
||||||
|
|
||||||
graphics::draw_rect(ctx, bar_rect, Color::new(1.0, 1.0, 1.0, 1.0))?;
|
graphics::draw_rect(ctx, bar_rect, Color::new(1.0, 1.0, 1.0, 1.0))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
{
|
{
|
||||||
state
|
state.font.builder().x(self.x as f32 - 25.0).y(y).shadow(true).draw(
|
||||||
.font
|
"<",
|
||||||
.builder()
|
ctx,
|
||||||
.x(self.x as f32 - 25.0)
|
&state.constants,
|
||||||
.y(y)
|
&mut state.texture_set,
|
||||||
.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(
|
||||||
state
|
">",
|
||||||
.font
|
ctx,
|
||||||
.builder()
|
&state.constants,
|
||||||
.x((self.x + self.width as isize) as f32 + 15.0)
|
&mut state.texture_set,
|
||||||
.y(y)
|
)?;
|
||||||
.shadow(true)
|
|
||||||
.draw(">", ctx, &state.constants, &mut state.texture_set)?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MenuEntry::NewSave => {
|
MenuEntry::NewSave => {
|
||||||
|
@ -677,13 +676,44 @@ impl<T: std::cmp::PartialEq + std::default::Default + Clone> Menu<T> {
|
||||||
);
|
);
|
||||||
batch.draw(ctx)?;
|
batch.draw(ctx)?;
|
||||||
} else {
|
} else {
|
||||||
let mut difficulty_name: String = "Difficulty: ".to_owned();
|
fn translate_fallback<'l: 'a, 'a>(
|
||||||
|
loc: &'l Locale,
|
||||||
|
key: &'a str,
|
||||||
|
fallback: &'a str,
|
||||||
|
) -> &'a str {
|
||||||
|
let result = loc.t(key);
|
||||||
|
if result == key {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
let loc = &state.loc;
|
||||||
|
let mut difficulty_name =
|
||||||
|
translate_fallback(loc, "menus.difficulty_menu.difficulty_name", "Difficulty: ")
|
||||||
|
.to_owned();
|
||||||
|
|
||||||
match save.difficulty {
|
match save.difficulty {
|
||||||
0 => difficulty_name.push_str("Normal"),
|
0 => difficulty_name.push_str(translate_fallback(
|
||||||
2 => difficulty_name.push_str("Easy"),
|
loc,
|
||||||
4 => difficulty_name.push_str("Hard"),
|
"menus.difficulty_menu.normal",
|
||||||
_ => difficulty_name.push_str("(unknown)"),
|
"Normal",
|
||||||
|
)),
|
||||||
|
2 => difficulty_name.push_str(translate_fallback(
|
||||||
|
loc,
|
||||||
|
"menus.difficulty_menu.easy",
|
||||||
|
"Easy",
|
||||||
|
)),
|
||||||
|
4 => difficulty_name.push_str(translate_fallback(
|
||||||
|
loc,
|
||||||
|
"menus.difficulty_menu.hard",
|
||||||
|
"Hard",
|
||||||
|
)),
|
||||||
|
_ => difficulty_name.push_str(translate_fallback(
|
||||||
|
loc,
|
||||||
|
"menus.difficulty_menu.unknown",
|
||||||
|
"(unknown)",
|
||||||
|
)),
|
||||||
}
|
}
|
||||||
|
|
||||||
state.font.builder().position(self.x as f32 + 20.0, y + 10.0).draw(
|
state.font.builder().position(self.x as f32 + 20.0, y + 10.0).draw(
|
||||||
|
@ -770,11 +800,7 @@ impl<T: std::cmp::PartialEq + std::default::Default + Clone> Menu<T> {
|
||||||
state: &mut SharedGameState,
|
state: &mut SharedGameState,
|
||||||
) -> MenuSelectionResult<T> {
|
) -> MenuSelectionResult<T> {
|
||||||
// the engine does 4 times more ticks during cutscene skipping
|
// the engine does 4 times more ticks during cutscene skipping
|
||||||
let max_anim_wait = if state.textscript_vm.flags.cutscene_skip() {
|
let max_anim_wait = if state.textscript_vm.flags.cutscene_skip() { 32 } else { 8 };
|
||||||
32
|
|
||||||
} else {
|
|
||||||
8
|
|
||||||
};
|
|
||||||
|
|
||||||
self.anim_wait += 1;
|
self.anim_wait += 1;
|
||||||
if self.anim_wait > max_anim_wait {
|
if self.anim_wait > max_anim_wait {
|
||||||
|
|
Loading…
Reference in New Issue