Skip to content

Commit cc1d11c

Browse files
committed
fix(Mouse): add better support for mouse/touch for buttons and menu cards
1 parent 1bb836e commit cc1d11c

File tree

4 files changed

+41
-29
lines changed

4 files changed

+41
-29
lines changed

core/ui/card_ui/quick_bar/qb_card.gd

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ signal nonchild_focused
2323
else:
2424
toggled_off.emit()
2525
toggled.emit(is_toggled)
26+
if not grower:
27+
return
28+
effect_in_progress = true
29+
if is_toggled:
30+
await grower.effect_finished
31+
else:
32+
await grower.shrink_finished
33+
effect_in_progress = false
2634

2735
@onready var header_container := $%HeaderContainer as VBoxContainer
2836
@onready var label := $%SectionLabel as Label
@@ -32,6 +40,7 @@ signal nonchild_focused
3240
@onready var smooth_scroll := $SmoothScrollEffect as SmoothScrollEffect
3341
@onready var grower := $GrowerEffect as GrowerEffect
3442

43+
var effect_in_progress := false
3544
var focus_group: FocusGroup
3645
var logger := Log.get_logger("QBCard", Log.LEVEL.INFO)
3746

@@ -47,7 +56,6 @@ func _ready() -> void:
4756
var on_focus_exited := func():
4857
self._on_unfocus.call_deferred()
4958
focus_exited.connect(on_focus_exited)
50-
focus_entered.connect(_on_focus)
5159
button_up.connect(_on_button_up)
5260
theme_changed.connect(_on_theme_changed)
5361

@@ -139,14 +147,6 @@ func _find_child_focus_group(nodes: Array[Node]) -> FocusGroup:
139147
return null
140148

141149

142-
func _on_focus() -> void:
143-
# If the card gets focused, and its already expanded, that means we've
144-
# the user has focused outside the card, and we should shrink to hide the
145-
# content
146-
if is_toggled:
147-
_on_button_up()
148-
149-
150150
func _on_unfocus() -> void:
151151
# Get the new focus owner
152152
var focus_owner := get_viewport().gui_get_focus_owner()
@@ -186,39 +186,42 @@ func _on_focus_change(focused: Control) -> void:
186186

187187
func _on_button_up() -> void:
188188
is_toggled = !is_toggled
189-
if is_toggled:
190-
toggled_on.emit()
191-
else:
192-
toggled_off.emit()
193-
194-
toggled.emit(is_toggled)
195189

196190

197191
func _gui_input(event: InputEvent) -> void:
198-
var is_valid := [event is InputEventAction, event is InputEventKey]
192+
var is_valid := [
193+
event is InputEventAction and event.is_action("ui_accept"),
194+
event is InputEventKey and event.is_action("ui_accept"),
195+
event is InputEventMouseButton and (event as InputEventMouseButton).button_index == MOUSE_BUTTON_LEFT,
196+
]
199197
if not true in is_valid:
200198
return
201-
if event.is_action("ui_accept"):
202-
if event.is_pressed():
203-
button_down.emit()
204-
pressed.emit()
205-
else:
206-
button_up.emit()
199+
# Mouse input changes focus on button down, which can cause the
200+
# card to toggle off on focus change before the "button_up" event.
201+
# To get around this, ignore mouse events if the grow/shrink effect
202+
# is in progress.
203+
if event is InputEventMouseButton and effect_in_progress:
204+
return
205+
if event.is_pressed():
206+
button_down.emit()
207+
pressed.emit()
208+
else:
209+
button_up.emit()
207210

208211

209212
func _input(event: InputEvent) -> void:
210213
if not is_toggled:
211214
return
212-
if not event.is_action("ogui_east"):
215+
var is_valid := [
216+
event.is_action("ogui_east"),
217+
event.is_action("ogui_back"),
218+
event.is_action("ui_cancel")
219+
]
220+
if not true in is_valid:
213221
return
214222
if not event.is_released():
215223
return
216224

217-
# Only process input if a child node has focus
218-
#var focus_owner := get_viewport().gui_get_focus_owner()
219-
#if not self.is_ancestor_of(focus_owner):
220-
# return
221-
222225
# Handle back input
223226
is_toggled = false
224227

core/ui/card_ui/quick_bar/qb_card.tscn

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ on_signal = "focus_entered"
3434
fade_out_signal = "nonchild_focused"
3535
on_signal = "focus_entered"
3636

37+
[node name="HoverHighlightFadeEffect" parent="." node_paths=PackedStringArray("target") instance=ExtResource("3_6u4la")]
38+
target = NodePath("../PanelContainer/HighlightTexture")
39+
on_signal = "mouse_entered"
40+
fade_out_signal = "mouse_exited"
41+
on_signal = "mouse_entered"
42+
3743
[node name="GrowerEffect" parent="." node_paths=PackedStringArray("target", "content_container", "inside_panel", "separator") instance=ExtResource("4_1jyfj")]
3844
target = NodePath("..")
3945
content_container = NodePath("../MarginContainer/CardVBoxContainer/ContentContainer")

core/ui/card_ui/settings/general_settings_menu.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func _add_user_themes() -> void:
161161
var button := card_button_scene.instantiate() as CardButton
162162
button.text = theme_name
163163
button.custom_minimum_size.x = 158
164+
button.click_focuses = false
164165

165166
# Add the theme setter behavior
166167
var theme_setter := theme_setter_scene.instantiate() as ThemeSetter

core/ui/components/card_button.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ signal player_button_down(metaname: String, dbus_path: String)
5252
@export_file("*.ogg") var select_audio = "res://assets/audio/interface/96127__bmaczero__contact1.ogg"
5353

5454
@export_category("Mouse")
55-
@export var click_focuses := true
55+
@export var click_focuses := false
5656

5757
var tween: Tween
5858
var focus_audio_stream = load(focus_audio)
@@ -126,6 +126,8 @@ func _gui_input(event: InputEvent) -> void:
126126
return
127127
var dbus_path := event.get_meta("dbus_path", "") as String
128128
if event is InputEventMouseButton and not click_focuses:
129+
if (event as InputEventMouseButton).button_index != MOUSE_BUTTON_LEFT:
130+
return
129131
if event.is_pressed():
130132
button_down.emit()
131133
pressed.emit()

0 commit comments

Comments
 (0)