59 lines
1.8 KiB
GDScript3
59 lines
1.8 KiB
GDScript3
|
extends BaseUI
|
||
|
|
||
|
var last_key_pressed = null
|
||
|
|
||
|
func input_list_to_string(inputlist: Array) -> String:
|
||
|
var arr_str = []
|
||
|
for input in inputlist:
|
||
|
arr_str.append(input.as_text())
|
||
|
|
||
|
var psa = PoolStringArray(arr_str)
|
||
|
return psa.join(", ")
|
||
|
|
||
|
onready var keymap_btns = {
|
||
|
$VBoxContainer/GridContainer/Forward: "move_forward",
|
||
|
$VBoxContainer/GridContainer/Backward: "move_backward",
|
||
|
$VBoxContainer/GridContainer/Left: "move_left",
|
||
|
$VBoxContainer/GridContainer/Right: "move_right",
|
||
|
$VBoxContainer/GridContainer/Jump: "move_jump",
|
||
|
$VBoxContainer/GridContainer/Frontcamera: "camera_front",
|
||
|
$VBoxContainer/GridContainer/Sprint: "move_sprint",
|
||
|
$VBoxContainer/GridContainer/Changeweapon: "weapon_forward",
|
||
|
}
|
||
|
|
||
|
func _ready():
|
||
|
add_user_signal("key_pressed", [{"name": "event", "type": InputEvent}])
|
||
|
refresh_keymap_btns()
|
||
|
for input_btn in keymap_btns:
|
||
|
input_btn.connect("pressed", self, "_on_keymap_pressed", [input_btn, keymap_btns[input_btn]])
|
||
|
|
||
|
func refresh_keymap_btns():
|
||
|
for keymap_btn in keymap_btns:
|
||
|
refresh_keymap_btn(keymap_btn, keymap_btns[keymap_btn])
|
||
|
|
||
|
func refresh_keymap_btn(button: Button, action: String):
|
||
|
button.text = input_list_to_string(InputMap.get_action_list(action))
|
||
|
|
||
|
|
||
|
func _on_keymap_pressed(button: Button, action: String):
|
||
|
wait_for_new_key(button, action)
|
||
|
|
||
|
func wait_for_new_key(btn: Button, action: String):
|
||
|
btn.text = "Press a key..."
|
||
|
last_key_pressed = null
|
||
|
connect("key_pressed", self, "set_key", [action, btn], CONNECT_ONESHOT)
|
||
|
|
||
|
func set_key(key: InputEvent, action: String, btn: Button):
|
||
|
InputMap.action_erase_events(action)
|
||
|
InputMap.action_add_event(action, key)
|
||
|
refresh_keymap_btn(btn, action)
|
||
|
|
||
|
func _input(event: InputEvent):
|
||
|
if last_key_pressed or not event is InputEventKey:
|
||
|
return
|
||
|
last_key_pressed = event
|
||
|
emit_signal("key_pressed", event)
|
||
|
|
||
|
func _on_Save_pressed():
|
||
|
close()
|