Skip to content

Commit

Permalink
fix(Mouse): add better support for mouse/touch for buttons and menu c…
Browse files Browse the repository at this point in the history
…ards
  • Loading branch information
ShadowApex committed Dec 30, 2024
1 parent 1bb836e commit 32d9ea2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
50 changes: 34 additions & 16 deletions core/ui/card_ui/quick_bar/qb_card.gd
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ signal nonchild_focused
else:
toggled_off.emit()
toggled.emit(is_toggled)
if not grower:
return
effect_in_progress = true
if is_toggled:
await grower.effect_finished
else:
await grower.shrink_finished
effect_in_progress = false

@onready var header_container := $%HeaderContainer as VBoxContainer
@onready var label := $%SectionLabel as Label
Expand All @@ -32,6 +40,7 @@ signal nonchild_focused
@onready var smooth_scroll := $SmoothScrollEffect as SmoothScrollEffect
@onready var grower := $GrowerEffect as GrowerEffect

var effect_in_progress := false
var focus_group: FocusGroup
var logger := Log.get_logger("QBCard", Log.LEVEL.INFO)

Expand Down Expand Up @@ -143,8 +152,9 @@ func _on_focus() -> void:
# If the card gets focused, and its already expanded, that means we've
# the user has focused outside the card, and we should shrink to hide the
# content
if is_toggled:
_on_button_up()
#if is_toggled:
# _on_button_up()
pass


func _on_unfocus() -> void:
Expand Down Expand Up @@ -186,30 +196,38 @@ func _on_focus_change(focused: Control) -> void:

func _on_button_up() -> void:
is_toggled = !is_toggled
if is_toggled:
toggled_on.emit()
else:
toggled_off.emit()

toggled.emit(is_toggled)


func _gui_input(event: InputEvent) -> void:
var is_valid := [event is InputEventAction, event is InputEventKey]
var is_valid := [
event is InputEventAction and event.is_action("ui_accept"),
event is InputEventKey and event.is_action("ui_accept"),
event is InputEventMouseButton and (event as InputEventMouseButton).button_index == MOUSE_BUTTON_LEFT,
]
if not true in is_valid:
return
if event.is_action("ui_accept"):
if event.is_pressed():
button_down.emit()
pressed.emit()
else:
button_up.emit()
# Mouse input changes focus on button down, which can cause the
# card to toggle off on focus change before the "button_up" event.
# To get around this, ignore mouse events if the grow/shrink effect
# is in progress.
if event is InputEventMouseButton and effect_in_progress:
return
if event.is_pressed():
button_down.emit()
pressed.emit()
else:
button_up.emit()


func _input(event: InputEvent) -> void:
if not is_toggled:
return
if not event.is_action("ogui_east"):
var is_valid := [
event.is_action("ogui_east"),
event.is_action("ogui_back"),
event.is_action("ui_cancel")
]
if not true in is_valid:
return
if not event.is_released():
return
Expand Down
6 changes: 6 additions & 0 deletions core/ui/card_ui/quick_bar/qb_card.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ on_signal = "focus_entered"
fade_out_signal = "nonchild_focused"
on_signal = "focus_entered"

[node name="HoverHighlightFadeEffect" parent="." node_paths=PackedStringArray("target") instance=ExtResource("3_6u4la")]
target = NodePath("../PanelContainer/HighlightTexture")
on_signal = "mouse_entered"
fade_out_signal = "mouse_exited"
on_signal = "mouse_entered"

[node name="GrowerEffect" parent="." node_paths=PackedStringArray("target", "content_container", "inside_panel", "separator") instance=ExtResource("4_1jyfj")]
target = NodePath("..")
content_container = NodePath("../MarginContainer/CardVBoxContainer/ContentContainer")
Expand Down
1 change: 1 addition & 0 deletions core/ui/card_ui/settings/general_settings_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func _add_user_themes() -> void:
var button := card_button_scene.instantiate() as CardButton
button.text = theme_name
button.custom_minimum_size.x = 158
button.click_focuses = false

# Add the theme setter behavior
var theme_setter := theme_setter_scene.instantiate() as ThemeSetter
Expand Down
4 changes: 3 additions & 1 deletion core/ui/components/card_button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ signal player_button_down(metaname: String, dbus_path: String)
@export_file("*.ogg") var select_audio = "res://assets/audio/interface/96127__bmaczero__contact1.ogg"

@export_category("Mouse")
@export var click_focuses := true
@export var click_focuses := false

var tween: Tween
var focus_audio_stream = load(focus_audio)
Expand Down Expand Up @@ -126,6 +126,8 @@ func _gui_input(event: InputEvent) -> void:
return
var dbus_path := event.get_meta("dbus_path", "") as String
if event is InputEventMouseButton and not click_focuses:
if (event as InputEventMouseButton).button_index != MOUSE_BUTTON_LEFT:
return
if event.is_pressed():
button_down.emit()
pressed.emit()
Expand Down

0 comments on commit 32d9ea2

Please sign in to comment.