99 lines
2.5 KiB
GDScript3
99 lines
2.5 KiB
GDScript3
|
class_name InputEventPicker extends Control
|
||
|
|
||
|
@onready var _label := $'VBoxContainer/Label' as Label
|
||
|
@onready var _button_reassign := $'VBoxContainer/Reassign' as Button
|
||
|
var event: InputEvent = null
|
||
|
|
||
|
func _ready() -> void:
|
||
|
update_label()
|
||
|
_button_reassign.pressed.connect(_reassign)
|
||
|
|
||
|
func update_label() -> void:
|
||
|
if not event:
|
||
|
_label.text = "None"
|
||
|
elif event is InputEventKey:
|
||
|
_label.text = event.as_text_physical_keycode()
|
||
|
elif event is InputEventJoypadMotion:
|
||
|
match event.axis:
|
||
|
JOY_AXIS_INVALID:
|
||
|
event = null
|
||
|
_label.text = "Unknown"
|
||
|
JOY_AXIS_LEFT_X:
|
||
|
if event.axis_value < 0.0:
|
||
|
_label.text = "Lstick left"
|
||
|
else:
|
||
|
_label.text = "Lstick right"
|
||
|
JOY_AXIS_LEFT_Y:
|
||
|
if event.axis_value < 0.0:
|
||
|
_label.text = "Lstick up"
|
||
|
else:
|
||
|
_label.text = "Lstick down"
|
||
|
JOY_AXIS_RIGHT_X:
|
||
|
if event.axis_value < 0.0:
|
||
|
_label.text = "Rstick left"
|
||
|
else:
|
||
|
_label.text = "Rstick right"
|
||
|
JOY_AXIS_RIGHT_Y:
|
||
|
if event.axis_value < 0.0:
|
||
|
_label.text = "Rstick up"
|
||
|
else:
|
||
|
_label.text = "Rstick down"
|
||
|
JOY_AXIS_TRIGGER_LEFT:
|
||
|
_label.text = "L2"
|
||
|
JOY_AXIS_TRIGGER_RIGHT:
|
||
|
_label.text = "R2"
|
||
|
_: _label.text = event.as_text()
|
||
|
elif event is InputEventJoypadButton:
|
||
|
match event.button_index:
|
||
|
JOY_BUTTON_INVALID:
|
||
|
event = null
|
||
|
_label.text = "Unknown"
|
||
|
JOY_BUTTON_A:
|
||
|
_label.text = "Bottom face"
|
||
|
JOY_BUTTON_B:
|
||
|
_label.text = "Right face"
|
||
|
JOY_BUTTON_X:
|
||
|
_label.text = "Left face"
|
||
|
JOY_BUTTON_Y:
|
||
|
_label.text = "Top face"
|
||
|
JOY_BUTTON_BACK:
|
||
|
_label.text = "Select/Back"
|
||
|
JOY_BUTTON_START:
|
||
|
_label.text = "Start"
|
||
|
JOY_BUTTON_LEFT_STICK:
|
||
|
_label.text = "L3"
|
||
|
JOY_BUTTON_RIGHT_STICK:
|
||
|
_label.text = "R3"
|
||
|
JOY_BUTTON_LEFT_SHOULDER:
|
||
|
_label.text = "L1"
|
||
|
JOY_BUTTON_RIGHT_SHOULDER:
|
||
|
_label.text = "R1"
|
||
|
JOY_BUTTON_DPAD_DOWN:
|
||
|
_label.text = "Dpad down"
|
||
|
JOY_BUTTON_DPAD_LEFT:
|
||
|
_label.text = "Dpad left"
|
||
|
JOY_BUTTON_DPAD_RIGHT:
|
||
|
_label.text = "Dpad right"
|
||
|
JOY_BUTTON_DPAD_UP:
|
||
|
_label.text = "Dpad up"
|
||
|
_: _label.text = event.as_text()
|
||
|
elif event is InputEventMouseButton:
|
||
|
match event.button_index:
|
||
|
MOUSE_BUTTON_LEFT:
|
||
|
_label.text = "Left click"
|
||
|
MOUSE_BUTTON_MIDDLE:
|
||
|
_label.text = "Middle click"
|
||
|
MOUSE_BUTTON_RIGHT:
|
||
|
_label.text = "Right click"
|
||
|
_: _label.text = event.as_text()
|
||
|
else:
|
||
|
_label.text = event.as_text()
|
||
|
|
||
|
func _reassign() -> void:
|
||
|
var maybe_event = await UI.Call(
|
||
|
preload("res://ui/OptionsMenu/InputEventEnquiry.tscn")
|
||
|
)
|
||
|
if maybe_event is InputEvent:
|
||
|
event = maybe_event
|
||
|
update_label()
|