#966 - Add setting to invert controller camera Y axis

This commit is contained in:
heydabop 2021-02-23 21:50:17 -06:00
parent 914266c705
commit d4e3a3f29f
7 changed files with 56 additions and 4 deletions

View File

@ -41,6 +41,7 @@
"hud.settings.zoom_sensitivity": "Zoom Sensitivity", "hud.settings.zoom_sensitivity": "Zoom Sensitivity",
"hud.settings.invert_scroll_zoom": "Invert Scroll Zoom", "hud.settings.invert_scroll_zoom": "Invert Scroll Zoom",
"hud.settings.invert_mouse_y_axis": "Invert Mouse Y Axis", "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.enable_mouse_smoothing": "Camera Smoothing",
"hud.settings.free_look_behavior": "Free look behavior", "hud.settings.free_look_behavior": "Free look behavior",
"hud.settings.auto_walk_behavior": "Auto walk behavior", "hud.settings.auto_walk_behavior": "Auto walk behavior",

View File

@ -207,6 +207,7 @@ Enjoy your stay in the World of Veloren."#,
"hud.settings.zoom_sensitivity": "Zoom Sensitivity", "hud.settings.zoom_sensitivity": "Zoom Sensitivity",
"hud.settings.invert_scroll_zoom": "Invert Scroll Zoom", "hud.settings.invert_scroll_zoom": "Invert Scroll Zoom",
"hud.settings.invert_mouse_y_axis": "Invert Mouse Y Axis", "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.view_distance": "View Distance",
"hud.settings.maximum_fps": "Maximum FPS", "hud.settings.maximum_fps": "Maximum FPS",

View File

@ -17,6 +17,7 @@ pub struct ControllerSettings {
pub game_axis_map: HashMap<Axis, Vec<AxisGameAction>>, pub game_axis_map: HashMap<Axis, Vec<AxisGameAction>>,
pub menu_axis_map: HashMap<Axis, Vec<AxisMenuAction>>, pub menu_axis_map: HashMap<Axis, Vec<AxisMenuAction>>,
pub pan_sensitivity: u32, pub pan_sensitivity: u32,
pub pan_invert_y: bool,
pub axis_deadzones: HashMap<Axis, f32>, pub axis_deadzones: HashMap<Axis, f32>,
pub button_deadzones: HashMap<AnalogButton, f32>, pub button_deadzones: HashMap<AnalogButton, f32>,
pub mouse_emulation_sensitivity: u32, pub mouse_emulation_sensitivity: u32,
@ -259,6 +260,7 @@ impl From<&crate::settings::GamepadSettings> for ControllerSettings {
map map
}, },
pan_sensitivity: settings.pan_sensitivity, pan_sensitivity: settings.pan_sensitivity,
pan_invert_y: settings.pan_invert_y,
axis_deadzones: settings.axis_deadzones.clone(), axis_deadzones: settings.axis_deadzones.clone(),
button_deadzones: settings.button_deadzones.clone(), button_deadzones: settings.button_deadzones.clone(),
mouse_emulation_sensitivity: settings.mouse_emulation_sensitivity, mouse_emulation_sensitivity: settings.mouse_emulation_sensitivity,

View File

