From 0349461533c150968c7fe8d751b9562b931b5afd Mon Sep 17 00:00:00 2001 From: Imbris Date: Sat, 18 May 2019 19:55:06 -0400 Subject: [PATCH] Pass up Vd slider changes to session.rs & fmt Former-commit-id: 187a3d286e288d2159fcde292f78e2bc08ec796b --- voxygen/src/hud/img_ids.rs | 2 +- voxygen/src/hud/mod.rs | 25 +++++++----- voxygen/src/hud/settings_window.rs | 62 +++++++++++++++++------------- voxygen/src/session.rs | 4 ++ 4 files changed, 57 insertions(+), 36 deletions(-) diff --git a/voxygen/src/hud/img_ids.rs b/voxygen/src/hud/img_ids.rs index 5060ebce44..d514b4e1af 100644 --- a/voxygen/src/hud/img_ids.rs +++ b/voxygen/src/hud/img_ids.rs @@ -127,7 +127,7 @@ image_ids! { charwindow_gradient:"voxygen/element/misc_bg/charwindow.png", // Spell Book Window - spellbook_icon: "voxygen/element/icons/spellbook.png", + spellbook_icon: "voxygen/element/icons/spellbook.png", // Bag bag: "voxygen/element/buttons/bag/closed.png", bag_hover: "voxygen/element/buttons/bag/closed_hover.png", diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 1f1b51d590..acad613cca 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -90,6 +90,7 @@ font_ids! { pub enum Event { SendMessage(String), + AdjustVd(u8), Logout, Quit, } @@ -207,6 +208,8 @@ pub struct Hud { to_focus: Option>, settings: Settings, force_ungrab: bool, + // TODO: move to settings + current_vd: u8, } impl Hud { @@ -243,6 +246,7 @@ impl Hud { to_focus: None, settings, force_ungrab: false, + current_vd: 5, } } @@ -372,18 +376,21 @@ impl Hud { // Settings if let Windows::Settings = self.show.open_windows { - match SettingsWindow::new(&self.show, &self.imgs, &self.fonts) + for event in SettingsWindow::new(&self.show, &self.imgs, &self.fonts, self.current_vd) .set(self.ids.settings_window, ui_widgets) { - Some(settings_window::Event::ToggleHelp) => self.show.toggle_help(), - Some(settings_window::Event::ToggleInventoryTestButton) => { - self.show.inventory_test_button = !self.show.inventory_test_button + match event { + settings_window::Event::ToggleHelp => self.show.toggle_help(), + settings_window::Event::ToggleInventoryTestButton => { + self.show.inventory_test_button = !self.show.inventory_test_button + } + settings_window::Event::ToggleDebug => self.show.debug = !self.show.debug, + settings_window::Event::Close => self.show.open_windows = Windows::None, + settings_window::Event::AdjustVd(new_vd) => { + self.current_vd = new_vd; + events.push(Event::AdjustVd(new_vd)); + } } - Some(settings_window::Event::ToggleDebug) => self.show.debug = !self.show.debug, - Some(settings_window::Event::Close) => { - self.show.open_windows = Windows::None; - } - None => {} } } diff --git a/voxygen/src/hud/settings_window.rs b/voxygen/src/hud/settings_window.rs index e713a7b156..11573b8d63 100644 --- a/voxygen/src/hud/settings_window.rs +++ b/voxygen/src/hud/settings_window.rs @@ -1,10 +1,5 @@ use super::{img_ids::Imgs, Fonts, TEXT_COLOR}; use crate::{hud::Show, ui::ToggleButton}; -use conrod_core::{ - color, - widget::{self, Button, Image, Rectangle, Scrollbar, Text}, - widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon, -}; use crate::{ render::Renderer, ui::{ @@ -14,6 +9,11 @@ use crate::{ }, window::Window, }; +use conrod_core::{ + color, + widget::{self, Button, Image, Rectangle, Scrollbar, Text}, + widget_ids, Colorable, Labelable, Positionable, Sizeable, Widget, WidgetCommon, +}; widget_ids! { struct Ids { @@ -62,16 +62,19 @@ pub struct SettingsWindow<'a> { imgs: &'a Imgs, fonts: &'a Fonts, + current_vd: u8, + #[conrod(common_builder)] common: widget::CommonBuilder, } impl<'a> SettingsWindow<'a> { - pub fn new(show: &'a Show, imgs: &'a Imgs, fonts: &'a Fonts) -> Self { + pub fn new(show: &'a Show, imgs: &'a Imgs, fonts: &'a Fonts, current_vd: u8) -> Self { Self { show, imgs, fonts, + current_vd, common: widget::CommonBuilder::default(), } } @@ -88,12 +91,13 @@ pub enum Event { ToggleInventoryTestButton, ToggleDebug, Close, + AdjustVd(u8), } impl<'a> Widget for SettingsWindow<'a> { type State = State; type Style = (); - type Event = Option; + type Event = Vec; fn init_state(&self, id_gen: widget::id::Generator) -> Self::State { State { @@ -109,6 +113,8 @@ impl<'a> Widget for SettingsWindow<'a> { fn update(self, args: widget::UpdateArgs) -> Self::Event { let widget::UpdateArgs { state, ui, .. } = args; + let mut events = Vec::new(); + // Frame Alignment Rectangle::fill_with([824.0, 488.0], color::TRANSPARENT) .middle_of(ui.window) @@ -142,7 +148,7 @@ impl<'a> Widget for SettingsWindow<'a> { .set(state.ids.settings_close, ui) .was_clicked() { - return Some(Event::Close); + events.push(Event::Close); } // Title @@ -190,7 +196,7 @@ impl<'a> Widget for SettingsWindow<'a> { .set(state.ids.button_help, ui); if self.show.help != show_help { - return Some(Event::ToggleHelp); + events.push(Event::ToggleHelp); } Text::new("Show Help") @@ -214,7 +220,7 @@ impl<'a> Widget for SettingsWindow<'a> { .set(state.ids.inventory_test_button, ui); if self.show.inventory_test_button != inventory_test_button { - return Some(Event::ToggleInventoryTestButton); + events.push(Event::ToggleInventoryTestButton); } Text::new("Show Inventory Test Button") @@ -235,7 +241,7 @@ impl<'a> Widget for SettingsWindow<'a> { .set(state.ids.debug_button, ui); if self.show.debug != show_debug { - return Some(Event::ToggleDebug); + events.push(Event::ToggleDebug); } Text::new("Show Debug Window") @@ -461,26 +467,30 @@ impl<'a> Widget for SettingsWindow<'a> { state.update(|s| s.settings_tab = SettingsTab::Video); } // Contents - if let SettingsTab::Video = state.settings_tab { - Text::new("Viewdistance") - .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.vd_slider_text, ui); + if let SettingsTab::Video = state.settings_tab { + Text::new("Viewdistance") + .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.vd_slider_text, ui); - if let Some(new_val) = ImageSlider::continuous(5.0, - 5.0, - 25.0, - self.imgs.slider_indicator, - self.imgs.slider,) - .w_h(208.0, 22.0) + if let Some(new_val) = ImageSlider::discrete( + self.current_vd, + 1, + 25, + self.imgs.slider_indicator, + self.imgs.slider, + ) + .w_h(104.0, 22.0) .down_from(state.ids.vd_slider_text, 10.0) .track_breadth(12.0) .slider_length(10.0) .pad_track((5.0, 5.0)) .set(state.ids.vd_slider, ui) - {} + { + events.push(Event::AdjustVd(new_val)); + } } // 5 Sound if Button::image(if let SettingsTab::Sound = state.settings_tab { @@ -510,6 +520,6 @@ impl<'a> Widget for SettingsWindow<'a> { state.update(|s| s.settings_tab = SettingsTab::Sound); } - None + events } } diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 8b958d5a21..912adfc7b3 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -190,6 +190,10 @@ impl PlayState for SessionState { HudEvent::Quit => { return PlayStateResult::Shutdown; } + HudEvent::AdjustVd(new_vd) => { + println!("New VD is {}, TODO: Actually change VD", new_vd); + //self.client.borrow_mut().set_vd(new_vd); + } } }