Combine GamepadSettings with ControlSettings

This commit is contained in:
YuWeiWu 2020-04-26 22:59:51 +08:00 committed by Forest Anderson
parent 04b7837340
commit 28326312ca
4 changed files with 30 additions and 42 deletions

View File

@ -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 group chat `/join_group` `/group`
- Added faction chat `/join_faction` `/faction` - Added faction chat `/join_faction` `/faction`
- Added regional, local, and global chat (`/region`, `/say`, and `/world`, respectively) - 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 ### Changed

View File

@ -53,8 +53,8 @@ impl ControllerSettings {
} }
} }
impl From<&crate::settings::GamepadSettings> for ControllerSettings { impl From<&crate::settings::ControlSettings> for ControllerSettings {
fn from(settings: &crate::settings::GamepadSettings) -> Self { fn from(settings: &crate::settings::ControlSettings) -> Self {
Self { Self {
game_button_map: { game_button_map: {
let mut map: HashMap<_, Vec<_>> = HashMap::new(); let mut map: HashMap<_, Vec<_>> = HashMap::new();

View File

@ -42,6 +42,18 @@ impl From<ControlSettings> for ControlSettingsSerde {
pub struct ControlSettings { pub struct ControlSettings {
pub keybindings: HashMap<GameInput, KeyMouse>, pub keybindings: HashMap<GameInput, KeyMouse>,
pub inverse_keybindings: HashMap<KeyMouse, HashSet<GameInput>>, // used in event loop pub inverse_keybindings: HashMap<KeyMouse, HashSet<GameInput>>, // 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<crate::controller::Axis, f32>,
pub button_deadzones: HashMap<crate::controller::AnalogButton, f32>,
pub mouse_emulation_sensitivity: u32,
pub inverted_axes: Vec<crate::controller::Axis>,
} }
impl From<ControlSettingsSerde> for ControlSettings { impl From<ControlSettingsSerde> for ControlSettings {
@ -160,6 +172,18 @@ impl Default for ControlSettings {
let mut new_settings = Self { let mut new_settings = Self {
keybindings: HashMap::new(), keybindings: HashMap::new(),
inverse_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 // 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 // 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<crate::controller::Axis, f32>,
pub button_deadzones: HashMap<crate::controller::AnalogButton, f32>,
pub mouse_emulation_sensitivity: u32,
pub inverted_axes: Vec<crate::controller::Axis>,
}
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 { pub mod con_settings {
use crate::controller::*; use crate::controller::*;
use gilrs::{Axis as GilAxis, Button as GilButton}; use gilrs::{Axis as GilAxis, Button as GilButton};
@ -673,7 +661,6 @@ pub struct Settings {
pub logon_commands: Vec<String>, pub logon_commands: Vec<String>,
pub language: LanguageSettings, pub language: LanguageSettings,
pub screenshots_path: PathBuf, pub screenshots_path: PathBuf,
pub controller: GamepadSettings,
} }
impl Default for Settings { impl Default for Settings {
@ -707,7 +694,6 @@ impl Default for Settings {
logon_commands: Vec::new(), logon_commands: Vec::new(),
language: LanguageSettings::default(), language: LanguageSettings::default(),
screenshots_path, screenshots_path,
controller: GamepadSettings::default(),
} }
} }
} }

View File

@ -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): ( let (message_sender, message_receiver): (
channel::Sender<String>, channel::Sender<String>,