From 3be54b22d2251fc0643b4fc0ab4e5a9589c03344 Mon Sep 17 00:00:00 2001 From: Observer KRypt0n_ Date: Fri, 1 Jul 2022 21:38:12 +0200 Subject: [PATCH] Added wine language option, added gamemode option sync --- assets/ui/preferences_enhanced.blp | 46 ++++++++++++----- src/lib/config/hud.rs | 4 +- src/lib/config/mod.rs | 8 ++- src/lib/config/wine_lang.rs | 78 +++++++++++++++++++++++++++++ src/lib/config/wine_sync.rs | 6 +-- src/lib/game.rs | 1 + src/ui/preferences/enhanced_page.rs | 70 +++++++++++++++++++------- 7 files changed, 174 insertions(+), 39 deletions(-) create mode 100644 src/lib/config/wine_lang.rs diff --git a/assets/ui/preferences_enhanced.blp b/assets/ui/preferences_enhanced.blp index 45be20b..f80b0bc 100644 --- a/assets/ui/preferences_enhanced.blp +++ b/assets/ui/preferences_enhanced.blp @@ -7,18 +7,6 @@ Adw.PreferencesPage enhanced_page { Adw.PreferencesGroup { title: "Wine"; - Adw.ComboRow hud_combo { - title: "HUD"; - - model: Gtk.StringList { - strings [ - "None", - "DXVK", - "MangoHUD" - ] - }; - } - Adw.ComboRow sync_combo { title: "Synchronization"; subtitle: "Technology used to synchronize inner wine events"; @@ -50,16 +38,48 @@ Adw.PreferencesPage enhanced_page { valign: center; } } + + Adw.ComboRow wine_lang { + title: "Language"; + subtitle: "Choose the language to use in wine environment. Can fix keyboard layout detection in-game"; + + model: Gtk.StringList { + strings [ + "System", + "English", + "German", + "Russian", + "Portuguese", + "French", + "Chinese", + "Spanish", + "Japanese", + "Korean" + ] + }; + } } Adw.PreferencesGroup { title: "Game"; + Adw.ComboRow hud_combo { + title: "HUD"; + + model: Gtk.StringList { + strings [ + "None", + "DXVK", + "MangoHUD" + ] + }; + } + Adw.ActionRow { title: "Gamemode"; subtitle: "This prioritizes the game over the rest of the processes"; - Gtk.Switch { + Gtk.Switch gamemode_switcher { valign: center; } } diff --git a/src/lib/config/hud.rs b/src/lib/config/hud.rs index dda444d..8da54f2 100644 --- a/src/lib/config/hud.rs +++ b/src/lib/config/hud.rs @@ -31,8 +31,8 @@ impl TryFrom for HUD { impl Into for HUD { fn into(self) -> u32 { match self { - Self::None => 0, - Self::DXVK => 1, + Self::None => 0, + Self::DXVK => 1, Self::MangoHUD => 2 } } diff --git a/src/lib/config/mod.rs b/src/lib/config/mod.rs index 89a527a..c0cbe48 100644 --- a/src/lib/config/mod.rs +++ b/src/lib/config/mod.rs @@ -9,9 +9,11 @@ use super::consts::*; mod hud; mod wine_sync; +mod wine_lang; pub use hud::HUD; pub use wine_sync::WineSync; +pub use wine_lang::WineLang; pub fn get() -> Result { match config_file() { @@ -154,7 +156,8 @@ pub struct Wine { pub prefix: String, pub builds: String, pub selected: Option, - pub sync: WineSync + pub sync: WineSync, + pub language: WineLang } impl Default for Wine { @@ -169,7 +172,8 @@ impl Default for Wine { None => String::new() }, selected: None, - sync: WineSync::default() + sync: WineSync::default(), + language: WineLang::default() } } } diff --git a/src/lib/config/wine_lang.rs b/src/lib/config/wine_lang.rs new file mode 100644 index 0000000..05ac31e --- /dev/null +++ b/src/lib/config/wine_lang.rs @@ -0,0 +1,78 @@ +use std::collections::HashMap; + +use serde::{Serialize, Deserialize}; + +#[derive(Debug, Clone, Copy, Serialize, Deserialize)] +pub enum WineLang { + System, + English, + German, + Russian, + Portuguese, + French, + Chinese, + Spanish, + Japanese, + Korean +} + +impl Default for WineLang { + fn default() -> Self { + Self::System + } +} + +impl TryFrom for WineLang { + type Error = String; + + fn try_from(value: u32) -> Result { + match value { + 0 => Ok(Self::System), + 1 => Ok(Self::English), + 2 => Ok(Self::German), + 3 => Ok(Self::Russian), + 4 => Ok(Self::Portuguese), + 5 => Ok(Self::French), + 6 => Ok(Self::Chinese), + 7 => Ok(Self::Spanish), + 8 => Ok(Self::Japanese), + 9 => Ok(Self::Korean), + _ => Err(String::from("Failed to convert number to WineLang enum")) + } + } +} + +impl Into for WineLang { + fn into(self) -> u32 { + match self { + WineLang::System => 0, + WineLang::English => 1, + WineLang::German => 2, + WineLang::Russian => 3, + WineLang::Portuguese => 4, + WineLang::French => 5, + WineLang::Chinese => 6, + WineLang::Spanish => 7, + WineLang::Japanese => 8, + WineLang::Korean => 9 + } + } +} + +impl WineLang { + /// Get environment variables corresponding to used wine language + pub fn get_env_vars(&self) -> HashMap<&str, &str> { + match self { + WineLang::System => HashMap::new(), + WineLang::English => HashMap::from([("LANG", "en_us.utf8")]), + WineLang::German => HashMap::from([("LANG", "de_de.utf8")]), + WineLang::Russian => HashMap::from([("LANG", "ru_ru.utf8")]), + WineLang::Portuguese => HashMap::from([("LANG", "pt_pt.utf8")]), + WineLang::French => HashMap::from([("LANG", "fr_fr.utf8")]), + WineLang::Chinese => HashMap::from([("LANG", "zh_cn.utf8")]), + WineLang::Spanish => HashMap::from([("LANG", "es_es.utf8")]), + WineLang::Japanese => HashMap::from([("LANG", "ja_jp.utf8")]), + WineLang::Korean => HashMap::from([("LANG", "ko_kr.utf8")]) + } + } +} diff --git a/src/lib/config/wine_sync.rs b/src/lib/config/wine_sync.rs index 458fd09..bb8e1ca 100644 --- a/src/lib/config/wine_sync.rs +++ b/src/lib/config/wine_sync.rs @@ -33,9 +33,9 @@ impl TryFrom for WineSync { impl Into for WineSync { fn into(self) -> u32 { match self { - Self::None => 0, - Self::ESync => 1, - Self::FSync => 2, + Self::None => 0, + Self::ESync => 1, + Self::FSync => 2, Self::Futex2 => 3 } } diff --git a/src/lib/game.rs b/src/lib/game.rs index 72a7395..03409c2 100644 --- a/src/lib/game.rs +++ b/src/lib/game.rs @@ -100,6 +100,7 @@ pub fn run(debug: bool) -> Result<(), Error> { command.envs(config.game.wine.sync.get_env_vars()); command.envs(config.game.enhancements.hud.get_env_vars()); command.envs(config.game.enhancements.fsr.get_env_vars()); + command.envs(config.game.wine.language.get_env_vars()); command.envs(config.game.environment) .current_dir(config.game.path) diff --git a/src/ui/preferences/enhanced_page.rs b/src/ui/preferences/enhanced_page.rs index 9739fa2..f83f71a 100644 --- a/src/ui/preferences/enhanced_page.rs +++ b/src/ui/preferences/enhanced_page.rs @@ -10,10 +10,13 @@ use crate::lib::config; pub struct Page { pub page: adw::PreferencesPage, - pub hud_combo: adw::ComboRow, pub sync_combo: adw::ComboRow, pub fsr_combo: adw::ComboRow, - pub fsr_switcher: gtk::Switch + pub fsr_switcher: gtk::Switch, + pub wine_lang: adw::ComboRow, + + pub hud_combo: adw::ComboRow, + pub gamemode_switcher: gtk::Switch } impl Page { @@ -23,22 +26,15 @@ impl Page { let result = Self { page: get_object(&builder, "enhanced_page")?, - hud_combo: get_object(&builder, "hud_combo")?, sync_combo: get_object(&builder, "sync_combo")?, fsr_combo: get_object(&builder, "fsr_combo")?, - fsr_switcher: get_object(&builder, "fsr_switcher")? + fsr_switcher: get_object(&builder, "fsr_switcher")?, + + hud_combo: get_object(&builder, "hud_combo")?, + gamemode_switcher: get_object(&builder, "gamemode_switcher")?, + wine_lang: get_object(&builder, "wine_lang")? }; - // Wine HUD selection - result.hud_combo.connect_selected_notify(|hud| { - if let Ok(mut config) = config::get() { - // TODO: show toast - config.game.enhancements.hud = config::HUD::try_from(hud.selected()).unwrap(); - - config::update(config).unwrap(); - } - }); - // Wine sync selection result.sync_combo.connect_selected_notify(|hud| { if let Ok(mut config) = config::get() { @@ -59,7 +55,7 @@ impl Page { } }); - // FSR switcher changing + // FSR switching result.fsr_switcher.connect_state_notify(|switcher| { if let Ok(mut config) = config::get() { // TODO: show toast @@ -69,6 +65,36 @@ impl Page { } }); + // Wine language selection + result.wine_lang.connect_selected_notify(|hud| { + if let Ok(mut config) = config::get() { + // TODO: show toast + config.game.wine.language = config::WineLang::try_from(hud.selected()).unwrap(); + + config::update(config).unwrap(); + } + }); + + // HUD selection + result.hud_combo.connect_selected_notify(|hud| { + if let Ok(mut config) = config::get() { + // TODO: show toast + config.game.enhancements.hud = config::HUD::try_from(hud.selected()).unwrap(); + + config::update(config).unwrap(); + } + }); + + // Gamemode switching + result.gamemode_switcher.connect_state_notify(|switcher| { + if let Ok(mut config) = config::get() { + // TODO: show toast + config.game.enhancements.gamemode = switcher.state(); + + config::update(config).unwrap(); + } + }); + Ok(result) } @@ -80,18 +106,24 @@ impl Page { pub fn update(&self) -> Result<(), Error> { let config = config::get()?; - // Update Wine HUD - self.hud_combo.set_selected(config.game.enhancements.hud.into()); - // Update Wine sync self.sync_combo.set_selected(config.game.wine.sync.into()); // FSR strength selection self.fsr_combo.set_selected(config.game.enhancements.fsr.strength); - // FSR switcher changing + // FSR switching self.fsr_switcher.set_state(config.game.enhancements.fsr.enabled); + // Update wine language + self.wine_lang.set_selected(config.game.wine.language.into()); + + // Update HUD + self.hud_combo.set_selected(config.game.enhancements.hud.into()); + + // Gamemode switching + self.fsr_switcher.set_state(config.game.enhancements.gamemode); + Ok(()) } }