forked from woofmeow/straywild
fix controller file dialog navigation
This commit is contained in:
parent
2208977c8d
commit
e12ed54ab8
6 changed files with 469 additions and 26 deletions
|
|
@ -116,6 +116,64 @@ func _process(_delta: float) -> void:
|
|||
_connect_file_dialog_text_controls(dialog)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if (
|
||||
_controller_text_entry_is_open.is_valid()
|
||||
and bool(_controller_text_entry_is_open.call())
|
||||
):
|
||||
return
|
||||
if not (event is InputEventJoypadButton or event is InputEventJoypadMotion):
|
||||
return
|
||||
var scope: Window = _active_file_dialog_scope()
|
||||
if scope == null:
|
||||
return
|
||||
var focused: Control = scope.gui_get_focus_owner()
|
||||
if focused == null:
|
||||
return
|
||||
var direction: Vector2 = _controller_direction(event)
|
||||
var item_list := focused as ItemList
|
||||
if (
|
||||
item_list != null
|
||||
and direction != Vector2.ZERO
|
||||
and FileDialogControllerNavigationType.move_from_item_list(
|
||||
item_list, direction
|
||||
)
|
||||
):
|
||||
get_viewport().set_input_as_handled()
|
||||
return
|
||||
var button_event := event as InputEventJoypadButton
|
||||
if (
|
||||
button_event != null
|
||||
and button_event.pressed
|
||||
and event.is_action_pressed(&"ui_accept")
|
||||
and (focused is LineEdit or focused is TextEdit)
|
||||
and _controller_text_entry_request.is_valid()
|
||||
and bool(_controller_text_entry_request.call(focused))
|
||||
):
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
|
||||
func _active_file_dialog_scope() -> Window:
|
||||
for reference_value: WeakRef in _tracked_file_dialogs.values():
|
||||
var dialog := reference_value.get_ref() as FileDialog
|
||||
if dialog == null or not is_instance_valid(dialog) or not dialog.visible:
|
||||
continue
|
||||
return FileDialogControllerNavigationType.active_scope(dialog)
|
||||
return null
|
||||
|
||||
|
||||
func _controller_direction(event: InputEvent) -> Vector2:
|
||||
if event.is_action_pressed(&"ui_up"):
|
||||
return Vector2.UP
|
||||
if event.is_action_pressed(&"ui_down"):
|
||||
return Vector2.DOWN
|
||||
if event.is_action_pressed(&"ui_left"):
|
||||
return Vector2.LEFT
|
||||
if event.is_action_pressed(&"ui_right"):
|
||||
return Vector2.RIGHT
|
||||
return Vector2.ZERO
|
||||
|
||||
|
||||
func _connect_file_dialog_text_controls(dialog: FileDialog) -> void:
|
||||
var scope: Window = FileDialogControllerNavigationType.active_scope(dialog)
|
||||
for control: Control in (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue