From 28326312ca6489501e1606e83296e3dae6f81394 Mon Sep 17 00:00:00 2001 From: YuWeiWu Date: Sun, 26 Apr 2020 22:59:51 +0800 Subject: [PATCH] Combine GamepadSettings with ControlSettings --- CHANGELOG.md | 4 ++- voxygen/src/controller.rs | 4 +-- voxygen/src/settings.rs | 62 +++++++++++++++------------------------ voxygen/src/window.rs | 2 +- 4 files changed, 30 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a433d61f68..a152b1a095 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Added group chat `/join_group` `/group` - Added faction chat `/join_faction` `/faction` - Added regional, local, and global chat (`/region`, `/say`, and `/world`, respectively) -- Added command shortcuts for each of the above chat modes (`/g`, `/f`, `/r`, `/s`, and `/w`, respectively and `/t` for `/tell`) +- Added command shortcuts for each of the above chat modes (`/g`, `/f`, `/r`, + `/s`, and `/w`, respectively and `/t` for `/tell`) +- Combine GamepadSettings with ControlSettings ### Changed diff --git a/voxygen/src/controller.rs b/voxygen/src/controller.rs index 42f60cb3e3..f4b14f1ae1 100644 --- a/voxygen/src/controller.rs +++ b/voxygen/src/controller.rs @@ -53,8 +53,8 @@ impl ControllerSettings { } } -impl From<&crate::settings::GamepadSettings> for ControllerSettings { - fn from(settings: &crate::settings::GamepadSettings) -> Self { +impl From<&crate::settings::ControlSettings> for ControllerSettings { + fn from(settings: &crate::settings::ControlSettings) -> Self { Self { game_button_map: { let mut map: HashMap<_, Vec<_>> = HashMap::new(); diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 3427b3a8fe..7e5c71bfcf 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -42,6 +42,18 @@ impl From for ControlSettingsSerde { pub struct ControlSettings { pub keybindings: HashMap, pub inverse_keybindings: HashMap>, // used in event loop + pub game_buttons: con_settings::GameButtons, + pub menu_buttons: con_settings::MenuButtons, + pub game_axis: con_settings::GameAxis, + pub menu_axis: con_settings::MenuAxis, + pub game_analog_buttons: con_settings::GameAnalogButton, + pub menu_analog_buttons: con_settings::MenuAnalogButton, + pub pan_sensitivity: u32, + pub pan_invert_y: bool, + pub axis_deadzones: HashMap, + pub button_deadzones: HashMap, + pub mouse_emulation_sensitivity: u32, + pub inverted_axes: Vec, } impl From for ControlSettings { @@ -160,6 +172,18 @@ impl Default for ControlSettings { let mut new_settings = Self { keybindings: HashMap::new(), inverse_keybindings: HashMap::new(), + game_buttons: con_settings::GameButtons::default(), + menu_buttons: con_settings::MenuButtons::default(), + game_axis: con_settings::GameAxis::default(), + menu_axis: con_settings::MenuAxis::default(), + game_analog_buttons: con_settings::GameAnalogButton::default(), + menu_analog_buttons: con_settings::MenuAnalogButton::default(), + pan_sensitivity: 10, + pan_invert_y: false, + axis_deadzones: HashMap::new(), + button_deadzones: HashMap::new(), + mouse_emulation_sensitivity: 12, + inverted_axes: Vec::new(), }; // Sets the initial keybindings for those GameInputs. If a new one is created in // future, you'll have to update default_binding, and you should update this vec @@ -221,42 +245,6 @@ impl Default for ControlSettings { } } -#[derive(Clone, Debug, Serialize, Deserialize)] -#[serde(default)] -pub struct GamepadSettings { - pub game_buttons: con_settings::GameButtons, - pub menu_buttons: con_settings::MenuButtons, - pub game_axis: con_settings::GameAxis, - pub menu_axis: con_settings::MenuAxis, - pub game_analog_buttons: con_settings::GameAnalogButton, - pub menu_analog_buttons: con_settings::MenuAnalogButton, - pub pan_sensitivity: u32, - pub pan_invert_y: bool, - pub axis_deadzones: HashMap, - pub button_deadzones: HashMap, - pub mouse_emulation_sensitivity: u32, - pub inverted_axes: Vec, -} - -impl Default for GamepadSettings { - fn default() -> Self { - Self { - game_buttons: con_settings::GameButtons::default(), - menu_buttons: con_settings::MenuButtons::default(), - game_axis: con_settings::GameAxis::default(), - menu_axis: con_settings::MenuAxis::default(), - game_analog_buttons: con_settings::GameAnalogButton::default(), - menu_analog_buttons: con_settings::MenuAnalogButton::default(), - pan_sensitivity: 10, - pan_invert_y: false, - axis_deadzones: HashMap::new(), - button_deadzones: HashMap::new(), - mouse_emulation_sensitivity: 12, - inverted_axes: Vec::new(), - } - } -} - pub mod con_settings { use crate::controller::*; use gilrs::{Axis as GilAxis, Button as GilButton}; @@ -673,7 +661,6 @@ pub struct Settings { pub logon_commands: Vec, pub language: LanguageSettings, pub screenshots_path: PathBuf, - pub controller: GamepadSettings, } impl Default for Settings { @@ -707,7 +694,6 @@ impl Default for Settings { logon_commands: Vec::new(), language: LanguageSettings::default(), screenshots_path, - controller: GamepadSettings::default(), } } } diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index c859676083..96ed090dfb 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -466,7 +466,7 @@ impl Window { }, }; - let controller_settings = ControllerSettings::from(&settings.controller); + let controller_settings = ControllerSettings::from(&settings.controls); let (message_sender, message_receiver): ( channel::Sender,