Merge branch 'juliancoffee/i18n_sprites' into 'master'

Localization for sprite overitem (currenly only crafting stations)

See merge request veloren/veloren!2759
This commit is contained in:
Marcel 2021-08-10 23:17:25 +00:00
commit 631b4747d9

View File

@ -1665,8 +1665,7 @@ impl Hud {
.set(overitem_id, ui_widgets);
} else if let Some(sprite) = block.get_sprite() {
overitem::Overitem::new(
format!("{:?}", sprite).into(), /* TODO: A better way to generate text
* for this */
get_sprite_desc(sprite, i18n),
overitem::TEXT_COLOR,
pos.distance_squared(player_pos),
&self.fonts,
@ -4055,6 +4054,21 @@ pub fn get_buff_desc(buff: BuffKind, data: BuffData, localized_strings: &Localiz
}
}
pub fn get_sprite_desc(sprite: SpriteKind, localized_strings: &Localization) -> Cow<str> {
let i18n_key = match sprite {
SpriteKind::Anvil => "hud.crafting.anvil",
SpriteKind::Cauldron => "hud.crafting.cauldron",
SpriteKind::CookingPot => "hud.crafting.cooking_pot",
SpriteKind::CraftingBench => "hud.crafting.crafting_bench",
SpriteKind::Forge => "hud.crafting.forge",
SpriteKind::Loom => "hud.crafting.loom",
SpriteKind::SpinningWheel => "hud.crafting.spinning_wheel",
SpriteKind::TanningRack => "hud.crafting.tanning_rack",
sprite => return Cow::Owned(format!("{:?}", sprite)),
};
Cow::Borrowed(localized_strings.get(i18n_key))
}
pub fn get_buff_time(buff: BuffInfo) -> String {
if let Some(dur) = buff.dur {
format!("{:.0}s", dur.as_secs_f32())