From bf3e58e21c89206a9fc9b3d9bb5e68c4da862b97 Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Sat, 28 Jan 2023 21:18:24 +0200 Subject: [PATCH] settings: added showing of installed game version --- Cargo.lock | 1 + Cargo.toml | 1 + assets/locales/en/general.ftl | 6 ++++ assets/locales/ru/enhancements.ftl | 4 +-- assets/locales/ru/general.ftl | 6 ++++ src/i18n.rs | 13 +++++++ src/ui/preferences/enhancements.rs | 25 ++++++------- src/ui/preferences/general.rs | 57 ++++++++++++++++++++++++++++-- 8 files changed, 96 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 45e27ff..e791ca4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -55,6 +55,7 @@ name = "anime-game-launcher" version = "2.0.0-dev" dependencies = [ "anime-launcher-sdk", + "anyhow", "fluent-templates", "glib-build-tools", "gtk4", diff --git a/Cargo.toml b/Cargo.toml index 6142ed8..3003578 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,3 +29,4 @@ fluent-templates = "0.8" unic-langid = "0.9" lazy_static = "1.4.0" +anyhow = "1.0" diff --git a/assets/locales/en/general.ftl b/assets/locales/en/general.ftl index 570cdc3..f979ed5 100644 --- a/assets/locales/en/general.ftl +++ b/assets/locales/en/general.ftl @@ -12,6 +12,12 @@ repair-game = Repair game status = Status game-version = Game version +game-not-installed = not installed + +game-predownload-available = Game update pre-downloading available: {$old} -> {$new} +game-update-available = Game update available: {$old} -> {$new} +game-outdated = Game is too outdated and can't be updated. Latest version: {$latest} + patch-version = Patch version selected-version = Selected version diff --git a/assets/locales/ru/enhancements.ftl b/assets/locales/ru/enhancements.ftl index 61dafa2..fc85c04 100644 --- a/assets/locales/ru/enhancements.ftl +++ b/assets/locales/ru/enhancements.ftl @@ -18,8 +18,8 @@ fsr = FSR fsr-description = Для использования установите меньшее разрешение в настройках игры и нажмите Alt+Enter ultra-quality = Ультра quality = Хорошо -balanced = Сбалансированно -performance = Производительно +balanced = Баланс +performance = Скорость gamemode = Gamemode gamemode-description = Выделять игре приоритет перед остальными процессами diff --git a/assets/locales/ru/general.ftl b/assets/locales/ru/general.ftl index a5308ce..5617aac 100644 --- a/assets/locales/ru/general.ftl +++ b/assets/locales/ru/general.ftl @@ -12,6 +12,12 @@ repair-game = Починить игру status = Статус game-version = Версия игры +game-not-installed = не установлена + +game-predownload-available = Доступна предзагрузка обновления игры: {$old} -> {$new} +game-update-available = Доступно обновление игры: {$old} -> {$new} +game-outdated = Версия игры слишком устаревшая и не может быть обновлена. Последняя версия: {$latest} + patch-version = Версия патча selected-version = Выбранная версия diff --git a/src/i18n.rs b/src/i18n.rs index 937f087..a245132 100644 --- a/src/i18n.rs +++ b/src/i18n.rs @@ -18,3 +18,16 @@ pub fn tr(id: &str) -> String { .expect(&format!("Failed to find message with a given id: {id}")) } } + +#[allow(clippy::expect_fun_call)] +pub fn tr_args(id: &str, args: I) -> String +where + I: IntoIterator)>, + T: AsRef + std::hash::Hash + Eq +{ + unsafe { + LOCALES + .lookup_with_args(&LANG, id, &std::collections::HashMap::from_iter(args.into_iter())) + .expect(&format!("Failed to find message with a given id: {id}")) + } +} diff --git a/src/ui/preferences/enhancements.rs b/src/ui/preferences/enhancements.rs index b561e67..0f1789e 100644 --- a/src/ui/preferences/enhancements.rs +++ b/src/ui/preferences/enhancements.rs @@ -251,31 +251,32 @@ impl WidgetTemplate for Enhancements { #[wrap(Some)] set_model = >k::StringList::new(&[ - &tr("custom"), "90", "120", "144", "165", "180", "200", - "240" + "240", + &tr("custom") ]), set_selected: match Fps::from_num(CONFIG.game.enhancements.fps_unlocker.config.fps) { - Fps::Custom(_) => 0, - Fps::Ninety => 1, - Fps::HundredTwenty => 2, - Fps::HundredFourtyFour => 3, - Fps::HundredSixtyFive => 4, - Fps::HundredEighty => 5, - Fps::TwoHundred => 6, - Fps::TwoHundredFourty => 7 + Fps::Ninety => 0, + Fps::HundredTwenty => 1, + Fps::HundredFourtyFour => 2, + Fps::HundredSixtyFive => 3, + Fps::HundredEighty => 4, + Fps::TwoHundred => 5, + Fps::TwoHundredFourty => 6, + + Fps::Custom(_) => 7 }, connect_selected_notify => move |row| { - if is_ready() && row.selected() > 0 { + if is_ready() && row.selected() < Fps::list().len() as u32 - 1 { if let Ok(mut config) = config::get() { - config.game.enhancements.fps_unlocker.config.fps = Fps::list()[row.selected() as usize - 1].to_num(); + config.game.enhancements.fps_unlocker.config.fps = Fps::list()[row.selected() as usize].to_num(); config::update(config); } diff --git a/src/ui/preferences/general.rs b/src/ui/preferences/general.rs index af4eaba..a85ba5c 100644 --- a/src/ui/preferences/general.rs +++ b/src/ui/preferences/general.rs @@ -4,12 +4,25 @@ use gtk::prelude::*; use adw::prelude::*; use anime_launcher_sdk::config; +use anime_launcher_sdk::anime_game_core::prelude::*; +use anime_launcher_sdk::anime_game_core::genshin::prelude::*; -use crate::i18n::tr; +use crate::i18n::*; use crate::ui::main::is_ready; lazy_static::lazy_static! { static ref CONFIG: config::Config = config::get().expect("Failed to load config"); + + static ref GAME: Game = Game::new(&CONFIG.game.path.join("fioweiofweuihj")); + + static ref GAME_DIFF: Option = match GAME.try_get_diff() { + Ok(diff) => Some(diff), + Err(err) => { + tracing::error!("Failed to get game diff {err}"); + + None + } + }; } #[relm4::widget_template(pub)] @@ -116,8 +129,46 @@ impl WidgetTemplate for General { set_title: &tr("game-version"), add_suffix = >k::Label { - set_text: "3.3.0", - add_css_class: "success" + set_text: &match GAME_DIFF.as_ref() { + Some(diff) => match diff { + VersionDiff::Latest(current) | + VersionDiff::Predownload { current, .. } | + VersionDiff::Diff { current, .. } | + VersionDiff::Outdated { current, .. } => current.to_string(), + + VersionDiff::NotInstalled { .. } => tr("game-not-installed") + } + + None => String::from("?") + }, + + add_css_class: match GAME_DIFF.as_ref() { + Some(diff) => match diff { + VersionDiff::Latest(_) => "success", + VersionDiff::Predownload { .. } => "accent", + VersionDiff::Diff { .. } => "warning", + VersionDiff::Outdated { .. } => "error", + VersionDiff::NotInstalled { .. } => "" + } + + None => "success" + }, + + set_tooltip_text: Some(&match GAME_DIFF.as_ref().unwrap() { + VersionDiff::Latest(_) => String::new(), + VersionDiff::Predownload { current, latest, .. } => tr_args("game-predownload-available", [ + ("old", current.to_string().into()), + ("new", latest.to_string().into()) + ]), + VersionDiff::Diff { current, latest, .. } => tr_args("game-update-available", [ + ("old", current.to_string().into()), + ("new", latest.to_string().into()) + ]), + VersionDiff::Outdated { latest, ..} => tr_args("game-outdated", [ + ("latest", latest.to_string().into()) + ]), + VersionDiff::NotInstalled { .. } => String::new() + }) } },