This repository has been archived on 2024-07-02. You can view files and clone it, but cannot push or open issues or pull requests.
HoppyEaster/Scripts/UI/Remaping/RemapController.gd

36 lines
860 B
GDScript3
Raw Normal View History

extends Control
var remap_button : Button
var remap_action : String
func _unhandled_key_input(event):
if remap_button != null and event.pressed:
remap_key(event)
pass
func _ready():
set_process_unhandled_key_input(false)
remap_button = null
pass
func start_remap(button : Button, action : String):
if(remap_button != null):
remap_button.display_key()
remap_button = button
remap_action = action
remap_button.text = "..."
set_process_unhandled_key_input(true)
2023-04-10 22:27:26 +00:00
button.release_focus()
pass
func remap_key(event):
2023-04-10 22:27:26 +00:00
set_process_unhandled_key_input(false)
for key in InputMap.action_get_events(remap_action):
2023-04-10 22:27:26 +00:00
InputMap.action_erase_event(remap_action, key)
InputMap.action_add_event(remap_action, event)
2023-04-10 22:27:26 +00:00
Save.game_data["%s" % [remap_action]] = event.keycode
remap_button.display_key()
2023-04-10 22:27:26 +00:00
remap_button.grab_focus()
remap_button = null
pass