basic implementation of input remapping

This commit is contained in:
Haze Weathers 2024-01-15 18:00:03 -05:00
parent 5f2b3c6d5e
commit 70ef1a8450
5 changed files with 290 additions and 45 deletions

View file

@ -0,0 +1,55 @@
extends Button
const BLINK_SPEED: int = 150
export var action: String
var listen := false
func _init() -> void:
connect("pressed", self, "_on_pressed")
func _ready() -> void:
_update_text()
func _process(delta: float) -> void:
if listen:
if Time.get_ticks_msec() % (BLINK_SPEED * 2) < BLINK_SPEED:
modulate.a = 0.0
else:
modulate.a = 1.0
func _update_text() -> void:
text = OS.get_scancode_string(Controls.get_key(action))
modulate.a = 1.0
func _on_pressed() -> void:
if not listen:
listen = true
disabled = true
text = ""
get_tree().create_timer(2.0, true).connect("timeout", self, "_on_timeout")
func _on_timeout() -> void:
listen = false
disabled = false
_update_text()
func _gui_input(event: InputEvent) -> void:
if listen:
if event is InputEventKey and event.pressed:
Controls.set_key(action, event.physical_scancode)
listen = false
set_deferred("disabled", false)
_update_text()
accept_event()