From 16b66f9cd6f9400816c9bb25d7f4a3920b889836 Mon Sep 17 00:00:00 2001 From: Adam Blanchet Date: Mon, 8 Mar 2021 17:24:03 +0100 Subject: [PATCH] Add reset button to graphics settings --- CHANGELOG.md | 1 + assets/voxygen/i18n/en/hud/hud_settings.ron | 1 + voxygen/src/hud/mod.rs | 4 +++ voxygen/src/hud/settings_window.rs | 19 ++++++++++++++ voxygen/src/session.rs | 28 ++++++++++++++++++++- 5 files changed, 52 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4976a302f3..43a0609889 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Procedural trees (currently only oaks and pines are procedural) - Cliffs on steep slopes - Giant tree sites +- Reset button for graphics settings ### Changed diff --git a/assets/voxygen/i18n/en/hud/hud_settings.ron b/assets/voxygen/i18n/en/hud/hud_settings.ron index 4443d7a70d..b208c000ca 100644 --- a/assets/voxygen/i18n/en/hud/hud_settings.ron +++ b/assets/voxygen/i18n/en/hud/hud_settings.ron @@ -85,6 +85,7 @@ "hud.settings.shadow_rendering_mode.map.resolution": "Resolution", "hud.settings.lod_detail": "LoD Detail", "hud.settings.save_window_size": "Save window size", + "hud.settings.reset_graphics": "Reset to Defaults", "hud.settings.music_volume": "Music Volume", diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 7efda93209..6395ceff88 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -408,6 +408,7 @@ pub enum Event { ChangeLanguage(Box), ChangeBinding(GameInput), ResetBindings, + ResetGraphics, ChangeFreeLookBehavior(PressBehavior), ChangeRenderMode(Box), ChangeAutoWalkBehavior(PressBehavior), @@ -2527,6 +2528,9 @@ impl Hud { settings_window::Event::ChangeStopAutoWalkOnInput(state) => { events.push(Event::ChangeStopAutoWalkOnInput(state)); }, + settings_window::Event::ResetGraphics => { + events.push(Event::ResetGraphics); + }, } } } diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index b029ec68ec..40079902d9 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -60,6 +60,7 @@ widget_ids! { controls_texts[], controls_buttons[], reset_controls_button, + reset_graphics_button, controls_alignment_rectangle, button_help, button_help2, @@ -329,6 +330,7 @@ pub enum Event { ChangeLanguage(Box), ChangeBinding(GameInput), ResetBindings, + ResetGraphics, ChangeFreeLookBehavior(PressBehavior), ChangeAutoWalkBehavior(PressBehavior), ChangeStopAutoWalkOnInput(bool), @@ -2709,6 +2711,23 @@ impl<'a> Widget for SettingsWindow<'a> { .into_array(), )); } + + // Save current screen size + if Button::image(self.imgs.button) + .w_h(31.0 * 5.0, 12.0 * 2.0) + .hover_image(self.imgs.button_hover) + .press_image(self.imgs.button_press) + .down_from(state.ids.save_window_size_button, 12.0) + .label(&self.localized_strings.get("hud.settings.reset_graphics")) + .label_font_size(self.fonts.cyri.scale(14)) + .label_color(TEXT_COLOR) + .label_font_id(self.fonts.cyri.conrod_id) + .label_y(Relative::Scalar(2.0)) + .set(state.ids.reset_graphics_button, ui) + .was_clicked() + { + events.push(Event::ResetGraphics); + } } // 5) Sound Tab ----------------------------------- diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 4344a54162..895e3c1af7 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -38,7 +38,7 @@ use crate::{ menu::char_selection::CharSelectionState, render::Renderer, scene::{camera, CameraMode, Scene, SceneData}, - settings::{ControlSettings, Settings}, + settings::{ControlSettings, GraphicsSettings, Settings}, window::{AnalogGameInput, Event, GameInput}, Direction, Error, GlobalState, PlayState, PlayStateResult, }; @@ -1362,6 +1362,32 @@ impl PlayState for SessionState { global_state.settings.gameplay.minimap_face_north = state; global_state.settings.save_to_file_warn(); }, + HudEvent::ResetGraphics => { + global_state.settings.graphics = GraphicsSettings::default(); + global_state.settings.save_to_file_warn(); + let graphics = &global_state.settings.graphics; + // View distance + self.client + .borrow_mut() + .set_view_distance(graphics.view_distance); + // FOV + self.scene.camera_mut().set_fov_deg(graphics.fov); + self.scene + .camera_mut() + .compute_dependents(&*self.client.borrow().state().terrain()); + // LoD + self.scene.lod.set_detail(graphics.lod_detail); + // Render mode + global_state + .window + .renderer_mut() + .set_render_mode(graphics.render_mode.clone()) + .unwrap(); + // Fullscreen mode + global_state.window.set_fullscreen_mode(graphics.fullscreen); + // Window size + global_state.window.set_size(graphics.window_size.into()); + }, } }