settings: added showing of installed game version

This commit is contained in:
Observer KRypt0n_ 2023-01-28 21:18:24 +02:00
parent 14c425ae9b
commit bf3e58e21c
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
8 changed files with 96 additions and 17 deletions

1
Cargo.lock generated
View file

@ -55,6 +55,7 @@ name = "anime-game-launcher"
version = "2.0.0-dev" version = "2.0.0-dev"
dependencies = [ dependencies = [
"anime-launcher-sdk", "anime-launcher-sdk",
"anyhow",
"fluent-templates", "fluent-templates",
"glib-build-tools", "glib-build-tools",
"gtk4", "gtk4",

View file

@ -29,3 +29,4 @@ fluent-templates = "0.8"
unic-langid = "0.9" unic-langid = "0.9"
lazy_static = "1.4.0" lazy_static = "1.4.0"
anyhow = "1.0"

View file

@ -12,6 +12,12 @@ repair-game = Repair game
status = Status status = Status
game-version = Game version 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 patch-version = Patch version
selected-version = Selected version selected-version = Selected version

View file

@ -18,8 +18,8 @@ fsr = FSR
fsr-description = Для использования установите меньшее разрешение в настройках игры и нажмите Alt+Enter fsr-description = Для использования установите меньшее разрешение в настройках игры и нажмите Alt+Enter
ultra-quality = Ультра ultra-quality = Ультра
quality = Хорошо quality = Хорошо
balanced = Сбалансированно balanced = Баланс
performance = Производительно performance = Скорость
gamemode = Gamemode gamemode = Gamemode
gamemode-description = Выделять игре приоритет перед остальными процессами gamemode-description = Выделять игре приоритет перед остальными процессами

View file

@ -12,6 +12,12 @@ repair-game = Починить игру
status = Статус status = Статус
game-version = Версия игры game-version = Версия игры
game-not-installed = не установлена
game-predownload-available = Доступна предзагрузка обновления игры: {$old} -> {$new}
game-update-available = Доступно обновление игры: {$old} -> {$new}
game-outdated = Версия игры слишком устаревшая и не может быть обновлена. Последняя версия: {$latest}
patch-version = Версия патча patch-version = Версия патча
selected-version = Выбранная версия selected-version = Выбранная версия

View file

@ -18,3 +18,16 @@ pub fn tr(id: &str) -> String {
.expect(&format!("Failed to find message with a given id: {id}")) .expect(&format!("Failed to find message with a given id: {id}"))
} }
} }
#[allow(clippy::expect_fun_call)]
pub fn tr_args<I, T>(id: &str, args: I) -> String
where
I: IntoIterator<Item = (T, fluent_templates::fluent_bundle::FluentValue<'static>)>,
T: AsRef<str> + 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}"))
}
}

View file

@ -251,31 +251,32 @@ impl WidgetTemplate for Enhancements {
#[wrap(Some)] #[wrap(Some)]
set_model = &gtk::StringList::new(&[ set_model = &gtk::StringList::new(&[
&tr("custom"),
"90", "90",
"120", "120",
"144", "144",
"165", "165",
"180", "180",
"200", "200",
"240" "240",
&tr("custom")
]), ]),
set_selected: match Fps::from_num(CONFIG.game.enhancements.fps_unlocker.config.fps) { set_selected: match Fps::from_num(CONFIG.game.enhancements.fps_unlocker.config.fps) {
Fps::Custom(_) => 0, Fps::Ninety => 0,
Fps::Ninety => 1, Fps::HundredTwenty => 1,
Fps::HundredTwenty => 2, Fps::HundredFourtyFour => 2,
Fps::HundredFourtyFour => 3, Fps::HundredSixtyFive => 3,
Fps::HundredSixtyFive => 4, Fps::HundredEighty => 4,
Fps::HundredEighty => 5, Fps::TwoHundred => 5,
Fps::TwoHundred => 6, Fps::TwoHundredFourty => 6,
Fps::TwoHundredFourty => 7
Fps::Custom(_) => 7
}, },
connect_selected_notify => move |row| { 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() { 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); config::update(config);
} }

View file

@ -4,12 +4,25 @@ use gtk::prelude::*;
use adw::prelude::*; use adw::prelude::*;
use anime_launcher_sdk::config; 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; use crate::ui::main::is_ready;
lazy_static::lazy_static! { lazy_static::lazy_static! {
static ref CONFIG: config::Config = config::get().expect("Failed to load config"); 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<VersionDiff> = match GAME.try_get_diff() {
Ok(diff) => Some(diff),
Err(err) => {
tracing::error!("Failed to get game diff {err}");
None
}
};
} }
#[relm4::widget_template(pub)] #[relm4::widget_template(pub)]
@ -116,8 +129,46 @@ impl WidgetTemplate for General {
set_title: &tr("game-version"), set_title: &tr("game-version"),
add_suffix = &gtk::Label { add_suffix = &gtk::Label {
set_text: "3.3.0", set_text: &match GAME_DIFF.as_ref() {
add_css_class: "success" 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()
})
} }
}, },