summaryrefslogtreecommitdiff
path: root/addons/gdUnit4/src/ui/settings/GdUnitInputCapture.gd
diff options
context:
space:
mode:
authorradiohotline <radoihotline@disroot.rg>2026-08-25 16:33:56 +0300
committerradiohotline <radoihotline@disroot.rg>2026-08-25 16:33:56 +0300
commita89e744ed0e8c759caf041a580112365bbfe4303 (patch)
treedd61e320904176995727e86a857d00c90d4933ba /addons/gdUnit4/src/ui/settings/GdUnitInputCapture.gd
parent6d53d8cac78250dc888aa49d5f9d4175c6652feb (diff)
escoria updateHEADmain
Diffstat (limited to 'addons/gdUnit4/src/ui/settings/GdUnitInputCapture.gd')
-rw-r--r--addons/gdUnit4/src/ui/settings/GdUnitInputCapture.gd56
1 files changed, 56 insertions, 0 deletions
diff --git a/addons/gdUnit4/src/ui/settings/GdUnitInputCapture.gd b/addons/gdUnit4/src/ui/settings/GdUnitInputCapture.gd
new file mode 100644
index 0000000..b5cc837
--- /dev/null
+++ b/addons/gdUnit4/src/ui/settings/GdUnitInputCapture.gd
@@ -0,0 +1,56 @@
+@tool
+class_name GdUnitInputCapture
+extends Control
+
+signal input_completed(input_event: InputEventKey)
+
+
+var _tween: Tween
+var _input_event: InputEventKey
+
+
+func _ready() -> void:
+ reset()
+ self_modulate = Color.WHITE
+ _tween = create_tween()
+ @warning_ignore("return_value_discarded")
+ _tween.set_loops()
+ @warning_ignore("return_value_discarded")
+ _tween.tween_property(%Label, "self_modulate", Color(1, 1, 1, .8), 1.0).from_current().set_trans(Tween.TRANS_BACK).set_ease(Tween.EASE_IN_OUT)
+
+
+func reset() -> void:
+ _input_event = InputEventKey.new()
+
+
+func _input(event: InputEvent) -> void:
+ if not is_visible_in_tree():
+ return
+ if event is InputEventKey and event.is_pressed() and not event.is_echo():
+ var _event := event as InputEventKey
+ match _event.keycode:
+ KEY_CTRL:
+ _input_event.ctrl_pressed = true
+ KEY_SHIFT:
+ _input_event.shift_pressed = true
+ KEY_ALT:
+ _input_event.alt_pressed = true
+ KEY_META:
+ _input_event.meta_pressed = true
+ _:
+ _input_event.keycode = _event.keycode
+ _apply_input_modifiers(_event)
+ accept_event()
+
+ if event is InputEventKey and not event.is_pressed():
+ input_completed.emit(_input_event)
+ hide()
+
+
+func _apply_input_modifiers(event: InputEvent) -> void:
+ if event is InputEventWithModifiers:
+ var _event := event as InputEventWithModifiers
+ _input_event.meta_pressed = _event.meta_pressed or _input_event.meta_pressed
+ _input_event.alt_pressed = _event.alt_pressed or _input_event.alt_pressed
+ _input_event.shift_pressed = _event.shift_pressed or _input_event.shift_pressed
+ _input_event.ctrl_pressed = _event.ctrl_pressed or _input_event.ctrl_pressed