Added wine language option, added gamemode option sync

This commit is contained in:
Observer KRypt0n_ 2022-07-01 21:38:12 +02:00
parent 40e6de29cf
commit 3be54b22d2
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
7 changed files with 174 additions and 39 deletions

View file

@ -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;
}
}

View file

@ -31,8 +31,8 @@ impl TryFrom<u32> for HUD {
impl Into<u32> for HUD {
fn into(self) -> u32 {
match self {
Self::None => 0,
Self::DXVK => 1,
Self::None => 0,
Self::DXVK => 1,
Self::MangoHUD => 2
}
}

View file

@ -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<Config, Error> {
match config_file() {
@ -154,7 +156,8 @@ pub struct Wine {
pub prefix: String,
pub builds: String,
pub selected: Option<String>,
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()
}
}
}

View file

@ -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<u32> for WineLang {
type Error = String;
fn try_from(value: u32) -> Result<Self, Self::Error> {
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<u32> 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")])
}
}
}

View file

@ -33,9 +33,9 @@ impl TryFrom<u32> for WineSync {
impl Into<u32> 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
}
}

View file

@ -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)

View file

@ -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(())
}
}