From 41f3cd58039102ca61831445c99838ed5b60a5c6 Mon Sep 17 00:00:00 2001 From: Cody Date: Thu, 6 Jun 2019 13:42:13 -0400 Subject: [PATCH] Changes setting type to u32, enforces live in-game updates to setting. --- voxygen/src/hud/settings_window.rs | 39 ++++++++++++++++++++++-------- voxygen/src/session.rs | 7 +++--- voxygen/src/settings.rs | 8 +++--- voxygen/src/window.rs | 10 ++++---- 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index a0533f0938..0acea547e6 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -32,9 +32,11 @@ widget_ids! { inventory_test_button, inventory_test_button_label, mouse_pan_slider, - mouse_pan_text, + mouse_pan_label, + mouse_pan_value, mouse_zoom_slider, - mouse_zoom_text, + mouse_zoom_label, + mouse_zoom_value, settings_bg, sound, test, @@ -291,22 +293,25 @@ impl<'a> Widget for SettingsWindow<'a> { // Contents if let SettingsTab::Gameplay = self.show.settings_tab { + let display_pan = self.global_state.settings.gameplay.pan_sensitivity; + let display_zoom = self.global_state.settings.gameplay.zoom_sensitivity; + Text::new("Pan Sensitivity") .top_left_with_margins_on(state.ids.settings_content, 10.0, 10.0) .font_size(14) .font_id(self.fonts.opensans) .color(TEXT_COLOR) - .set(state.ids.mouse_pan_text, ui); + .set(state.ids.mouse_pan_label, ui); if let Some(new_val) = ImageSlider::discrete( - (self.global_state.settings.gameplay.pan_sensitivity * 100.0) as u32, + display_pan, 1, 200, self.imgs.slider_indicator, self.imgs.slider, ) - .w_h(208.0, 22.0) - .down_from(state.ids.mouse_pan_text, 10.0) + .w_h(550.0, 22.0) + .down_from(state.ids.mouse_pan_label, 10.0) .track_breadth(30.0) .slider_length(10.0) .pad_track((5.0, 5.0)) @@ -315,22 +320,29 @@ impl<'a> Widget for SettingsWindow<'a> { events.push(Event::AdjustMousePan(new_val)); } + Text::new(&format!("{}", display_pan)) + .right_from(state.ids.mouse_pan_slider, 8.0) + .font_size(14) + .font_id(self.fonts.opensans) + .color(TEXT_COLOR) + .set(state.ids.mouse_pan_value, ui); + Text::new("Zoom Sensitivity") .down_from(state.ids.mouse_pan_slider, 10.0) .font_size(14) .font_id(self.fonts.opensans) .color(TEXT_COLOR) - .set(state.ids.mouse_zoom_text, ui); + .set(state.ids.mouse_zoom_label, ui); if let Some(new_val) = ImageSlider::discrete( - (self.global_state.settings.gameplay.zoom_sensitivity * 100.0) as u32, + display_zoom, 1, 200, self.imgs.slider_indicator, self.imgs.slider, ) - .w_h(208.0, 22.0) - .down_from(state.ids.mouse_zoom_text, 10.0) + .w_h(550.0, 22.0) + .down_from(state.ids.mouse_zoom_label, 10.0) .track_breadth(30.0) .slider_length(10.0) .pad_track((5.0, 5.0)) @@ -338,6 +350,13 @@ impl<'a> Widget for SettingsWindow<'a> { { events.push(Event::AdjustMouseZoom(new_val)); } + + Text::new(&format!("{}", display_zoom)) + .right_from(state.ids.mouse_zoom_slider, 8.0) + .font_size(14) + .font_id(self.fonts.opensans) + .color(TEXT_COLOR) + .set(state.ids.mouse_zoom_value, ui); } // 3) Controls Tab -------------------------------- diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 28aa3d8f2c..253737924e 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -186,12 +186,13 @@ impl PlayState for SessionState { return PlayStateResult::Shutdown; } HudEvent::AdjustMousePan(sensitivity) => { - global_state.settings.gameplay.pan_sensitivity = sensitivity as f32 / 100.0; + global_state.window.pan_sensitivity = sensitivity; + global_state.settings.gameplay.pan_sensitivity = sensitivity; global_state.settings.save_to_file(); } HudEvent::AdjustMouseZoom(sensitivity) => { - global_state.settings.gameplay.zoom_sensitivity = - sensitivity as f32 / 100.0; + global_state.window.zoom_sensitivity = sensitivity; + global_state.settings.gameplay.zoom_sensitivity = sensitivity; global_state.settings.save_to_file(); } HudEvent::AdjustViewDistance(view_distance) => { diff --git a/voxygen/src/settings.rs b/voxygen/src/settings.rs index 488413ef02..63e1cccfa6 100644 --- a/voxygen/src/settings.rs +++ b/voxygen/src/settings.rs @@ -48,8 +48,8 @@ pub struct ControlSettings { /// `GameplaySettings` contains sensitivity and gameplay options. #[derive(Clone, Debug, Serialize, Deserialize)] pub struct GameplaySettings { - pub pan_sensitivity: f32, - pub zoom_sensitivity: f32, + pub pan_sensitivity: u32, + pub zoom_sensitivity: u32, } #[derive(Clone, Debug, Serialize, Deserialize)] @@ -109,8 +109,8 @@ impl Default for Settings { attack: KeyMouse::Mouse(MouseButton::Left), }, gameplay: GameplaySettings { - pan_sensitivity: 1.0, - zoom_sensitivity: 1.0, + pan_sensitivity: 100, + zoom_sensitivity: 100, }, networking: NetworkingSettings { username: "Username".to_string(), diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index de1f02d94f..fd158a4708 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -71,8 +71,8 @@ pub struct Window { renderer: Renderer, window: glutin::GlWindow, cursor_grabbed: bool, - pub pan_sensitivity: f32, - pub zoom_sensitivity: f32, + pub pan_sensitivity: u32, + pub zoom_sensitivity: u32, fullscreen: bool, needs_refresh_resize: bool, key_map: HashMap, @@ -230,14 +230,14 @@ impl Window { glutin::DeviceEvent::MouseMotion { delta: (dx, dy), .. } if cursor_grabbed && *focused => events.push(Event::CursorPan(Vec2::new( - dx as f32 * pan_sensitivity, - dy as f32 * pan_sensitivity, + dx as f32 * (pan_sensitivity as f32 / 100.0), + dy as f32 * (pan_sensitivity as f32 / 100.0), ))), glutin::DeviceEvent::MouseWheel { delta: glutin::MouseScrollDelta::LineDelta(_x, y), .. } if cursor_grabbed && *focused => { - events.push(Event::Zoom(y as f32 * zoom_sensitivity)) + events.push(Event::Zoom(y * (zoom_sensitivity as f32 / 100.0))) } _ => {} },