mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Adds mouse sensitivity sliders that update settings file.
This commit is contained in:
parent
eb83040af3
commit
a90d073c22
@ -108,6 +108,8 @@ pub struct DebugInfo {
|
||||
|
||||
pub enum Event {
|
||||
SendMessage(String),
|
||||
AdjustMousePan(u32),
|
||||
AdjustMouseZoom(u32),
|
||||
AdjustViewDistance(u32),
|
||||
AdjustVolume(f32),
|
||||
ChangeAudioDevice(String),
|
||||
@ -567,6 +569,12 @@ impl Hud {
|
||||
settings_window::Event::ToggleDebug => self.show.debug = !self.show.debug,
|
||||
settings_window::Event::ChangeTab(tab) => self.show.open_setting_tab(tab),
|
||||
settings_window::Event::Close => self.show.settings(false),
|
||||
settings_window::Event::AdjustMousePan(sensitivity) => {
|
||||
events.push(Event::AdjustMousePan(sensitivity));
|
||||
}
|
||||
settings_window::Event::AdjustMouseZoom(sensitivity) => {
|
||||
events.push(Event::AdjustMouseZoom(sensitivity));
|
||||
}
|
||||
settings_window::Event::AdjustViewDistance(view_distance) => {
|
||||
events.push(Event::AdjustViewDistance(view_distance));
|
||||
}
|
||||
|
@ -31,6 +31,10 @@ widget_ids! {
|
||||
interface,
|
||||
inventory_test_button,
|
||||
inventory_test_button_label,
|
||||
mouse_pan_slider,
|
||||
mouse_pan_text,
|
||||
mouse_zoom_slider,
|
||||
mouse_zoom_text,
|
||||
settings_bg,
|
||||
sound,
|
||||
test,
|
||||
@ -92,6 +96,8 @@ pub enum Event {
|
||||
ToggleDebug,
|
||||
ChangeTab(SettingsTab),
|
||||
Close,
|
||||
AdjustMousePan(u32),
|
||||
AdjustMouseZoom(u32),
|
||||
AdjustViewDistance(u32),
|
||||
AdjustVolume(f32),
|
||||
ChangeAudioDevice(String),
|
||||
@ -160,7 +166,7 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
.color(TEXT_COLOR)
|
||||
.set(state.ids.settings_title, ui);
|
||||
|
||||
// Interface
|
||||
// 1) Interface Tab -------------------------------
|
||||
if Button::image(if let SettingsTab::Interface = self.show.settings_tab {
|
||||
self.imgs.settings_button_pressed
|
||||
} else {
|
||||
@ -187,6 +193,7 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
events.push(Event::ChangeTab(SettingsTab::Interface));
|
||||
}
|
||||
|
||||
// Contents
|
||||
if let SettingsTab::Interface = self.show.settings_tab {
|
||||
// Help
|
||||
let show_help =
|
||||
@ -255,7 +262,7 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
.set(state.ids.debug_button_label, ui);
|
||||
}
|
||||
|
||||
// 2 Gameplay
|
||||
// 2) Gameplay Tab --------------------------------
|
||||
if Button::image(if let SettingsTab::Gameplay = self.show.settings_tab {
|
||||
self.imgs.settings_button_pressed
|
||||
} else {
|
||||
@ -282,7 +289,58 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
events.push(Event::ChangeTab(SettingsTab::Gameplay));
|
||||
}
|
||||
|
||||
// 3 Controls
|
||||
// Contents
|
||||
if let SettingsTab::Gameplay = self.show.settings_tab {
|
||||
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);
|
||||
|
||||
if let Some(new_val) = ImageSlider::discrete(
|
||||
(self.global_state.settings.gameplay.pan_sensitivity * 100.0) as u32,
|
||||
1,
|
||||
200,
|
||||
self.imgs.slider_indicator,
|
||||
self.imgs.slider,
|
||||
)
|
||||
.w_h(208.0, 22.0)
|
||||
.down_from(state.ids.mouse_pan_text, 10.0)
|
||||
.track_breadth(30.0)
|
||||
.slider_length(10.0)
|
||||
.pad_track((5.0, 5.0))
|
||||
.set(state.ids.mouse_pan_slider, ui)
|
||||
{
|
||||
events.push(Event::AdjustMousePan(new_val));
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
if let Some(new_val) = ImageSlider::discrete(
|
||||
(self.global_state.settings.gameplay.zoom_sensitivity * 100.0) as u32,
|
||||
1,
|
||||
200,
|
||||
self.imgs.slider_indicator,
|
||||
self.imgs.slider,
|
||||
)
|
||||
.w_h(208.0, 22.0)
|
||||
.down_from(state.ids.mouse_zoom_text, 10.0)
|
||||
.track_breadth(30.0)
|
||||
.slider_length(10.0)
|
||||
.pad_track((5.0, 5.0))
|
||||
.set(state.ids.mouse_zoom_slider, ui)
|
||||
{
|
||||
events.push(Event::AdjustMouseZoom(new_val));
|
||||
}
|
||||
}
|
||||
|
||||
// 3) Controls Tab --------------------------------
|
||||
if Button::image(if let SettingsTab::Controls = self.show.settings_tab {
|
||||
self.imgs.settings_button_pressed
|
||||
} else {
|
||||
@ -308,6 +366,8 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
{
|
||||
events.push(Event::ChangeTab(SettingsTab::Controls));
|
||||
}
|
||||
|
||||
// Contents
|
||||
if let SettingsTab::Controls = self.show.settings_tab {
|
||||
Text::new(
|
||||
"Free Cursor\n\
|
||||
@ -376,7 +436,6 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
/tp [Name] - Teleports you to another player \n\
|
||||
/jump <dx> <dy> <dz> - Offset your position \n\
|
||||
/goto <x> <y> <z> - Teleport to a position \n\
|
||||
/tp <name> - Teleport to another player \n\
|
||||
/kill - Kill yourself \n\
|
||||
/pig - Spawn pig NPC \n\
|
||||
/wolf - Spawn wolf NPC \n\
|
||||
@ -462,7 +521,8 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
.font_size(18)
|
||||
.set(state.ids.controls_controls, ui);
|
||||
}
|
||||
// 4 Video
|
||||
|
||||
// 4) Video Tab -----------------------------------
|
||||
if Button::image(if let SettingsTab::Video = self.show.settings_tab {
|
||||
self.imgs.settings_button_pressed
|
||||
} else {
|
||||
@ -489,6 +549,7 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
{
|
||||
events.push(Event::ChangeTab(SettingsTab::Video));
|
||||
}
|
||||
|
||||
// Contents
|
||||
if let SettingsTab::Video = self.show.settings_tab {
|
||||
Text::new("View Distance")
|
||||
@ -515,7 +576,8 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
events.push(Event::AdjustViewDistance(new_val));
|
||||
}
|
||||
}
|
||||
// 5 Sound
|
||||
|
||||
// 5) Sound Tab -----------------------------------
|
||||
if Button::image(if let SettingsTab::Sound = self.show.settings_tab {
|
||||
self.imgs.settings_button_pressed
|
||||
} else {
|
||||
@ -542,6 +604,7 @@ impl<'a> Widget for SettingsWindow<'a> {
|
||||
{
|
||||
events.push(Event::ChangeTab(SettingsTab::Sound));
|
||||
}
|
||||
|
||||
// Contents
|
||||
if let SettingsTab::Sound = self.show.settings_tab {
|
||||
Text::new("Volume")
|
||||
|
@ -149,10 +149,10 @@ impl PlayState for SessionState {
|
||||
return PlayStateResult::Pop;
|
||||
}
|
||||
|
||||
// Maintain global state
|
||||
// Maintain global state.
|
||||
global_state.maintain();
|
||||
|
||||
// extract HUD events ensuring the client borrow gets dropped
|
||||
// Extract HUD events ensuring the client borrow gets dropped.
|
||||
let hud_events = self.hud.maintain(
|
||||
&self.client.borrow(),
|
||||
global_state,
|
||||
@ -170,6 +170,7 @@ impl PlayState for SessionState {
|
||||
},
|
||||
&self.scene.camera(),
|
||||
);
|
||||
|
||||
// Maintain the UI.
|
||||
for event in hud_events {
|
||||
match event {
|
||||
@ -184,6 +185,15 @@ impl PlayState for SessionState {
|
||||
HudEvent::Quit => {
|
||||
return PlayStateResult::Shutdown;
|
||||
}
|
||||
HudEvent::AdjustMousePan(sensitivity) => {
|
||||
global_state.settings.gameplay.pan_sensitivity = sensitivity as f32 / 100.0;
|
||||
global_state.settings.save_to_file();
|
||||
}
|
||||
HudEvent::AdjustMouseZoom(sensitivity) => {
|
||||
global_state.settings.gameplay.zoom_sensitivity =
|
||||
sensitivity as f32 / 100.0;
|
||||
global_state.settings.save_to_file();
|
||||
}
|
||||
HudEvent::AdjustViewDistance(view_distance) => {
|
||||
self.client.borrow_mut().set_view_distance(view_distance);
|
||||
|
||||
|
@ -4,11 +4,12 @@ use glutin::{MouseButton, VirtualKeyCode};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::{fs, io::prelude::*, path::PathBuf};
|
||||
|
||||
/// `Settings` contains everything that can be configured in the Settings.toml file.
|
||||
/// `Settings` contains everything that can be configured in the settings.ron file.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct Settings {
|
||||
pub controls: ControlSettings,
|
||||
pub gameplay: GameplaySettings,
|
||||
pub networking: NetworkingSettings,
|
||||
pub log: Log,
|
||||
pub graphics: GraphicsSettings,
|
||||
@ -41,9 +42,14 @@ pub struct ControlSettings {
|
||||
pub fullscreen: KeyMouse,
|
||||
pub screenshot: KeyMouse,
|
||||
pub toggle_ingame_ui: KeyMouse,
|
||||
pub attack: KeyMouse,
|
||||
}
|
||||
|
||||
/// `GameplaySettings` contains sensitivity and gameplay options.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct GameplaySettings {
|
||||
pub pan_sensitivity: f32,
|
||||
pub zoom_sensitivity: f32,
|
||||
pub attack: KeyMouse,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
@ -100,9 +106,11 @@ impl Default for Settings {
|
||||
fullscreen: KeyMouse::Key(VirtualKeyCode::F11),
|
||||
screenshot: KeyMouse::Key(VirtualKeyCode::F4),
|
||||
toggle_ingame_ui: KeyMouse::Key(VirtualKeyCode::F6),
|
||||
attack: KeyMouse::Mouse(MouseButton::Left),
|
||||
},
|
||||
gameplay: GameplaySettings {
|
||||
pan_sensitivity: 1.0,
|
||||
zoom_sensitivity: 1.0,
|
||||
attack: KeyMouse::Mouse(MouseButton::Left),
|
||||
},
|
||||
networking: NetworkingSettings {
|
||||
username: "Username".to_string(),
|
||||
|
@ -54,7 +54,7 @@ pub enum Event {
|
||||
InputUpdate(GameInput, bool),
|
||||
/// Event that the ui uses.
|
||||
Ui(ui::Event),
|
||||
// The view distance has been changed
|
||||
/// The view distance has changed.
|
||||
ViewDistanceChanged(u32),
|
||||
/// Game settings have changed.
|
||||
SettingsChanged,
|
||||
@ -140,8 +140,8 @@ impl Window {
|
||||
renderer: Renderer::new(device, factory, win_color_view, win_depth_view)?,
|
||||
window,
|
||||
cursor_grabbed: false,
|
||||
pan_sensitivity: settings.controls.pan_sensitivity,
|
||||
zoom_sensitivity: settings.controls.zoom_sensitivity,
|
||||
pan_sensitivity: settings.gameplay.pan_sensitivity,
|
||||
zoom_sensitivity: settings.gameplay.zoom_sensitivity,
|
||||
fullscreen: false,
|
||||
needs_refresh_resize: false,
|
||||
key_map,
|
||||
|
Loading…
Reference in New Issue
Block a user