mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Redo settings -> help text, add supplement_events
to Window
.
Former-commit-id: 1e679a6fc3300b6269672650564405c031b151ae
This commit is contained in:
parent
7593d4e821
commit
be9a399269
@ -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,
|
||||
|
@ -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())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<RefCell<Client>>) -> Self {
|
||||
pub fn new(window: &mut Window, client: Rc<RefCell<Client>>, 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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ pub struct Window {
|
||||
window: glutin::GlWindow,
|
||||
cursor_grabbed: bool,
|
||||
needs_refresh_resize: bool,
|
||||
settings_changed: bool,
|
||||
key_map: HashMap<glutin::VirtualKeyCode, Key>,
|
||||
supplement_events: Vec<Event>,
|
||||
}
|
||||
|
||||
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<Event> {
|
||||
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,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user