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,
|
ids: Ids,
|
||||||
imgs: Imgs,
|
imgs: Imgs,
|
||||||
chat: chat::Chat,
|
chat: chat::Chat,
|
||||||
typing: bool,
|
|
||||||
cursor_grabbed: bool,
|
cursor_grabbed: bool,
|
||||||
font_metamorph: FontId,
|
font_metamorph: FontId,
|
||||||
font_opensans: FontId,
|
font_opensans: FontId,
|
||||||
@ -456,7 +455,6 @@ impl Hud {
|
|||||||
imgs,
|
imgs,
|
||||||
ids,
|
ids,
|
||||||
chat,
|
chat,
|
||||||
typing: false,
|
|
||||||
cursor_grabbed: true,
|
cursor_grabbed: true,
|
||||||
settings_tab: SettingsTab::Interface,
|
settings_tab: SettingsTab::Interface,
|
||||||
show_help: true,
|
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
|
events
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1530,29 +1520,34 @@ impl Hud {
|
|||||||
self.cursor_grabbed = cursor_grabbed;
|
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 {
|
pub fn handle_event(&mut self, event: WinEvent) -> bool {
|
||||||
match event {
|
match event {
|
||||||
WinEvent::Ui(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.cursor_grabbed && event.is_keyboard_or_mouse())
|
||||||
{
|
{
|
||||||
self.ui.handle_event(event);
|
self.ui.handle_event(event);
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
WinEvent::Zoom(_) => !self.cursor_grabbed && !self.ui.no_widget_capturing_mouse(),
|
||||||
WinEvent::KeyDown(Key::Enter) => {
|
WinEvent::KeyDown(Key::Enter) => {
|
||||||
if self.typing {
|
self.ui.focus_widget(if self.typing() {
|
||||||
self.ui.focus_widget(None);
|
None
|
||||||
self.typing = false;
|
|
||||||
} else {
|
} else {
|
||||||
self.ui.focus_widget(Some(self.chat.input_box_id()));
|
Some(self.chat.input_box_id())
|
||||||
self.typing = true;
|
});
|
||||||
};
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
WinEvent::KeyDown(Key::Escape) => {
|
WinEvent::KeyDown(Key::Escape) => {
|
||||||
if self.typing {
|
if self.typing() {
|
||||||
self.typing = false;
|
|
||||||
self.ui.focus_widget(None);
|
self.ui.focus_widget(None);
|
||||||
} else {
|
} else {
|
||||||
// Close windows on esc
|
// Close windows on esc
|
||||||
@ -1560,7 +1555,7 @@ impl Hud {
|
|||||||
}
|
}
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
WinEvent::KeyDown(key) if !self.typing => match key {
|
WinEvent::KeyDown(key) if !self.typing() => match key {
|
||||||
Key::Map => {
|
Key::Map => {
|
||||||
self.toggle_map();
|
self.toggle_map();
|
||||||
true
|
true
|
||||||
@ -1601,9 +1596,9 @@ impl Hud {
|
|||||||
},
|
},
|
||||||
WinEvent::KeyDown(key) | WinEvent::KeyUp(key) => match key {
|
WinEvent::KeyDown(key) | WinEvent::KeyUp(key) => match key {
|
||||||
Key::ToggleCursor => false,
|
Key::ToggleCursor => false,
|
||||||
_ => self.typing,
|
_ => self.typing(),
|
||||||
},
|
},
|
||||||
WinEvent::Char(_) => self.typing,
|
WinEvent::Char(_) => self.typing(),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ impl ClientInit {
|
|||||||
for socket_addr in first_addrs.into_iter().chain(second_addrs) {
|
for socket_addr in first_addrs.into_iter().chain(second_addrs) {
|
||||||
match Client::new(socket_addr, player.clone(), character, view_distance) {
|
match Client::new(socket_addr, player.clone(), character, view_distance) {
|
||||||
Ok(client) => {
|
Ok(client) => {
|
||||||
tx.send(Ok(client));
|
let _ = tx.send(Ok(client));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -65,11 +65,11 @@ impl ClientInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Parsing/host name resolution successful but no connection succeeded
|
// 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) => {
|
Err(err) => {
|
||||||
// Error parsing input string or error resolving host name
|
// 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()
|
self.ui.set_widgets()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Workaround because conrod currently gives us no way to programmatically set which widget is capturing key input
|
// Accepts option so widget can be unfocused
|
||||||
// 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"
|
|
||||||
pub fn focus_widget(&mut self, id: Option<WidgId>) {
|
pub fn focus_widget(&mut self, id: Option<WidgId>) {
|
||||||
let (x, y) = match id {
|
self.ui.keyboard_capture(match id {
|
||||||
// get position of widget
|
Some(id) => id,
|
||||||
Some(id) => if let Some([x, y]) = self.ui.xy_of(id) {
|
None => self.ui.window,
|
||||||
(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))
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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) {
|
pub fn handle_event(&mut self, event: Event) {
|
||||||
match event.0 {
|
match event.0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user