diff --git a/assets/voxygen/i18n/en/hud/hud_settings.ron b/assets/voxygen/i18n/en/hud/hud_settings.ron index 3d19528961..4443d7a70d 100644 --- a/assets/voxygen/i18n/en/hud/hud_settings.ron +++ b/assets/voxygen/i18n/en/hud/hud_settings.ron @@ -41,6 +41,7 @@ "hud.settings.zoom_sensitivity": "Zoom Sensitivity", "hud.settings.invert_scroll_zoom": "Invert Scroll Zoom", "hud.settings.invert_mouse_y_axis": "Invert Mouse Y Axis", + "hud.settings.invert_controller_y_axis": "Invert Controller Y Axis", "hud.settings.enable_mouse_smoothing": "Camera Smoothing", "hud.settings.free_look_behavior": "Free look behavior", "hud.settings.auto_walk_behavior": "Auto walk behavior", diff --git a/assets/voxygen/i18n/sv/_manifest.ron b/assets/voxygen/i18n/sv/_manifest.ron index f7ab658926..2726566fa9 100644 --- a/assets/voxygen/i18n/sv/_manifest.ron +++ b/assets/voxygen/i18n/sv/_manifest.ron @@ -207,6 +207,7 @@ Enjoy your stay in the World of Veloren."#, "hud.settings.zoom_sensitivity": "Zoom Sensitivity", "hud.settings.invert_scroll_zoom": "Invert Scroll Zoom", "hud.settings.invert_mouse_y_axis": "Invert Mouse Y Axis", + "hud.settings.invert_controller_y_axis": "Invert Controller Y Axis", "hud.settings.view_distance": "View Distance", "hud.settings.maximum_fps": "Maximum FPS", diff --git a/voxygen/src/controller.rs b/voxygen/src/controller.rs index 1bbc05a644..a426ea3ee8 100644 --- a/voxygen/src/controller.rs +++ b/voxygen/src/controller.rs @@ -17,6 +17,7 @@ pub struct ControllerSettings { pub game_axis_map: HashMap>, pub menu_axis_map: HashMap>, pub pan_sensitivity: u32, + pub pan_invert_y: bool, pub axis_deadzones: HashMap, pub button_deadzones: HashMap, pub mouse_emulation_sensitivity: u32, @@ -259,6 +260,7 @@ impl From<&crate::settings::GamepadSettings> for ControllerSettings { map }, pan_sensitivity: settings.pan_sensitivity, + pan_invert_y: settings.pan_invert_y, axis_deadzones: settings.axis_deadzones.clone(), button_deadzones: settings.button_deadzones.clone(), mouse_emulation_sensitivity: settings.mouse_emulation_sensitivity, diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 1261c20bf9..470903a944 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -348,6 +348,7 @@ pub enum Event { AdjustMouseZoom(u32), ToggleZoomInvert(bool), ToggleMouseYInvert(bool), + ToggleControllerYInvert(bool), ToggleSmoothPan(bool), AdjustViewDistance(u32), AdjustLodDetail(u32), @@ -2328,6 +2329,9 @@ impl Hud { settings_window::Event::ToggleMouseYInvert(mouse_y_inverted) => { events.push(Event::ToggleMouseYInvert(mouse_y_inverted)); }, + settings_window::Event::ToggleControllerYInvert(controller_y_inverted) => { + events.push(Event::ToggleControllerYInvert(controller_y_inverted)); + }, settings_window::Event::ToggleSmoothPan(smooth_pan_enabled) => { events.push(Event::ToggleSmoothPan(smooth_pan_enabled)); }, diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index def979106b..b029ec68ec 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -95,6 +95,8 @@ widget_ids! { mouse_zoom_invert_label, mouse_y_invert_button, mouse_y_invert_label, + controller_y_invert_button, + controller_y_invert_label, smooth_pan_toggle_button, smooth_pan_toggle_label, ch_title, @@ -296,6 +298,7 @@ pub enum Event { AdjustMouseZoom(u32), ToggleZoomInvert(bool), ToggleMouseYInvert(bool), + ToggleControllerYInvert(bool), ToggleSmoothPan(bool), AdjustViewDistance(u32), AdjustSpriteRenderDistance(u32), @@ -1455,6 +1458,36 @@ impl<'a> Widget for SettingsWindow<'a> { .color(TEXT_COLOR) .set(state.ids.mouse_y_invert_label, ui); + // Controller Y Pan Inversion + let controller_y_inverted = ToggleButton::new( + self.global_state.settings.controller.pan_invert_y, + self.imgs.checkbox, + self.imgs.checkbox_checked, + ) + .w_h(18.0, 18.0) + .right_from(state.ids.mouse_y_invert_label, 10.0) + .hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo) + .press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked) + .set(state.ids.controller_y_invert_button, ui); + + if self.global_state.settings.controller.pan_invert_y != controller_y_inverted { + events.push(Event::ToggleControllerYInvert( + !self.global_state.settings.controller.pan_invert_y, + )); + } + + Text::new( + &self + .localized_strings + .get("hud.settings.invert_controller_y_axis"), + ) + .right_from(state.ids.controller_y_invert_button, 10.0) + .font_size(self.fonts.cyri.scale(14)) + .font_id(self.fonts.cyri.conrod_id) + .graphics_for(state.ids.controller_y_invert_button) + .color(TEXT_COLOR) + .set(state.ids.controller_y_invert_label, ui); + // Mouse Smoothing Toggle let smooth_pan_enabled = ToggleButton::new( self.global_state.settings.gameplay.smooth_pan_enable, @@ -1462,7 +1495,7 @@ impl<'a> Widget for SettingsWindow<'a> { self.imgs.checkbox_checked, ) .w_h(18.0, 18.0) - .right_from(state.ids.mouse_y_invert_label, 10.0) + .right_from(state.ids.controller_y_invert_label, 10.0) .hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo) .press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked) .set(state.ids.smooth_pan_toggle_button, ui); diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 2c9b052c1e..b37dec9d5e 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -906,6 +906,12 @@ impl PlayState for SessionState { global_state.settings.gameplay.mouse_y_inversion = mouse_y_inverted; global_state.settings.save_to_file_warn(); }, + HudEvent::ToggleControllerYInvert(controller_y_inverted) => { + global_state.window.controller_settings.pan_invert_y = + controller_y_inverted; + global_state.settings.controller.pan_invert_y = controller_y_inverted; + global_state.settings.save_to_file_warn(); + }, HudEvent::ToggleSmoothPan(smooth_pan_enabled) => { global_state.settings.gameplay.smooth_pan_enable = smooth_pan_enabled; global_state.settings.save_to_file_warn(); diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index 8bd5175731..d931abbcb3 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -513,7 +513,7 @@ pub struct Window { events: Vec, focused: bool, gilrs: Option, - controller_settings: ControllerSettings, + pub controller_settings: ControllerSettings, cursor_position: winit::dpi::PhysicalPosition, mouse_emulation_vec: Vec2, // Currently used to send and receive screenshot result messages @@ -776,13 +776,18 @@ impl Window { )); }, AxisGameAction::CameraY => { + let pan_invert_y = + match self.controller_settings.pan_invert_y { + true => -1.0, + false => 1.0, + }; + self.events.push(Event::AnalogGameInput( AnalogGameInput::CameraY( - // TODO: Use pan_invert_y here. Remove - in - // front of `value` as well -value * self.controller_settings.pan_sensitivity as f32 + * pan_invert_y / 100.0, ), ));