Merge branch 'treeco/invert-mouse-setting' into 'master'

Added mouse inversion setting

Closes #376

See merge request veloren/veloren!677
This commit is contained in:
Acrimon 2019-12-06 23:24:55 +00:00
commit 3e2fe36a8c
5 changed files with 47 additions and 1 deletions

View File

@ -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));
}

View File

@ -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 --------------------------------

View File

@ -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);

View File

@ -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,

View File

@ -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<KeyMouse, Vec<GameInput>>,
@ -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 {