2020-02-12 23:42:12 +01:00
|
|
|
extends Button
|
|
|
|
|
2022-03-26 11:00:50 +01:00
|
|
|
@export var action: String = "ui_up"
|
2020-02-12 23:42:12 +01:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
assert(InputMap.has_action(action))
|
|
|
|
set_process_unhandled_key_input(false)
|
|
|
|
display_current_key()
|
|
|
|
|
|
|
|
|
2022-04-03 07:21:54 +02:00
|
|
|
func _toggled(is_button_pressed):
|
|
|
|
set_process_unhandled_key_input(is_button_pressed)
|
|
|
|
if is_button_pressed:
|
2020-02-12 23:42:12 +01:00
|
|
|
text = "... Key"
|
|
|
|
release_focus()
|
|
|
|
else:
|
|
|
|
display_current_key()
|
|
|
|
|
|
|
|
|
|
|
|
func _unhandled_key_input(event):
|
|
|
|
# Note that you can use the _input callback instead, especially if
|
|
|
|
# you want to work with gamepads.
|
|
|
|
remap_action_to(event)
|
2022-04-03 07:21:54 +02:00
|
|
|
button_pressed = false
|
2020-02-12 23:42:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
func remap_action_to(event):
|
2022-05-07 23:33:49 +02:00
|
|
|
# We first change the event in this game instance.
|
2020-02-12 23:42:12 +01:00
|
|
|
InputMap.action_erase_events(action)
|
|
|
|
InputMap.action_add_event(action, event)
|
2022-05-07 23:33:49 +02:00
|
|
|
# And then save it to the keymaps file
|
|
|
|
KeyPersistence.keymaps[action] = event
|
|
|
|
KeyPersistence.save_keymap()
|
2020-02-12 23:42:12 +01:00
|
|
|
text = "%s Key" % event.as_text()
|
|
|
|
|
|
|
|
|
|
|
|
func display_current_key():
|
2022-04-03 07:21:54 +02:00
|
|
|
var current_key = InputMap.action_get_events(action)[0].as_text()
|
2020-02-12 23:42:12 +01:00
|
|
|
text = "%s Key" % current_key
|