refactor: some events turned into gui_input

This commit is contained in:
tiger tiger tiger 2026-01-22 17:42:56 +01:00
parent 69cec724f5
commit 9990a80845
6 changed files with 13 additions and 20 deletions

View File

@ -390,7 +390,7 @@ func handle_drop(draggable: Draggable) -> int:
# Takes the inputs for control inputs # Takes the inputs for control inputs
func _input(event : InputEvent) -> void: func _gui_input(event : InputEvent) -> void:
if event.is_action_pressed("ui_cancel"): if event.is_action_pressed("ui_cancel"):
closed.emit() closed.emit()
get_viewport().set_input_as_handled() get_viewport().set_input_as_handled()

View File

@ -56,11 +56,11 @@ func _get_hover_handler() -> Node:
## Walks up the scene tree to find the CardBoard ## Walks up the scene tree to find the CardBoard
func _get_board() -> Node: func _get_board() -> CardBoard:
var node := get_parent() var node := get_parent()
while node: while node:
if node.has_method("handle_mouse_button"): if node.has_method("handle_mouse_button"):
return node return node as CardBoard
node = node.get_parent() node = node.get_parent()
return null return null
@ -91,23 +91,16 @@ func _on_mouse_exited() -> void:
## Handles global input events (used to catch mouse release during drag) ## Handles global input events (used to catch mouse release during drag)
func _input(event: InputEvent) -> void: func _input(event: InputEvent) -> void:
if event is InputEventMouseButton: if is_dragged and event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.is_released():
if event.button_index == MOUSE_BUTTON_LEFT and not event.pressed: is_dragged = false
if is_dragged: # Trigger the drop logic
is_dragged = false _get_board().handle_mouse_button(event, self)
# Trigger the drop logic
var board := _get_board()
if board and board.has_method("_end_drag"):
board._end_drag(self)
## Handles input events on this Area2D (used to start drag) ## Handles input events on this Area2D (used to start drag)
func _on_input_event(_viewport, event, _shape_idx): func _on_input_event(_viewport, event, _shape_idx):
if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed: if highlighted and event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
if highlighted: _get_board().handle_mouse_button(event, self)
var board := _get_board()
if board and board.has_method("handle_mouse_button"):
board.handle_mouse_button(event, self)
## Starts a drag operation ## Starts a drag operation

View File

@ -17,7 +17,7 @@ func _process(delta: float) -> void:
offset.y -= scroll_speed * delta offset.y -= scroll_speed * delta
Handle.position = offset Handle.position = offset
func _input(event: InputEvent) -> void: func _gui_input(event: InputEvent) -> void:
if event.is_action_pressed("ui_menu") or event.is_action_pressed("ui_cancel") or event.is_action_pressed("ui_accept"): if event.is_action_pressed("ui_menu") or event.is_action_pressed("ui_cancel") or event.is_action_pressed("ui_accept"):
stop() stop()

View File

@ -38,6 +38,6 @@ func _on_exit_button_pressed() -> void:
leave_stage.emit() leave_stage.emit()
State.save_settings() State.save_settings()
func _input(event: InputEvent) -> void: func _gui_input(event: InputEvent) -> void:
if event.is_action_pressed("ui_cancel") and focused: if event.is_action_pressed("ui_cancel") and focused:
leave_stage.emit() leave_stage.emit()

View File

@ -40,7 +40,7 @@ func _on_exit_button_pressed() -> void:
leave_stage.emit() leave_stage.emit()
State.save_settings() State.save_settings()
func _input(event: InputEvent) -> void: func _gui_input(event: InputEvent) -> void:
if event.is_action_pressed("ui_cancel") and focused: if event.is_action_pressed("ui_cancel") and focused:
leave_stage.emit() leave_stage.emit()

View File

@ -126,7 +126,7 @@ func has_more_saves() -> bool:
return true return true
return false return false
func _input(event: InputEvent) -> void: func _gui_input(event: InputEvent) -> void:
if event.is_action_pressed("ui_cancel"): if event.is_action_pressed("ui_cancel"):
cancel() cancel()