@ -348,6 +348,7 @@ pub enum Event {
AdjustMouseZoom(u32), AdjustMouseZoom(u32),
ToggleZoomInvert(bool), ToggleZoomInvert(bool),
ToggleMouseYInvert(bool), ToggleMouseYInvert(bool),
ToggleControllerYInvert(bool),
ToggleSmoothPan(bool), ToggleSmoothPan(bool),
AdjustViewDistance(u32), AdjustViewDistance(u32),
AdjustLodDetail(u32), AdjustLodDetail(u32),
@ -2328,6 +2329,9 @@ impl Hud {
settings_window::Event::ToggleMouseYInvert(mouse_y_inverted) => { settings_window::Event::ToggleMouseYInvert(mouse_y_inverted) => {
events.push(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) => { settings_window::Event::ToggleSmoothPan(smooth_pan_enabled) => {
events.push(Event::ToggleSmoothPan(smooth_pan_enabled)); events.push(Event::ToggleSmoothPan(smooth_pan_enabled));
}, },

View File

@ -95,6 +95,8 @@ widget_ids! {
mouse_zoom_invert_label, mouse_zoom_invert_label,
mouse_y_invert_button, mouse_y_invert_button,
mouse_y_invert_label, mouse_y_invert_label,
controller_y_invert_button,
controller_y_invert_label,
smooth_pan_toggle_button, smooth_pan_toggle_button,
smooth_pan_toggle_label, smooth_pan_toggle_label,
ch_title, ch_title,
@ -296,6 +298,7 @@ pub enum Event {
AdjustMouseZoom(u32), AdjustMouseZoom(u32),
ToggleZoomInvert(bool), ToggleZoomInvert(bool),
ToggleMouseYInvert(bool), ToggleMouseYInvert(bool),
ToggleControllerYInvert(bool),
ToggleSmoothPan(bool), ToggleSmoothPan(bool),
AdjustViewDistance(u32), AdjustViewDistance(u32),
AdjustSpriteRenderDistance(u32), AdjustSpriteRenderDistance(u32),
@ -1455,6 +1458,36 @@ impl<'a> Widget for SettingsWindow<'a> {
.color(TEXT_COLOR) .color(TEXT_COLOR)
.set(state.ids.mouse_y_invert_label, ui); .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 // Mouse Smoothing Toggle
let smooth_pan_enabled = ToggleButton::new( let smooth_pan_enabled = ToggleButton::new(
self.global_state.settings.gameplay.smooth_pan_enable, self.global_state.settings.gameplay.smooth_pan_enable,
@ -1462,7 +1495,7 @@ impl<'a> Widget for SettingsWindow<'a> {
self.imgs.checkbox_checked, self.imgs.checkbox_checked,
) )
.w_h(18.0, 18.0) .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) .hover_images(self.imgs.checkbox_mo, self.imgs.checkbox_checked_mo)
.press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked) .press_images(self.imgs.checkbox_press, self.imgs.checkbox_checked)
.set(state.ids.smooth_pan_toggle_button, ui); .set(state.ids.smooth_pan_toggle_button, ui);

View File

@ -906,6 +906,12 @@ impl PlayState for SessionState {
global_state.settings.gameplay.mouse_y_inversion = mouse_y_inverted; global_state.settings.gameplay.mouse_y_inversion = mouse_y_inverted;
global_state.settings.save_to_file_warn(); 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) => { HudEvent::ToggleSmoothPan(smooth_pan_enabled) => {
global_state.settings.gameplay.smooth_pan_enable = smooth_pan_enabled; global_state.settings.gameplay.smooth_pan_enable = smooth_pan_enabled;
global_state.settings.save_to_file_warn(); global_state.settings.save_to_file_warn();

View File

@ -513,7 +513,7 @@ pub struct Window {
events: Vec<Event>, events: Vec<Event>,
focused: bool, focused: bool,
gilrs: Option<Gilrs>, gilrs: Option<Gilrs>,
controller_settings: ControllerSettings, pub controller_settings: ControllerSettings,
cursor_position: winit::dpi::PhysicalPosition<f64>, cursor_position: winit::dpi::PhysicalPosition<f64>,
mouse_emulation_vec: Vec2<f32>, mouse_emulation_vec: Vec2<f32>,
// Currently used to send and receive screenshot result messages // Currently used to send and receive screenshot result messages
@ -776,13 +776,18 @@ impl Window {
)); ));
}, },
AxisGameAction::CameraY => { AxisGameAction::CameraY => {
let pan_invert_y =
match self.controller_settings.pan_invert_y {
true => -1.0,
false => 1.0,
};
self.events.push(Event::AnalogGameInput( self.events.push(Event::AnalogGameInput(
AnalogGameInput::CameraY( AnalogGameInput::CameraY(
// TODO: Use pan_invert_y here. Remove - in
// front of `value` as well
-value -value
* self.controller_settings.pan_sensitivity * self.controller_settings.pan_sensitivity
as f32 as f32
* pan_invert_y
/ 100.0, / 100.0,
), ),
)); ));