|
@ -18,8 +18,7 @@ func _ready(): |
|
|
|
|
|
|
|
|
func init_mapping(): |
|
|
func init_mapping(): |
|
|
new_inputs = {} |
|
|
new_inputs = {} |
|
|
for action in InputMap.get_actions(): |
|
|
|
|
|
if action.begins_with("controls_"): |
|
|
|
|
|
|
|
|
for action in settings.CONTROL_ACTIONS: |
|
|
var action_label = Label.new() |
|
|
var action_label = Label.new() |
|
|
action_label.set_name(action + "_label") |
|
|
action_label.set_name(action + "_label") |
|
|
action_label.set_text(action) |
|
|
action_label.set_text(action) |
|
@ -36,54 +35,89 @@ func init_mapping(): |
|
|
joypad_action_button.set_flat(true) |
|
|
joypad_action_button.set_flat(true) |
|
|
joypad_action_button.set_meta("action",action) |
|
|
joypad_action_button.set_meta("action",action) |
|
|
|
|
|
|
|
|
for mapping in InputMap.get_action_list(action): |
|
|
|
|
|
if mapping is InputEventKey: |
|
|
|
|
|
key_action_button.set_text(mapping.as_text()) |
|
|
|
|
|
key_action_button.set_tooltip(mapping.as_text()) |
|
|
|
|
|
elif mapping is InputEventJoypadButton: |
|
|
|
|
|
joypad_action_button.set_tooltip(str(mapping.button_index)) |
|
|
|
|
|
if has_node("icons/joypad/" + str(mapping.button_index)): |
|
|
|
|
|
joypad_action_button.set_button_icon(get_node("icons/joypad/" + str(mapping.button_index)).get_button_icon()) |
|
|
|
|
|
|
|
|
for event in InputMap.get_action_list(action): |
|
|
|
|
|
if event is InputEventKey: |
|
|
|
|
|
key_action_button.set_text(event.as_text()) |
|
|
|
|
|
key_action_button.set_tooltip(event.as_text()) |
|
|
|
|
|
elif event is InputEventJoypadButton: |
|
|
|
|
|
joypad_action_button.set_tooltip(str(event.button_index)) |
|
|
|
|
|
if has_node("icons/joypad/" + str(event.button_index)): |
|
|
|
|
|
joypad_action_button.set_button_icon(get_node("icons/joypad/" + str(event.button_index)).get_button_icon()) |
|
|
else: |
|
|
else: |
|
|
joypad_action_button.set_button_icon(get_node("icons/joypad/other").get_button_icon()) |
|
|
joypad_action_button.set_button_icon(get_node("icons/joypad/other").get_button_icon()) |
|
|
joypad_action_button.set_text(str(mapping.button_index)) |
|
|
|
|
|
|
|
|
joypad_action_button.set_text(str(event.button_index)) |
|
|
|
|
|
|
|
|
grid.add_child(key_action_button) |
|
|
grid.add_child(key_action_button) |
|
|
key_action_button.connect("pressed",self,"_on_button_pressed",[action, INPUT_TYPE_KEY]) |
|
|
|
|
|
|
|
|
key_action_button.connect("pressed",self,"_on_button_pressed",[key_action_button, INPUT_TYPE_KEY]) |
|
|
|
|
|
|
|
|
grid.add_child(joypad_action_button) |
|
|
grid.add_child(joypad_action_button) |
|
|
joypad_action_button.connect("pressed",self,"_on_button_pressed",[action, INPUT_TYPE_JOYPAD]) |
|
|
|
|
|
|
|
|
joypad_action_button.connect("pressed",self,"_on_button_pressed",[joypad_action_button, INPUT_TYPE_JOYPAD]) |
|
|
|
|
|
|
|
|
func _unhandled_input(event): |
|
|
func _unhandled_input(event): |
|
|
if key_dialog.is_visible_in_tree(): |
|
|
if key_dialog.is_visible_in_tree(): |
|
|
|
|
|
var action_button = key_dialog.find_node("action_button") |
|
|
|
|
|
var check_usage = false |
|
|
if key_dialog.get_meta("type") == INPUT_TYPE_KEY && event is InputEventKey: |
|
|
if key_dialog.get_meta("type") == INPUT_TYPE_KEY && event is InputEventKey: |
|
|
|
|
|
check_usage = true |
|
|
last_event = event |
|
|
last_event = event |
|
|
key_dialog.set_text(tr(last_event.as_text())) |
|
|
|
|
|
key_dialog.get_ok().set_disabled(false) |
|
|
|
|
|
|
|
|
action_button.set_button_icon(get_node("icons/key").get_button_icon()) |
|
|
|
|
|
action_button.set_text(event.as_text()) |
|
|
|
|
|
action_button.set_tooltip(event.as_text()) |
|
|
elif key_dialog.get_meta("type") == INPUT_TYPE_JOYPAD && event is InputEventJoypadButton: |
|
|
elif key_dialog.get_meta("type") == INPUT_TYPE_JOYPAD && event is InputEventJoypadButton: |
|
|
|
|
|
check_usage = true |
|
|
last_event = event |
|
|
last_event = event |
|
|
key_dialog.set_text(last_event.as_text()) |
|
|
|
|
|
|
|
|
action_button.set_tooltip(str(event.button_index)) |
|
|
|
|
|
if has_node("icons/joypad/" + str(event.button_index)): |
|
|
|
|
|
action_button.set_text("") |
|
|
|
|
|
action_button.set_button_icon(get_node("icons/joypad/" + str(event.button_index)).get_button_icon()) |
|
|
|
|
|
else: |
|
|
|
|
|
action_button.set_button_icon(get_node("icons/joypad/other").get_button_icon()) |
|
|
|
|
|
action_button.set_text(str(event.button_index)) |
|
|
|
|
|
|
|
|
|
|
|
if check_usage: |
|
|
|
|
|
var has_event = "" |
|
|
|
|
|
for action in settings.CONTROL_ACTIONS: |
|
|
|
|
|
if InputMap.event_is_action(event, action): |
|
|
|
|
|
has_event = action |
|
|
|
|
|
|
|
|
|
|
|
if not has_event == "" && not has_event == last_action: |
|
|
|
|
|
key_dialog.set_text(tr("KEY_ALREADY_TAKEN") + '\n\'' + tr(has_event) + '\'') |
|
|
|
|
|
key_dialog.get_ok().set_disabled(true) |
|
|
|
|
|
else: |
|
|
|
|
|
key_dialog.set_text(tr("PRESS_KEY")) |
|
|
key_dialog.get_ok().set_disabled(false) |
|
|
key_dialog.get_ok().set_disabled(false) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_button_pressed(action, type): |
|
|
|
|
|
last_action = action |
|
|
|
|
|
|
|
|
func _on_button_pressed(button, type): |
|
|
|
|
|
last_action = button.get_meta("action") |
|
|
last_event = null |
|
|
last_event = null |
|
|
|
|
|
|
|
|
|
|
|
var action_button = key_dialog.find_node("action_button") |
|
|
|
|
|
action_button.set_text("") |
|
|
|
|
|
action_button.set_button_icon(null) |
|
|
key_dialog.set_text(tr("PRESS_KEY")) |
|
|
key_dialog.set_text(tr("PRESS_KEY")) |
|
|
key_dialog.set_meta("type", type) |
|
|
key_dialog.set_meta("type", type) |
|
|
key_dialog.connect("confirmed",self,"_on_dialog_confirmed",[type]) |
|
|
|
|
|
|
|
|
key_dialog.connect("confirmed",self,"_on_dialog_confirmed",[button]) |
|
|
key_dialog.get_ok().set_disabled(true) |
|
|
key_dialog.get_ok().set_disabled(true) |
|
|
|
|
|
key_dialog.get_label().set_align(HALIGN_CENTER) |
|
|
key_dialog.popup_centered() |
|
|
key_dialog.popup_centered() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _on_dialog_confirmed(type): |
|
|
|
|
|
|
|
|
func _on_dialog_confirmed(button): |
|
|
if not new_inputs.has(last_action): |
|
|
if not new_inputs.has(last_action): |
|
|
new_inputs[last_action] = {} |
|
|
new_inputs[last_action] = {} |
|
|
match key_dialog.get_meta("type"): |
|
|
match key_dialog.get_meta("type"): |
|
|
INPUT_TYPE_KEY: |
|
|
INPUT_TYPE_KEY: |
|
|
if last_event is InputEventKey: |
|
|
if last_event is InputEventKey: |
|
|
new_inputs[last_action]["key"] = OS.get_scancode_string(last_event.scancode) |
|
|
new_inputs[last_action]["key"] = OS.get_scancode_string(last_event.scancode) |
|
|
|
|
|
button.set_text(last_event.as_text()) |
|
|
|
|
|
button.set_tooltip(last_event.as_text()) |
|
|
INPUT_TYPE_JOYPAD: |
|
|
INPUT_TYPE_JOYPAD: |
|
|
if last_event is InputEventJoypadButton: |
|
|
if last_event is InputEventJoypadButton: |
|
|
new_inputs[last_action]["joypad"] = last_event.button_index |
|
|
new_inputs[last_action]["joypad"] = last_event.button_index |
|
|
print(new_inputs) |
|
|
|
|
|
|
|
|
button.set_tooltip(str(last_event.button_index)) |
|
|
|
|
|
if has_node("icons/joypad/" + str(last_event.button_index)): |
|
|
|
|
|
button.set_button_icon(get_node("icons/joypad/" + str(last_event.button_index)).get_button_icon()) |
|
|
|
|
|
else: |
|
|
|
|
|
button.set_button_icon(get_node("icons/joypad/other").get_button_icon()) |
|
|
|
|
|
button.set_text(str(last_event.button_index)) |