mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
rearrange hud event handling slighlty
Former-commit-id: 8043d6c6197112123c371258407ea886a5ae3595
This commit is contained in:
parent
67584a49ce
commit
d6d4155fc4
@ -4,6 +4,7 @@ use crate::{
|
|||||||
render::Renderer,
|
render::Renderer,
|
||||||
ui::{self, ScaleMode, ToggleButton, Ui},
|
ui::{self, ScaleMode, ToggleButton, Ui},
|
||||||
window::{Event as WinEvent, Key, Window},
|
window::{Event as WinEvent, Key, Window},
|
||||||
|
GlobalState,
|
||||||
};
|
};
|
||||||
use common::assets;
|
use common::assets;
|
||||||
use conrod_core::{
|
use conrod_core::{
|
||||||
@ -406,7 +407,6 @@ pub struct Hud {
|
|||||||
ids: Ids,
|
ids: Ids,
|
||||||
imgs: Imgs,
|
imgs: Imgs,
|
||||||
chat: chat::Chat,
|
chat: chat::Chat,
|
||||||
cursor_grabbed: bool,
|
|
||||||
font_metamorph: FontId,
|
font_metamorph: FontId,
|
||||||
font_opensans: FontId,
|
font_opensans: FontId,
|
||||||
show_help: bool,
|
show_help: bool,
|
||||||
@ -459,7 +459,6 @@ impl Hud {
|
|||||||
imgs,
|
imgs,
|
||||||
ids,
|
ids,
|
||||||
chat,
|
chat,
|
||||||
cursor_grabbed: true,
|
|
||||||
settings_tab: SettingsTab::Interface,
|
settings_tab: SettingsTab::Interface,
|
||||||
show_help: true,
|
show_help: true,
|
||||||
bag_open: false,
|
bag_open: false,
|
||||||
@ -1460,13 +1459,17 @@ impl Hud {
|
|||||||
self.chat.new_message(msg);
|
self.chat.new_message(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn toggle_menu(&mut self) {
|
fn toggle_menu(&mut self) {
|
||||||
self.menu_open = !self.menu_open;
|
self.menu_open = !self.menu_open;
|
||||||
}
|
}
|
||||||
pub fn toggle_bag(&mut self) {
|
fn toggle_bag(&mut self) {
|
||||||
self.bag_open = !self.bag_open
|
self.bag_open = !self.bag_open
|
||||||
}
|
}
|
||||||
pub fn toggle_questlog(&mut self) {
|
fn toggle_map(&mut self) {
|
||||||
|
self.map_open = !self.map_open;
|
||||||
|
self.bag_open = false;
|
||||||
|
}
|
||||||
|
fn toggle_questlog(&mut self) {
|
||||||
self.open_windows = match self.open_windows {
|
self.open_windows = match self.open_windows {
|
||||||
Windows::Small(Small::Questlog) => Windows::None,
|
Windows::Small(Small::Questlog) => Windows::None,
|
||||||
Windows::None | Windows::Small(_) => Windows::Small(Small::Questlog),
|
Windows::None | Windows::Small(_) => Windows::Small(Small::Questlog),
|
||||||
@ -1477,11 +1480,7 @@ impl Hud {
|
|||||||
Windows::Settings => Windows::Settings,
|
Windows::Settings => Windows::Settings,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub fn toggle_map(&mut self) {
|
fn toggle_charwindow(&mut self) {
|
||||||
self.map_open = !self.map_open;
|
|
||||||
self.bag_open = false;
|
|
||||||
}
|
|
||||||
pub fn toggle_charwindow(&mut self) {
|
|
||||||
self.open_windows = match self.open_windows {
|
self.open_windows = match self.open_windows {
|
||||||
Windows::CharacterAnd(small) => match small {
|
Windows::CharacterAnd(small) => match small {
|
||||||
Some(small) => Windows::Small(small),
|
Some(small) => Windows::Small(small),
|
||||||
@ -1492,7 +1491,7 @@ impl Hud {
|
|||||||
Windows::Settings => Windows::Settings,
|
Windows::Settings => Windows::Settings,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn toggle_social(&mut self) {
|
fn toggle_social(&mut self) {
|
||||||
self.open_windows = match self.open_windows {
|
self.open_windows = match self.open_windows {
|
||||||
Windows::Small(Small::Social) => Windows::None,
|
Windows::Small(Small::Social) => Windows::None,
|
||||||
Windows::None | Windows::Small(_) => Windows::Small(Small::Social),
|
Windows::None | Windows::Small(_) => Windows::Small(Small::Social),
|
||||||
@ -1503,7 +1502,7 @@ impl Hud {
|
|||||||
Windows::Settings => Windows::Settings,
|
Windows::Settings => Windows::Settings,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub fn toggle_spellbook(&mut self) {
|
fn toggle_spellbook(&mut self) {
|
||||||
self.open_windows = match self.open_windows {
|
self.open_windows = match self.open_windows {
|
||||||
Windows::Small(Small::Spellbook) => Windows::None,
|
Windows::Small(Small::Spellbook) => Windows::None,
|
||||||
Windows::None | Windows::Small(_) => Windows::Small(Small::Spellbook),
|
Windows::None | Windows::Small(_) => Windows::Small(Small::Spellbook),
|
||||||
@ -1514,22 +1513,36 @@ impl Hud {
|
|||||||
Windows::Settings => Windows::Settings,
|
Windows::Settings => Windows::Settings,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
pub fn toggle_settings(&mut self) {
|
fn toggle_settings(&mut self) {
|
||||||
self.open_windows = match self.open_windows {
|
self.open_windows = match self.open_windows {
|
||||||
Windows::Settings => Windows::None,
|
Windows::Settings => Windows::None,
|
||||||
_ => Windows::Settings,
|
_ => Windows::Settings,
|
||||||
};
|
};
|
||||||
self.bag_open = false;
|
self.bag_open = false;
|
||||||
}
|
}
|
||||||
pub fn toggle_help(&mut self) {
|
fn toggle_help(&mut self) {
|
||||||
self.show_help = !self.show_help
|
self.show_help = !self.show_help
|
||||||
}
|
}
|
||||||
pub fn toggle_ui(&mut self) {
|
fn toggle_ui(&mut self) {
|
||||||
self.show_ui = !self.show_ui;
|
self.show_ui = !self.show_ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_grab(&mut self, cursor_grabbed: bool) {
|
fn toggle_windows(&mut self) {
|
||||||
self.cursor_grabbed = cursor_grabbed;
|
if self.bag_open
|
||||||
|
|| self.menu_open
|
||||||
|
|| self.map_open
|
||||||
|
|| match self.open_windows {
|
||||||
|
Windows::None => false,
|
||||||
|
_ => true,
|
||||||
|
}
|
||||||
|
{
|
||||||
|
self.bag_open = false;
|
||||||
|
self.menu_open = false;
|
||||||
|
self.map_open = false;
|
||||||
|
self.open_windows = Windows::None;
|
||||||
|
} else {
|
||||||
|
self.menu_open = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn typing(&self) -> bool {
|
fn typing(&self) -> bool {
|
||||||
@ -1539,11 +1552,12 @@ impl Hud {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_event(&mut self, event: WinEvent) -> bool {
|
pub fn handle_event(&mut self, event: WinEvent, global_state: &mut GlobalState) -> bool {
|
||||||
|
let cursor_grabbed = global_state.window.is_cursor_grabbed();
|
||||||
match event {
|
match event {
|
||||||
WinEvent::Ui(event) => {
|
WinEvent::Ui(event) => {
|
||||||
if (self.typing() && event.is_keyboard() && self.show_ui)
|
if (self.typing() && event.is_keyboard() && self.show_ui)
|
||||||
|| !(self.cursor_grabbed && event.is_keyboard_or_mouse())
|
|| !(cursor_grabbed && event.is_keyboard_or_mouse())
|
||||||
{
|
{
|
||||||
self.ui.handle_event(event);
|
self.ui.handle_event(event);
|
||||||
}
|
}
|
||||||
@ -1554,7 +1568,7 @@ impl Hud {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
_ if !self.show_ui => false,
|
_ if !self.show_ui => false,
|
||||||
WinEvent::Zoom(_) => !self.cursor_grabbed && !self.ui.no_widget_capturing_mouse(),
|
WinEvent::Zoom(_) => !cursor_grabbed && !self.ui.no_widget_capturing_mouse(),
|
||||||
WinEvent::KeyDown(Key::Enter) => {
|
WinEvent::KeyDown(Key::Enter) => {
|
||||||
self.ui.focus_widget(if self.typing() {
|
self.ui.focus_widget(if self.typing() {
|
||||||
None
|
None
|
||||||
@ -1625,21 +1639,4 @@ impl Hud {
|
|||||||
pub fn render(&self, renderer: &mut Renderer) {
|
pub fn render(&self, renderer: &mut Renderer) {
|
||||||
self.ui.render(renderer);
|
self.ui.render(renderer);
|
||||||
}
|
}
|
||||||
pub fn toggle_windows(&mut self) {
|
|
||||||
if self.bag_open
|
|
||||||
|| self.menu_open
|
|
||||||
|| self.map_open
|
|
||||||
|| match self.open_windows {
|
|
||||||
Windows::None => false,
|
|
||||||
_ => true,
|
|
||||||
}
|
|
||||||
{
|
|
||||||
self.bag_open = false;
|
|
||||||
self.menu_open = false;
|
|
||||||
self.map_open = false;
|
|
||||||
self.open_windows = Windows::None;
|
|
||||||
} else {
|
|
||||||
self.menu_open = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -120,8 +120,8 @@ impl PlayState for SessionState {
|
|||||||
// Handle window events
|
// Handle window events
|
||||||
for event in global_state.window.fetch_events() {
|
for event in global_state.window.fetch_events() {
|
||||||
|
|
||||||
// Pass all events to the ui first
|
// Pass all events to the ui first
|
||||||
if self.hud.handle_event(event.clone()) {
|
if self.hud.handle_event(event.clone(), global_state) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let _handled = match event {
|
let _handled = match event {
|
||||||
@ -134,8 +134,6 @@ impl PlayState for SessionState {
|
|||||||
global_state
|
global_state
|
||||||
.window
|
.window
|
||||||
.grab_cursor(!global_state.window.is_cursor_grabbed());
|
.grab_cursor(!global_state.window.is_cursor_grabbed());
|
||||||
self.hud
|
|
||||||
.update_grab(global_state.window.is_cursor_grabbed());
|
|
||||||
}
|
}
|
||||||
// Movement Key Pressed
|
// Movement Key Pressed
|
||||||
Event::KeyDown(Key::MoveForward) => self.key_state.up = true,
|
Event::KeyDown(Key::MoveForward) => self.key_state.up = true,
|
||||||
|
Loading…
Reference in New Issue
Block a user