basic implementation of input remapping
This commit is contained in:
parent
5f2b3c6d5e
commit
70ef1a8450
5 changed files with 290 additions and 45 deletions
55
objects/hud/set_keyboard_button.gd
Normal file
55
objects/hud/set_keyboard_button.gd
Normal 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()
|
Loading…
Add table
Add a link
Reference in a new issue