From 50c6518d89d57f479230fbca2f9975e7f72a17fa Mon Sep 17 00:00:00 2001 From: Yeedo Date: Thu, 25 Apr 2019 14:10:01 +0100 Subject: [PATCH 01/14] Update help window to use player's keybindings (fix #42) Former-commit-id: 5f35a153f05b48ae8c21ae9735080c5c7392e2dc --- voxygen/src/hud/mod.rs | 48 ++++++++++++++++++++++++++++++------------ voxygen/src/window.rs | 12 +++++++++++ 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index a8d1f55c48..25293d1c36 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -2,6 +2,7 @@ mod chat; use crate::{ render::Renderer, + settings::{Settings, ControlSettings}, ui::{self, ScaleMode, ToggleButton, Ui}, window::{Event as WinEvent, Key, Window}, GlobalState, @@ -479,6 +480,7 @@ pub struct Hud { mana_percentage: f64, inventorytest_button: bool, settings_tab: SettingsTab, + help_text: String, } //#[inline] @@ -530,6 +532,7 @@ impl Hud { xp_percentage: 0.4, hp_percentage: 1.0, mana_percentage: 1.0, + help_text: get_help_text(&Settings::default().controls), } } @@ -597,25 +600,14 @@ impl Hud { if self.show_help { Image::new(self.imgs.window_frame_2) .top_left_with_margins_on(ui_widgets.window, 3.0, 3.0) - .w_h(300.0, 190.0) + .w_h(300.0, 450.0) .set(self.ids.help_bg, ui_widgets); - - Text::new( - "Tab = Free Cursor \n\ - Esc = Open/Close Menus \n\ - \n\ - F1 = Toggle this Window \n\ - F2 = Toggle Interface \n\ - \n\ - Enter = Open Chat \n\ - Mouse Wheel = Scroll Chat" - ) + Text::new(self.help_text.as_str()) .color(TEXT_COLOR) .top_left_with_margins_on(self.ids.help_bg, 20.0, 20.0) .font_id(self.font_opensans) .font_size(18) .set(self.ids.help, ui_widgets); - // X-button if Button::image(self.imgs.close_button) .w_h(100.0 * 0.2, 100.0 * 0.2) @@ -1771,6 +1763,10 @@ impl Hud { _ => self.typing(), }, WinEvent::Char(_) => self.typing(), + WinEvent::SettingsChanged => { + self.help_text = get_help_text(&global_state.settings.controls); + true + }, _ => false, } } @@ -1785,3 +1781,29 @@ impl Hud { self.ui.render(renderer); } } + +fn get_help_text(cs: &ControlSettings) -> String { + [ + format!("{:?} = Free cursor\n", cs.toggle_cursor), + format!("{:?} = Open/close menus\n", cs.escape), + String::from("\n"), + format!("{:?} = Toggle this window\n", cs.help), + format!("{:?} = Toggle interface\n", cs.toggle_interface), + String::from("\n"), + format!("{:?} = Open chat\n", cs.enter), + String::from("Mouse Wheel = Scroll chat\n"), + String::from("\n"), + format!("{:?} = Move forward\n", cs.move_forward), + format!("{:?} = Move left\n", cs.move_left), + format!("{:?} = Move right\n", cs.move_right), + format!("{:?} = Move backwards\n", cs.move_back), + String::from("\n"), + format!("{:?} = Map\n", cs.map), + format!("{:?} = Bag\n", cs.bag), + format!("{:?} = Quest log\n", cs.quest_log), + format!("{:?} = Character window\n", cs.character_window), + format!("{:?} = Social\n", cs.social), + format!("{:?} = Spellbook\n", cs.spellbook), + format!("{:?} = Settings\n", cs.settings) + ].concat() +} \ No newline at end of file diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index f13a515455..bec293bc14 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -11,6 +11,7 @@ pub struct Window { window: glutin::GlWindow, cursor_grabbed: bool, needs_refresh_resize: bool, + settings_changed: bool, key_map: HashMap, } @@ -59,6 +60,7 @@ impl Window { window, cursor_grabbed: false, needs_refresh_resize: false, + settings_changed: true, key_map, }); tmp @@ -79,6 +81,10 @@ impl Window { self.needs_refresh_resize = false; } + if self.settings_changed { + events.push(Event::SettingsChanged); + } + // Copy data that is needed by the events closure to avoid lifetime errors // TODO: Remove this if/when the compiler permits it let cursor_grabbed = self.cursor_grabbed; @@ -161,6 +167,10 @@ impl Window { .into(); Vec2::new(w, h) } + + pub fn settings_changed(&mut self) { + self.settings_changed = true; + } } /// Represents a key that the game recognises after keyboard mapping @@ -203,4 +213,6 @@ pub enum Event { KeyUp(Key), /// Event that the ui uses Ui(ui::Event), + /// Game settings have changed + SettingsChanged, } From 7593d4e821d54c90a3233a43067e6354b99dffb0 Mon Sep 17 00:00:00 2001 From: Yeedo Date: Thu, 25 Apr 2019 14:23:40 +0100 Subject: [PATCH 02/14] Tiny fix to prevent settings from permanently being marked as changed Former-commit-id: 665a8851526c1386e497064e2b0f3f8689db60d8 --- voxygen/src/window.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index bec293bc14..fdfabbb76d 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -83,6 +83,7 @@ impl Window { if self.settings_changed { events.push(Event::SettingsChanged); + self.settings_changed = false; } // Copy data that is needed by the events closure to avoid lifetime errors From be9a399269166eb0bd5861292e91e1c4a83461c4 Mon Sep 17 00:00:00 2001 From: Yeedo Date: Thu, 25 Apr 2019 16:32:59 +0100 Subject: [PATCH 03/14] Redo settings -> help text, add `supplement_events` to `Window`. Former-commit-id: 1e679a6fc3300b6269672650564405c031b151ae --- voxygen/src/hud/mod.rs | 14 +++++++------- voxygen/src/menu/char_selection/mod.rs | 2 +- voxygen/src/session.rs | 5 +++-- voxygen/src/window.rs | 16 ++++++---------- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 25293d1c36..8af320fcea 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -480,7 +480,7 @@ pub struct Hud { mana_percentage: f64, inventorytest_button: bool, settings_tab: SettingsTab, - help_text: String, + settings: Settings, } //#[inline] @@ -489,7 +489,7 @@ pub struct Hud { //} impl Hud { - pub fn new(window: &mut Window) -> Self { + pub fn new(window: &mut Window, settings: Settings) -> Self { let mut ui = Ui::new(window).unwrap(); // TODO: adjust/remove this, right now it is used to demonstrate window scaling functionality ui.scaling_mode(ScaleMode::RelativeToWindow([1920.0, 1080.0].into())); @@ -532,7 +532,7 @@ impl Hud { xp_percentage: 0.4, hp_percentage: 1.0, mana_percentage: 1.0, - help_text: get_help_text(&Settings::default().controls), + settings: settings, } } @@ -602,7 +602,7 @@ impl Hud { .top_left_with_margins_on(ui_widgets.window, 3.0, 3.0) .w_h(300.0, 450.0) .set(self.ids.help_bg, ui_widgets); - Text::new(self.help_text.as_str()) + Text::new(get_help_text(&self.settings.controls).as_str()) .color(TEXT_COLOR) .top_left_with_margins_on(self.ids.help_bg, 20.0, 20.0) .font_id(self.font_opensans) @@ -959,7 +959,7 @@ impl Hud { .press_images(self.imgs.bag_press, self.imgs.bag_open_press) .w_h(420.0 / 10.0, 480.0 / 10.0) .set(self.ids.bag, ui_widgets); - Text::new("B") + Text::new(&format!("{:?}", self.settings.controls.bag)) .bottom_right_with_margins_on(self.ids.bag, 0.0, 0.0) .font_size(10) .color(TEXT_COLOR) @@ -969,7 +969,7 @@ impl Hud { .bottom_right_with_margins_on(ui_widgets.window, 5.0, 5.0) .w_h(420.0 / 10.0, 480.0 / 10.0) .set(self.ids.bag_map_open, ui_widgets); - Text::new("B") + Text::new(&format!("{:?}", self.settings.controls.bag)) .bottom_right_with_margins_on(self.ids.bag, 0.0, 0.0) .font_size(10) .color(TEXT_COLOR) @@ -1764,7 +1764,7 @@ impl Hud { }, WinEvent::Char(_) => self.typing(), WinEvent::SettingsChanged => { - self.help_text = get_help_text(&global_state.settings.controls); + self.settings = global_state.settings.clone(); true }, _ => false, diff --git a/voxygen/src/menu/char_selection/mod.rs b/voxygen/src/menu/char_selection/mod.rs index 031f6be195..a0c5539704 100644 --- a/voxygen/src/menu/char_selection/mod.rs +++ b/voxygen/src/menu/char_selection/mod.rs @@ -70,7 +70,7 @@ impl PlayState for CharSelectionState { }, ui::Event::Play => { self.client.borrow_mut().postbox.send_message(ClientMsg::Character(self.char_selection_ui.character)); - return PlayStateResult::Switch( Box::new(SessionState::new(&mut global_state.window, self.client.clone()))); + return PlayStateResult::Switch( Box::new(SessionState::new(&mut global_state.window, self.client.clone(), global_state.settings.clone()))); } } } diff --git a/voxygen/src/session.rs b/voxygen/src/session.rs index 77d1279140..1b29c6ca81 100644 --- a/voxygen/src/session.rs +++ b/voxygen/src/session.rs @@ -15,6 +15,7 @@ use crate::{ window::{Event, Key, Window}, render::Renderer, scene::Scene, + settings::Settings, hud::{Hud, Event as HudEvent}, }; @@ -31,14 +32,14 @@ pub struct SessionState { /// Represents an active game session (i.e: one that is being played) impl SessionState { /// Create a new `SessionState` - pub fn new(window: &mut Window, client: Rc>) -> Self { + pub fn new(window: &mut Window, client: Rc>, settings: Settings) -> Self { // Create a scene for this session. The scene handles visible elements of the game world let scene = Scene::new(window.renderer_mut(), &client.borrow()); Self { scene, client, key_state: KeyState::new(), - hud: Hud::new(window), + hud: Hud::new(window, settings), } } } diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index fdfabbb76d..e3d88998c9 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -11,8 +11,8 @@ pub struct Window { window: glutin::GlWindow, cursor_grabbed: bool, needs_refresh_resize: bool, - settings_changed: bool, key_map: HashMap, + supplement_events: Vec, } impl Window { @@ -60,8 +60,8 @@ impl Window { window, cursor_grabbed: false, needs_refresh_resize: false, - settings_changed: true, key_map, + supplement_events: vec![], }); tmp } @@ -75,17 +75,13 @@ impl Window { pub fn fetch_events(&mut self) -> Vec { let mut events = vec![]; + events.append(&mut self.supplement_events); // Refresh ui size (used when changing playstates) if self.needs_refresh_resize { events.push(Event::Ui(ui::Event::new_resize(self.logical_size()))); self.needs_refresh_resize = false; } - if self.settings_changed { - events.push(Event::SettingsChanged); - self.settings_changed = false; - } - // Copy data that is needed by the events closure to avoid lifetime errors // TODO: Remove this if/when the compiler permits it let cursor_grabbed = self.cursor_grabbed; @@ -169,8 +165,8 @@ impl Window { Vec2::new(w, h) } - pub fn settings_changed(&mut self) { - self.settings_changed = true; + pub fn send_supplement_event(&mut self, event: Event) { + self.supplement_events.push(event) } } @@ -216,4 +212,4 @@ pub enum Event { Ui(ui::Event), /// Game settings have changed SettingsChanged, -} +} \ No newline at end of file From 488132f63b9ffa21432a6c624069387dcade1286 Mon Sep 17 00:00:00 2001 From: Yeedo Date: Thu, 25 Apr 2019 14:10:01 +0100 Subject: [PATCH 04/14] Update help window to use player's keybindings (fix #42) Former-commit-id: b1d374e83ab134a094b664ada8f35916e4734602 --- voxygen/src/hud/mod.rs | 12 ++++++++++++ voxygen/src/window.rs | 12 +++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 8af320fcea..6779f9a099 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -480,7 +480,11 @@ pub struct Hud { mana_percentage: f64, inventorytest_button: bool, settings_tab: SettingsTab, +<<<<<<< HEAD settings: Settings, +======= + help_text: String, +>>>>>>> Update help window to use player's keybindings (fix #42) } //#[inline] @@ -532,7 +536,11 @@ impl Hud { xp_percentage: 0.4, hp_percentage: 1.0, mana_percentage: 1.0, +<<<<<<< HEAD settings: settings, +======= + help_text: get_help_text(&Settings::default().controls), +>>>>>>> Update help window to use player's keybindings (fix #42) } } @@ -1764,7 +1772,11 @@ impl Hud { }, WinEvent::Char(_) => self.typing(), WinEvent::SettingsChanged => { +<<<<<<< HEAD self.settings = global_state.settings.clone(); +======= + self.help_text = get_help_text(&global_state.settings.controls); +>>>>>>> Update help window to use player's keybindings (fix #42) true }, _ => false, diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index e3d88998c9..89eb7268bc 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -11,6 +11,7 @@ pub struct Window { window: glutin::GlWindow, cursor_grabbed: bool, needs_refresh_resize: bool, + settings_changed: bool, key_map: HashMap, supplement_events: Vec, } @@ -60,6 +61,7 @@ impl Window { window, cursor_grabbed: false, needs_refresh_resize: false, + settings_changed: true, key_map, supplement_events: vec![], }); @@ -82,6 +84,10 @@ impl Window { self.needs_refresh_resize = false; } + if self.settings_changed { + events.push(Event::SettingsChanged); + } + // Copy data that is needed by the events closure to avoid lifetime errors // TODO: Remove this if/when the compiler permits it let cursor_grabbed = self.cursor_grabbed; @@ -212,4 +218,8 @@ pub enum Event { Ui(ui::Event), /// Game settings have changed SettingsChanged, -} \ No newline at end of file +<<<<<<< HEAD +} +======= +} +>>>>>>> Update help window to use player's keybindings (fix #42) From 48747dd9a91e8c0eced87e58719d1155fa0cfe62 Mon Sep 17 00:00:00 2001 From: Yeedo Date: Thu, 25 Apr 2019 14:23:40 +0100 Subject: [PATCH 05/14] Tiny fix to prevent settings from permanently being marked as changed Former-commit-id: ce120495a91ce0306bcb010923cd340fc70b87db --- voxygen/src/window.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index 89eb7268bc..8fa8c93d01 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -86,6 +86,7 @@ impl Window { if self.settings_changed { events.push(Event::SettingsChanged); + self.settings_changed = false; } // Copy data that is needed by the events closure to avoid lifetime errors From 44f8e834fc56bd8316e6284c259d066fb216770a Mon Sep 17 00:00:00 2001 From: Yeedo Date: Thu, 25 Apr 2019 16:32:59 +0100 Subject: [PATCH 06/14] Redo settings -> help text, add `supplement_events` to `Window`. Former-commit-id: a0e023c1cce1677cd1178490df9c569b774db6b6 --- voxygen/src/hud/mod.rs | 12 ------------ voxygen/src/window.rs | 13 +------------ 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 6779f9a099..8af320fcea 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -480,11 +480,7 @@ pub struct Hud { mana_percentage: f64, inventorytest_button: bool, settings_tab: SettingsTab, -<<<<<<< HEAD settings: Settings, -======= - help_text: String, ->>>>>>> Update help window to use player's keybindings (fix #42) } //#[inline] @@ -536,11 +532,7 @@ impl Hud { xp_percentage: 0.4, hp_percentage: 1.0, mana_percentage: 1.0, -<<<<<<< HEAD settings: settings, -======= - help_text: get_help_text(&Settings::default().controls), ->>>>>>> Update help window to use player's keybindings (fix #42) } } @@ -1772,11 +1764,7 @@ impl Hud { }, WinEvent::Char(_) => self.typing(), WinEvent::SettingsChanged => { -<<<<<<< HEAD self.settings = global_state.settings.clone(); -======= - self.help_text = get_help_text(&global_state.settings.controls); ->>>>>>> Update help window to use player's keybindings (fix #42) true }, _ => false, diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index 8fa8c93d01..e3d88998c9 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -11,7 +11,6 @@ pub struct Window { window: glutin::GlWindow, cursor_grabbed: bool, needs_refresh_resize: bool, - settings_changed: bool, key_map: HashMap, supplement_events: Vec, } @@ -61,7 +60,6 @@ impl Window { window, cursor_grabbed: false, needs_refresh_resize: false, - settings_changed: true, key_map, supplement_events: vec![], }); @@ -84,11 +82,6 @@ impl Window { self.needs_refresh_resize = false; } - if self.settings_changed { - events.push(Event::SettingsChanged); - self.settings_changed = false; - } - // Copy data that is needed by the events closure to avoid lifetime errors // TODO: Remove this if/when the compiler permits it let cursor_grabbed = self.cursor_grabbed; @@ -219,8 +212,4 @@ pub enum Event { Ui(ui::Event), /// Game settings have changed SettingsChanged, -<<<<<<< HEAD -} -======= -} ->>>>>>> Update help window to use player's keybindings (fix #42) +} \ No newline at end of file From e1fc901b5f5f23eb0e402bd87032001c5084a038 Mon Sep 17 00:00:00 2001 From: Yeedo Date: Thu, 25 Apr 2019 14:10:01 +0100 Subject: [PATCH 07/14] Update help window to use player's keybindings (fix #42) Former-commit-id: c79b4184b279b2e6fbaac8e0b7c641741d8eb51e --- voxygen/src/window.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index e3d88998c9..979e48bbdb 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -11,6 +11,7 @@ pub struct Window { window: glutin::GlWindow, cursor_grabbed: bool, needs_refresh_resize: bool, + settings_changed: bool, key_map: HashMap, supplement_events: Vec, } @@ -60,6 +61,7 @@ impl Window { window, cursor_grabbed: false, needs_refresh_resize: false, + settings_changed: true, key_map, supplement_events: vec![], }); @@ -82,6 +84,10 @@ impl Window { self.needs_refresh_resize = false; } + if self.settings_changed { + events.push(Event::SettingsChanged); + } + // Copy data that is needed by the events closure to avoid lifetime errors // TODO: Remove this if/when the compiler permits it let cursor_grabbed = self.cursor_grabbed; From 00e92e5ea2bd234e2f4de98b9ee2c437f0189be5 Mon Sep 17 00:00:00 2001 From: Yeedo Date: Thu, 25 Apr 2019 14:23:40 +0100 Subject: [PATCH 08/14] Tiny fix to prevent settings from permanently being marked as changed Former-commit-id: 99927ee1ca6c1cabb5268353690ec88425b7ae3d --- voxygen/src/window.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index 979e48bbdb..6acaeeb4e7 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -86,6 +86,7 @@ impl Window { if self.settings_changed { events.push(Event::SettingsChanged); + self.settings_changed = false; } // Copy data that is needed by the events closure to avoid lifetime errors From ad1fc20cfec327e7fc0cd310f495cb856074e53d Mon Sep 17 00:00:00 2001 From: Yeedo Date: Thu, 25 Apr 2019 16:32:59 +0100 Subject: [PATCH 09/14] Redo settings -> help text, add `supplement_events` to `Window`. Former-commit-id: 5b29776d3f37fbf87842bc61c8d287fe8e66b691 --- voxygen/src/window.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index 6acaeeb4e7..e3d88998c9 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -11,7 +11,6 @@ pub struct Window { window: glutin::GlWindow, cursor_grabbed: bool, needs_refresh_resize: bool, - settings_changed: bool, key_map: HashMap, supplement_events: Vec, } @@ -61,7 +60,6 @@ impl Window { window, cursor_grabbed: false, needs_refresh_resize: false, - settings_changed: true, key_map, supplement_events: vec![], }); @@ -84,11 +82,6 @@ impl Window { self.needs_refresh_resize = false; } - if self.settings_changed { - events.push(Event::SettingsChanged); - self.settings_changed = false; - } - // Copy data that is needed by the events closure to avoid lifetime errors // TODO: Remove this if/when the compiler permits it let cursor_grabbed = self.cursor_grabbed; From dc5ec137e9a6601d8e416d8bdcec5f61860a1d72 Mon Sep 17 00:00:00 2001 From: Yeedo Date: Thu, 25 Apr 2019 14:10:01 +0100 Subject: [PATCH 10/14] Update help window to use player's keybindings (fix #42) Former-commit-id: b5bc8a8801fd4633ec94ea53a8973bcb891a4fd6 --- voxygen/src/window.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index e3d88998c9..c8d91dc45a 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -11,6 +11,7 @@ pub struct Window { window: glutin::GlWindow, cursor_grabbed: bool, needs_refresh_resize: bool, + settings_changed: bool, key_map: HashMap, supplement_events: Vec, } @@ -60,6 +61,7 @@ impl Window { window, cursor_grabbed: false, needs_refresh_resize: false, + settings_changed: true, key_map, supplement_events: vec![], }); @@ -82,6 +84,10 @@ impl Window { self.needs_refresh_resize = false; } + if self.settings_changed { + events.push(Event::SettingsChanged); + } + // Copy data that is needed by the events closure to avoid lifetime errors // TODO: Remove this if/when the compiler permits it let cursor_grabbed = self.cursor_grabbed; @@ -212,4 +218,4 @@ pub enum Event { Ui(ui::Event), /// Game settings have changed SettingsChanged, -} \ No newline at end of file +} From c032e60d12e4cd378bcde99e5d2c3e7b458ad050 Mon Sep 17 00:00:00 2001 From: Yeedo Date: Thu, 25 Apr 2019 14:23:40 +0100 Subject: [PATCH 11/14] Tiny fix to prevent settings from permanently being marked as changed Former-commit-id: c12d760a22926eebc2661be1db4609546286c89a --- voxygen/src/window.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index c8d91dc45a..e65b61191f 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -86,6 +86,7 @@ impl Window { if self.settings_changed { events.push(Event::SettingsChanged); + self.settings_changed = false; } // Copy data that is needed by the events closure to avoid lifetime errors From 0dbdb185d4ff6fea6eabd201582016b4ad29d3ff Mon Sep 17 00:00:00 2001 From: Yeedo Date: Thu, 25 Apr 2019 16:32:59 +0100 Subject: [PATCH 12/14] Redo settings -> help text, add `supplement_events` to `Window`. Former-commit-id: 2f341c1de302f5600436a3ded1c69af7c9b2c329 --- voxygen/src/window.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index e65b61191f..e3d88998c9 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -11,7 +11,6 @@ pub struct Window { window: glutin::GlWindow, cursor_grabbed: bool, needs_refresh_resize: bool, - settings_changed: bool, key_map: HashMap, supplement_events: Vec, } @@ -61,7 +60,6 @@ impl Window { window, cursor_grabbed: false, needs_refresh_resize: false, - settings_changed: true, key_map, supplement_events: vec![], }); @@ -84,11 +82,6 @@ impl Window { self.needs_refresh_resize = false; } - if self.settings_changed { - events.push(Event::SettingsChanged); - self.settings_changed = false; - } - // Copy data that is needed by the events closure to avoid lifetime errors // TODO: Remove this if/when the compiler permits it let cursor_grabbed = self.cursor_grabbed; @@ -219,4 +212,4 @@ pub enum Event { Ui(ui::Event), /// Game settings have changed SettingsChanged, -} +} \ No newline at end of file From f1e268986b83c91004fafa19369c4cd64fd6c4e2 Mon Sep 17 00:00:00 2001 From: Yeedo Date: Mon, 29 Apr 2019 22:23:31 +0100 Subject: [PATCH 13/14] cargo fmt, also remove a stray `<<<>>>>>> 4be2d5d8f791addfbeaab680d1699c4684069825 + Text::new(&format!("{:?}", self.settings.controls.bag)) .bottom_right_with_margins_on(self.ids.bag, 0.0, 0.0) .font_size(10) .font_id(self.font_metamorph) @@ -1891,7 +1887,7 @@ impl Hud { WinEvent::SettingsChanged => { self.settings = global_state.settings.clone(); true - }, + } _ => false, } } @@ -1929,6 +1925,7 @@ fn get_help_text(cs: &ControlSettings) -> String { format!("{:?} = Character window\n", cs.character_window), format!("{:?} = Social\n", cs.social), format!("{:?} = Spellbook\n", cs.spellbook), - format!("{:?} = Settings\n", cs.settings) - ].concat() -} \ No newline at end of file + format!("{:?} = Settings\n", cs.settings), + ] + .concat() +} From b7ba7f07953a4c1f0f6566d5ccf89ac18dcfc442 Mon Sep 17 00:00:00 2001 From: Yeedo Date: Wed, 1 May 2019 23:15:43 +0100 Subject: [PATCH 14/14] Use shorter help text format, compact stuff into one `format!()` Former-commit-id: 345bef9a2f0714986e4ba6fb24b0bc150023a12e --- voxygen/src/hud/mod.rs | 57 +++++++++++--------------- voxygen/src/menu/char_selection/mod.rs | 2 +- voxygen/src/window.rs | 4 +- 3 files changed, 28 insertions(+), 35 deletions(-) diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index f59212dd3f..da4f299de4 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -12,7 +12,7 @@ use common::{assets, figure::Segment}; use conrod_core::{ color, image::Id as ImgId, - text::font::Id as FontId, + text::{self, font::Id as FontId}, widget::{Button, Image, Rectangle, Scrollbar, Text}, widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, }; @@ -629,7 +629,7 @@ impl Hud { if self.show_help { Image::new(self.imgs.window_frame_2) .top_left_with_margins_on(ui_widgets.window, 3.0, 3.0) - .w_h(300.0, 450.0) + .w_h(300.0, 190.0) .set(self.ids.help_bg, ui_widgets); Text::new(get_help_text(&self.settings.controls).as_str()) .color(TEXT_COLOR) @@ -707,7 +707,7 @@ impl Hud { .bottom_right_with_margins_on(ui_widgets.window, 5.0, 57.0) .hover_image(self.imgs.settings_hover) .press_image(self.imgs.settings_press) - .label("N") + .label(&format!("{:?}", self.settings.controls.settings)) .label_font_size(10) .label_font_id(self.font_metamorph) .color(TEXT_COLOR) @@ -730,7 +730,7 @@ impl Hud { .left_from(self.ids.social_button, 10.0) .hover_image(self.imgs.map_hover) .press_image(self.imgs.map_press) - .label("M") + .label(&format!("{:?}", self.settings.controls.map)) .label_font_size(10) .label_font_id(self.font_metamorph) .label_color(TEXT_COLOR) @@ -774,7 +774,7 @@ impl Hud { .left_from(self.ids.settings_button, 10.0) .hover_image(self.imgs.social_hover) .press_image(self.imgs.social_press) - .label("O") + .label(&format!("{:?}", self.settings.controls.social)) .label_font_size(10) .label_font_id(self.font_metamorph) .label_color(TEXT_COLOR) @@ -800,7 +800,7 @@ impl Hud { .left_from(self.ids.map_button, 10.0) .hover_image(self.imgs.spellbook_hover) .press_image(self.imgs.spellbook_press) - .label("P") + .label(&format!("{:?}", self.settings.controls.spellbook)) .label_font_size(10) .label_font_id(self.font_metamorph) .label_color(TEXT_COLOR) @@ -826,7 +826,7 @@ impl Hud { .left_from(self.ids.spellbook_button, 10.0) .hover_image(self.imgs.character_hover) .press_image(self.imgs.character_press) - .label("C") + .label(&format!("{:?}", self.settings.controls.character_window)) .label_font_size(10) .label_font_id(self.font_metamorph) .label_color(TEXT_COLOR) @@ -852,7 +852,7 @@ impl Hud { .left_from(self.ids.character_button, 10.0) .hover_image(self.imgs.qlog_hover) .press_image(self.imgs.qlog_press) - .label("L") + .label(&format!("{:?}", self.settings.controls.quest_log)) .label_font_size(10) .label_font_id(self.font_metamorph) .label_color(TEXT_COLOR) @@ -1903,29 +1903,22 @@ impl Hud { } } +//Get the text to show in the help window, along with the +//length of the longest line in order to resize the window fn get_help_text(cs: &ControlSettings) -> String { - [ - format!("{:?} = Free cursor\n", cs.toggle_cursor), - format!("{:?} = Open/close menus\n", cs.escape), - String::from("\n"), - format!("{:?} = Toggle this window\n", cs.help), - format!("{:?} = Toggle interface\n", cs.toggle_interface), - String::from("\n"), - format!("{:?} = Open chat\n", cs.enter), - String::from("Mouse Wheel = Scroll chat\n"), - String::from("\n"), - format!("{:?} = Move forward\n", cs.move_forward), - format!("{:?} = Move left\n", cs.move_left), - format!("{:?} = Move right\n", cs.move_right), - format!("{:?} = Move backwards\n", cs.move_back), - String::from("\n"), - format!("{:?} = Map\n", cs.map), - format!("{:?} = Bag\n", cs.bag), - format!("{:?} = Quest log\n", cs.quest_log), - format!("{:?} = Character window\n", cs.character_window), - format!("{:?} = Social\n", cs.social), - format!("{:?} = Spellbook\n", cs.spellbook), - format!("{:?} = Settings\n", cs.settings), - ] - .concat() + format!( + "{free_cursor:?} = Free cursor\n\ + {escape:?} = Open/close menus\n\ + \n\ + {help:?} = Toggle this window\n\ + {toggle_interface:?} = Toggle interface\n\ + \n\ + {chat:?} = Open chat\n\ + Mouse Wheel = Scroll chat/zoom", + free_cursor = cs.toggle_cursor, + escape = cs.escape, + help = cs.help, + toggle_interface = cs.toggle_interface, + chat = cs.enter + ) } diff --git a/voxygen/src/menu/char_selection/mod.rs b/voxygen/src/menu/char_selection/mod.rs index 99adfbf8d6..565c114527 100644 --- a/voxygen/src/menu/char_selection/mod.rs +++ b/voxygen/src/menu/char_selection/mod.rs @@ -76,7 +76,7 @@ impl PlayState for CharSelectionState { return PlayStateResult::Switch(Box::new(SessionState::new( &mut global_state.window, self.client.clone(), - global_state.settings.clone() + global_state.settings.clone(), ))); } } diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index 2c5008eeec..a1e80b33a6 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -165,7 +165,7 @@ impl Window { .into(); Vec2::new(w, h) } - + pub fn send_supplement_event(&mut self, event: Event) { self.supplement_events.push(event) } @@ -213,4 +213,4 @@ pub enum Event { Ui(ui::Event), /// Game settings have changed SettingsChanged, -} \ No newline at end of file +}