mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Update help window to use player's keybindings (fix #42)
Former-commit-id: 5f35a153f05b48ae8c21ae9735080c5c7392e2dc
This commit is contained in:
parent
60017a4f99
commit
50c6518d89
@ -2,6 +2,7 @@ mod chat;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
render::Renderer,
|
render::Renderer,
|
||||||
|
settings::{Settings, ControlSettings},
|
||||||
ui::{self, ScaleMode, ToggleButton, Ui},
|
ui::{self, ScaleMode, ToggleButton, Ui},
|
||||||
window::{Event as WinEvent, Key, Window},
|
window::{Event as WinEvent, Key, Window},
|
||||||
GlobalState,
|
GlobalState,
|
||||||
@ -479,6 +480,7 @@ pub struct Hud {
|
|||||||
mana_percentage: f64,
|
mana_percentage: f64,
|
||||||
inventorytest_button: bool,
|
inventorytest_button: bool,
|
||||||
settings_tab: SettingsTab,
|
settings_tab: SettingsTab,
|
||||||
|
help_text: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
//#[inline]
|
//#[inline]
|
||||||
@ -530,6 +532,7 @@ impl Hud {
|
|||||||
xp_percentage: 0.4,
|
xp_percentage: 0.4,
|
||||||
hp_percentage: 1.0,
|
hp_percentage: 1.0,
|
||||||
mana_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 {
|
if self.show_help {
|
||||||
Image::new(self.imgs.window_frame_2)
|
Image::new(self.imgs.window_frame_2)
|
||||||
.top_left_with_margins_on(ui_widgets.window, 3.0, 3.0)
|
.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);
|
.set(self.ids.help_bg, ui_widgets);
|
||||||
|
Text::new(self.help_text.as_str())
|
||||||
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"
|
|
||||||
)
|
|
||||||
.color(TEXT_COLOR)
|
.color(TEXT_COLOR)
|
||||||
.top_left_with_margins_on(self.ids.help_bg, 20.0, 20.0)
|
.top_left_with_margins_on(self.ids.help_bg, 20.0, 20.0)
|
||||||
.font_id(self.font_opensans)
|
.font_id(self.font_opensans)
|
||||||
.font_size(18)
|
.font_size(18)
|
||||||
.set(self.ids.help, ui_widgets);
|
.set(self.ids.help, ui_widgets);
|
||||||
|
|
||||||
// X-button
|
// X-button
|
||||||
if Button::image(self.imgs.close_button)
|
if Button::image(self.imgs.close_button)
|
||||||
.w_h(100.0 * 0.2, 100.0 * 0.2)
|
.w_h(100.0 * 0.2, 100.0 * 0.2)
|
||||||
@ -1771,6 +1763,10 @@ impl Hud {
|
|||||||
_ => self.typing(),
|
_ => self.typing(),
|
||||||
},
|
},
|
||||||
WinEvent::Char(_) => self.typing(),
|
WinEvent::Char(_) => self.typing(),
|
||||||
|
WinEvent::SettingsChanged => {
|
||||||
|
self.help_text = get_help_text(&global_state.settings.controls);
|
||||||
|
true
|
||||||
|
},
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1785,3 +1781,29 @@ impl Hud {
|
|||||||
self.ui.render(renderer);
|
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()
|
||||||
|
}
|
@ -11,6 +11,7 @@ pub struct Window {
|
|||||||
window: glutin::GlWindow,
|
window: glutin::GlWindow,
|
||||||
cursor_grabbed: bool,
|
cursor_grabbed: bool,
|
||||||
needs_refresh_resize: bool,
|
needs_refresh_resize: bool,
|
||||||
|
settings_changed: bool,
|
||||||
key_map: HashMap<glutin::VirtualKeyCode, Key>,
|
key_map: HashMap<glutin::VirtualKeyCode, Key>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +60,7 @@ impl Window {
|
|||||||
window,
|
window,
|
||||||
cursor_grabbed: false,
|
cursor_grabbed: false,
|
||||||
needs_refresh_resize: false,
|
needs_refresh_resize: false,
|
||||||
|
settings_changed: true,
|
||||||
key_map,
|
key_map,
|
||||||
});
|
});
|
||||||
tmp
|
tmp
|
||||||
@ -79,6 +81,10 @@ impl Window {
|
|||||||
self.needs_refresh_resize = false;
|
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
|
// Copy data that is needed by the events closure to avoid lifetime errors
|
||||||
// TODO: Remove this if/when the compiler permits it
|
// TODO: Remove this if/when the compiler permits it
|
||||||
let cursor_grabbed = self.cursor_grabbed;
|
let cursor_grabbed = self.cursor_grabbed;
|
||||||
@ -161,6 +167,10 @@ impl Window {
|
|||||||
.into();
|
.into();
|
||||||
Vec2::new(w, h)
|
Vec2::new(w, h)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn settings_changed(&mut self) {
|
||||||
|
self.settings_changed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a key that the game recognises after keyboard mapping
|
/// Represents a key that the game recognises after keyboard mapping
|
||||||
@ -203,4 +213,6 @@ pub enum Event {
|
|||||||
KeyUp(Key),
|
KeyUp(Key),
|
||||||
/// Event that the ui uses
|
/// Event that the ui uses
|
||||||
Ui(ui::Event),
|
Ui(ui::Event),
|
||||||
|
/// Game settings have changed
|
||||||
|
SettingsChanged,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user