mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'master' into 'master'
Disable zooming when mouse is over UI elements See merge request veloren/veloren!28 Former-commit-id: cd6f02ac06777c0ed065024f31d3960a2af4898a
This commit is contained in:
commit
f32852054d
@ -402,7 +402,6 @@ pub struct Hud {
|
||||
ids: Ids,
|
||||
imgs: Imgs,
|
||||
chat: chat::Chat,
|
||||
typing: bool,
|
||||
cursor_grabbed: bool,
|
||||
font_metamorph: FontId,
|
||||
font_opensans: FontId,
|
||||
@ -456,7 +455,6 @@ impl Hud {
|
||||
imgs,
|
||||
ids,
|
||||
chat,
|
||||
typing: false,
|
||||
cursor_grabbed: true,
|
||||
settings_tab: SettingsTab::Interface,
|
||||
show_help: true,
|
||||
@ -1443,14 +1441,6 @@ impl Hud {
|
||||
};
|
||||
}
|
||||
|
||||
// update whether keyboard is captured
|
||||
self.typing =
|
||||
if let Some(widget_id) = ui_widgets.global_input().current.widget_capturing_keyboard {
|
||||
widget_id == self.chat.input_box_id()
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
events
|
||||
}
|
||||
|
||||
@ -1530,29 +1520,34 @@ impl Hud {
|
||||
self.cursor_grabbed = cursor_grabbed;
|
||||
}
|
||||
|
||||
fn typing(&self) -> bool {
|
||||
match self.ui.widget_capturing_keyboard() {
|
||||
Some(id) if id == self.chat.input_box_id() => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_event(&mut self, event: WinEvent) -> bool {
|
||||
match event {
|
||||
WinEvent::Ui(event) => {
|
||||
if (self.typing && event.is_keyboard())
|
||||
if (self.typing() && event.is_keyboard())
|
||||
|| !(self.cursor_grabbed && event.is_keyboard_or_mouse())
|
||||
{
|
||||
self.ui.handle_event(event);
|
||||
}
|
||||
true
|
||||
}
|
||||
WinEvent::Zoom(_) => !self.cursor_grabbed && !self.ui.no_widget_capturing_mouse(),
|
||||
WinEvent::KeyDown(Key::Enter) => {
|
||||
if self.typing {
|
||||
self.ui.focus_widget(None);
|
||||
self.typing = false;
|
||||
self.ui.focus_widget(if self.typing() {
|
||||
None
|
||||
} else {
|
||||
self.ui.focus_widget(Some(self.chat.input_box_id()));
|
||||
self.typing = true;
|
||||
};
|
||||
Some(self.chat.input_box_id())
|
||||
});
|
||||
true
|
||||
}
|
||||
WinEvent::KeyDown(Key::Escape) => {
|
||||
if self.typing {
|
||||
self.typing = false;
|
||||
if self.typing() {
|
||||
self.ui.focus_widget(None);
|
||||
} else {
|
||||
// Close windows on esc
|
||||
@ -1560,7 +1555,7 @@ impl Hud {
|
||||
}
|
||||
true
|
||||
}
|
||||
WinEvent::KeyDown(key) if !self.typing => match key {
|
||||
WinEvent::KeyDown(key) if !self.typing() => match key {
|
||||
Key::Map => {
|
||||
self.toggle_map();
|
||||
true
|
||||
@ -1601,9 +1596,9 @@ impl Hud {
|
||||
},
|
||||
WinEvent::KeyDown(key) | WinEvent::KeyUp(key) => match key {
|
||||
Key::ToggleCursor => false,
|
||||
_ => self.typing,
|
||||
_ => self.typing(),
|
||||
},
|
||||
WinEvent::Char(_) => self.typing,
|
||||
WinEvent::Char(_) => self.typing(),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ impl ClientInit {
|
||||
for socket_addr in first_addrs.into_iter().chain(second_addrs) {
|
||||
match Client::new(socket_addr, player.clone(), character, view_distance) {
|
||||
Ok(client) => {
|
||||
tx.send(Ok(client));
|
||||
let _ = tx.send(Ok(client));
|
||||
return;
|
||||
}
|
||||
Err(err) => {
|
||||
@ -65,11 +65,11 @@ impl ClientInit {
|
||||
}
|
||||
}
|
||||
// Parsing/host name resolution successful but no connection succeeded
|
||||
tx.send(Err(last_err.unwrap_or(Error::NoAddress)));
|
||||
let _ = tx.send(Err(last_err.unwrap_or(Error::NoAddress)));
|
||||
}
|
||||
Err(err) => {
|
||||
// Error parsing input string or error resolving host name
|
||||
tx.send(Err(Error::BadAddress(err)));
|
||||
let _ = tx.send(Err(Error::BadAddress(err)));
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
@ -246,32 +246,23 @@ impl Ui {
|
||||
self.ui.set_widgets()
|
||||
}
|
||||
|
||||
// Workaround because conrod currently gives us no way to programmatically set which widget is capturing key input
|
||||
// Note the widget must be visible and not covered by other widgets at its center for this to work
|
||||
// Accepts option so widget can be "unfocused"
|
||||
// Accepts option so widget can be unfocused
|
||||
pub fn focus_widget(&mut self, id: Option<WidgId>) {
|
||||
let (x, y) = match id {
|
||||
// get position of widget
|
||||
Some(id) => if let Some([x, y]) = self.ui.xy_of(id) {
|
||||
(x, y)
|
||||
} else {
|
||||
return;
|
||||
},
|
||||
// outside window (origin is center)
|
||||
None => (self.ui.win_h, self.ui.win_w)
|
||||
};
|
||||
// things to consider: does cursor need to be moved back?, should we check if the mouse if already pressed and then trigger a release?
|
||||
self.ui.handle_event(
|
||||
Input::Motion(Motion::MouseCursor { x, y })
|
||||
);
|
||||
self.ui.handle_event(
|
||||
Input::Press(Button::Mouse(MouseButton::Left))
|
||||
);
|
||||
self.ui.handle_event(
|
||||
Input::Release(Button::Mouse(MouseButton::Left))
|
||||
);
|
||||
self.ui.keyboard_capture(match id {
|
||||
Some(id) => id,
|
||||
None => self.ui.window,
|
||||
});
|
||||
}
|
||||
|
||||
// Get id of current widget capturing keyboard
|
||||
pub fn widget_capturing_keyboard(&self) -> Option<WidgId> {
|
||||
self.ui.global_input().current.widget_capturing_keyboard
|
||||
}
|
||||
|
||||
// Get whether the a widget besides the window is capturing the mouse
|
||||
pub fn no_widget_capturing_mouse(&self) -> bool {
|
||||
self.ui.global_input().current.widget_capturing_mouse.filter(|id| id != &self.ui.window ).is_none()
|
||||
}
|
||||
|
||||
pub fn handle_event(&mut self, event: Event) {
|
||||
match event.0 {
|
||||
|
Loading…
Reference in New Issue
Block a user