diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 9cde31b6d4..3c4308356e 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -172,6 +172,7 @@ pub enum Event { AdjustMousePan(u32), AdjustMouseZoom(u32), ToggleZoomInvert(bool), + ToggleMouseYInvert(bool), AdjustViewDistance(u32), AdjustMusicVolume(f32), AdjustSfxVolume(f32), @@ -1048,6 +1049,9 @@ impl Hud { settings_window::Event::ToggleZoomInvert(zoom_inverted) => { events.push(Event::ToggleZoomInvert(zoom_inverted)); } + settings_window::Event::ToggleMouseYInvert(mouse_y_inverted) => { + events.push(Event::ToggleMouseYInvert(mouse_y_inverted)); + } settings_window::Event::AdjustViewDistance(view_distance) => { events.push(Event::AdjustViewDistance(view_distance)); } diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index a351ef61aa..bb7572a61e 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -55,6 +55,8 @@ widget_ids! { mouse_zoom_value, mouse_zoom_invert_button, mouse_zoom_invert_label, + mouse_y_invert_button, + mouse_y_invert_label, ch_title, ch_transp_slider, ch_transp_label, @@ -164,6 +166,7 @@ pub enum Event { AdjustMousePan(u32), AdjustMouseZoom(u32), ToggleZoomInvert(bool), + ToggleMouseYInvert(bool), AdjustViewDistance(u32), AdjustFOV(u16), ChangeAaMode(AaMode), @@ -980,6 +983,32 @@ impl<'a> Widget for SettingsWindow<'a> { .graphics_for(state.ids.button_help) .color(TEXT_COLOR) .set(state.ids.mouse_zoom_invert_label, ui); + + // Mouse Y Inversion + let mouse_y_inverted = ToggleButton::new( + self.global_state.settings.gameplay.mouse_y_inversion, + self.imgs.checkbox, + self.imgs.checkbox_checked, + ) + .w_h(18.0, 18.0) + .right_from(state.ids.mouse_zoom_invert_button, 250.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.mouse_y_invert_button, ui); + + if self.global_state.settings.gameplay.mouse_y_inversion != mouse_y_inverted { + events.push(Event::ToggleMouseYInvert( + !self.global_state.settings.gameplay.mouse_y_inversion, + )); + } + + Text::new("Invert Mouse Y Axis") + .right_from(state.ids.mouse_y_invert_button, 10.0) + .font_size(14) + .font_id(self.fonts.cyri) + .graphics_for(state.ids.button_help) + .color(TEXT_COLOR) + .set(state.ids.mouse_y_invert_label, ui); } // 3) Controls Tab -------------------------------- diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 7aee3cb17f..6d7151d65f 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -420,6 +420,11 @@ impl PlayState for SessionState { global_state.settings.gameplay.zoom_inversion = zoom_inverted; global_state.settings.save_to_file_warn(); } + HudEvent::ToggleMouseYInvert(mouse_y_inverted) => { + global_state.window.mouse_y_inversion = mouse_y_inverted; + global_state.settings.gameplay.mouse_y_inversion = mouse_y_inverted; + global_state.settings.save_to_file_warn(); + } HudEvent::AdjustViewDistance(view_distance) => { self.client.borrow_mut().set_view_distance(view_distance); diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index af353a0e9f..85028412ec 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -100,6 +100,7 @@ pub struct GameplaySettings { pub pan_sensitivity: u32, pub zoom_sensitivity: u32, pub zoom_inversion: bool, + pub mouse_y_inversion: bool, pub crosshair_transp: f32, pub chat_transp: f32, pub crosshair_type: CrosshairType, @@ -116,6 +117,7 @@ impl Default for GameplaySettings { pan_sensitivity: 100, zoom_sensitivity: 100, zoom_inversion: false, + mouse_y_inversion: false, crosshair_transp: 0.6, chat_transp: 0.4, crosshair_type: CrosshairType::Round, diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index 80e18fbc3e..2cbd0c9ea0 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -94,6 +94,7 @@ pub struct Window { pub pan_sensitivity: u32, pub zoom_sensitivity: u32, pub zoom_inversion: bool, + pub mouse_y_inversion: bool, fullscreen: bool, needs_refresh_resize: bool, key_map: HashMap>, @@ -246,6 +247,7 @@ impl Window { pan_sensitivity: settings.gameplay.pan_sensitivity, zoom_sensitivity: settings.gameplay.zoom_sensitivity, zoom_inversion: settings.gameplay.zoom_inversion, + mouse_y_inversion: settings.gameplay.mouse_y_inversion, fullscreen: false, needs_refresh_resize: false, key_map: map, @@ -285,6 +287,10 @@ impl Window { true => -1.0, false => 1.0, }; + let mouse_y_inversion = match self.mouse_y_inversion { + true => -1.0, + false => 1.0, + }; let mut toggle_fullscreen = false; let mut take_screenshot = false; @@ -374,7 +380,7 @@ impl Window { } if *focused => { let delta = Vec2::new( dx as f32 * (pan_sensitivity as f32 / 100.0), - dy as f32 * (pan_sensitivity as f32 / 100.0), + dy as f32 * (pan_sensitivity as f32 * mouse_y_inversion / 100.0), ); if cursor_grabbed {