Changes setting type to u32, enforces live in-game updates to setting.

This commit is contained in:
Cody 2019-06-06 13:42:13 -04:00
parent a90d073c22
commit 41f3cd5803
No known key found for this signature in database
GPG Key ID: 4953DADF9B6AD3C8
4 changed files with 42 additions and 22 deletions

View File

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

View File

@ -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) => {

View File

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

View File

@ -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<KeyMouse, GameInput>,
@ -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)))
}
_ => {}
},