fix(bug-563): Better cursor toggling, no regrab when clicking window

This commit is contained in:
Adam Whitehurst 2021-05-24 16:14:34 -07:00
parent 0c3c5728d1
commit 81397349da

View File

@ -63,8 +63,8 @@ use crate::{
}, },
settings::chat::ChatFilter, settings::chat::ChatFilter,
ui::{ ui::{
self, fonts::Fonts, img_ids::Rotations, slot, slot::SlotKey, Graphic, Ingameable, self, fonts::Fonts, img_ids::Rotations, slot, slot::SlotKey, Event as UiEvent, Graphic,
ScaleMode, Ui, Ingameable, ScaleMode, Ui,
}, },
window::{Event as WinEvent, GameInput}, window::{Event as WinEvent, GameInput},
GlobalState, GlobalState,
@ -93,6 +93,8 @@ use common_net::{
sync::WorldSyncExt, sync::WorldSyncExt,
}; };
use conrod_core::{ use conrod_core::{
event::Input as ConrodInput,
input::{Button as ConrodInputButton, MouseButton as ConrodInputMouseButton},
text::cursor::Index, text::cursor::Index,
widget::{self, Button, Image, Text}, widget::{self, Button, Image, Text},
widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget, widget_ids, Color, Colorable, Labelable, Positionable, Sizeable, Widget,
@ -3355,6 +3357,11 @@ impl Hud {
let cursor_grabbed = global_state.window.is_cursor_grabbed(); let cursor_grabbed = global_state.window.is_cursor_grabbed();
let handled = match event { let handled = match event {
// Do not unfocus widgets that the user is typing into when Left-Clicking the window
WinEvent::Ui(UiEvent(ConrodInput::Press(ConrodInputButton::Mouse(
ConrodInputMouseButton::Left,
)))) if self.typing() => true,
WinEvent::Ui(event) => { WinEvent::Ui(event) => {
if (self.typing() && event.is_keyboard() && self.show.ui) if (self.typing() && event.is_keyboard() && self.show.ui)
|| !(cursor_grabbed && event.is_keyboard_or_mouse()) || !(cursor_grabbed && event.is_keyboard_or_mouse())
@ -3412,21 +3419,30 @@ impl Hud {
WinEvent::Zoom(_) => !cursor_grabbed && !self.ui.no_widget_capturing_mouse(), WinEvent::Zoom(_) => !cursor_grabbed && !self.ui.no_widget_capturing_mouse(),
WinEvent::InputUpdate(GameInput::Chat, true) => { WinEvent::InputUpdate(GameInput::Chat, true) => {
self.ui.focus_widget(if self.typing() { if self.typing() {
// regrab cursor when done typing if !self.show.bag
self.force_ungrab = false; && !self.show.trade
None && !self.show.esc_menu
&& !self.show.map
&& !self.show.social
&& !self.show.crafting
&& !self.show.diary
&& !self.show.help
&& !self.show.intro
{
self.show.want_grab = true;
}
self.ui.focus_widget(None);
} else { } else {
// ungrab cursor when activating typing self.show.want_grab = false;
self.force_ungrab = true; self.ui.focus_widget(Some(self.ids.chat));
Some(self.ids.chat) }
});
true true
}, },
WinEvent::InputUpdate(GameInput::Escape, true) => { WinEvent::InputUpdate(GameInput::Escape, true) => {
if self.typing() { if self.typing() {
// If we were typing, the cursor was ungrabbed, so regrab it. self.show.want_grab = true;
self.force_ungrab = false;
self.ui.focus_widget(None); self.ui.focus_widget(None);
} else if self.show.trade { } else if self.show.trade {
self.events.push(Event::TradeAction(TradeAction::Decline)); self.events.push(Event::TradeAction(TradeAction::Decline));