diff --git a/project.godot b/project.godot index 666a68a2..6e7e50c1 100644 --- a/project.godot +++ b/project.godot @@ -100,6 +100,7 @@ pause={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194305,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":4,"pressure":0.0,"pressed":false,"script":null) ] } restart={ diff --git a/src/menus/ActionInputIcon.gd b/src/menus/ActionInputIcon.gd index 75e7857b..ffab07f9 100644 --- a/src/menus/ActionInputIcon.gd +++ b/src/menus/ActionInputIcon.gd @@ -7,6 +7,63 @@ extends RichTextLabel if Engine.is_editor_hint(): render_icon() +@export var joy_button = [] : + set(v): + if input_text == "" and v and len(v) == 2: + input_text = button_to_input_text(v) + +func button_to_input_text(button): + var device_type = button[0] + var idx = button[1] + if device_type == "keyboard": + # not sure i love this + device_type = "generic" + + var dev_map = device_button_idx_input_text.get(device_type, {}) + var txt + if idx in dev_map: + txt = dev_map.get(idx, "") + + return txt + + +@export var joy_axis = [] : + set(v): + if input_text == "" and v and len(v) == 2: + input_text = axis_to_input_text(v) + +func axis_to_input_text(axis): + var idx = axis[0] + var val = axis[1] + + var txt = "" + match idx: + JOY_AXIS_LEFT_X: + if val > 0: + txt = "Joystick right" + else: + txt = "Joystick left" + JOY_AXIS_LEFT_Y: + if val > 0: + txt = "Joystick down" + else: + txt = "Joystick up" + JOY_AXIS_RIGHT_X: + if val > 0: + txt = "Joystick right" + else: + txt = "Joystick left" + JOY_AXIS_RIGHT_Y: + if val > 0: + txt = "Joystick down" + else: + txt = "Joystick up" + [JOY_AXIS_INVALID, JOY_AXIS_TRIGGER_LEFT, JOY_AXIS_TRIGGER_RIGHT, JOY_AXIS_SDL_MAX, JOY_AXIS_MAX]: + Log.pr("Unsupported joystick axis") + return + return txt + + func _ready(): render_icon() @@ -185,11 +242,12 @@ var keymap_extra={ "B Button"="B", "X Button"="X", "Y Button"="Y", + "Cross Button"="X", # mapped to X button for now "Square Button"="N", "Triangle Button"="T", "Circle Button"="C", "Dpad"="D", - "Dpad Up"="^", + "Dpad up"="^", "Dpad down"="V", "Dpad left"="<", "Dpad right"=">", @@ -220,3 +278,82 @@ var keymap_extra={ "Joystick 'L'"="{", "Joystick 'R'"="}", } + +# unfortunate we can't use constants to create dictionary keys here +var device_button_idx_input_text = { + "xbox"={ + 0: "A Button", + 1: "B Button", + 2: "X Button", + 3: "Y Button", + 4: "Pause", # back + 5: "Home", + 6: "Menu", # menu + 7: "Left Stick", + 8: "Right Stick", + 9: "Left Button", + 10: "Right Button", + 11: "Dpad up", + 12: "Dpad down", + 13: "Dpad left", + 14: "Dpad right", + 15: "Share", + }, + "switch"={ + 0: "B Button", + 1: "A Button", + 2: "Y Button", + 3: "X Button", + 4: "Menu", # - + 5: "", + 6: "Pause", # + + 7: "Left Stick", + 8: "Right Stick", + 9: "Left Button", + 10: "Right Button", + 11: "Dpad up", + 12: "Dpad down", + 13: "Dpad left", + 14: "Dpad right", + 15: "Capture", + }, + "switch_left_joycon"={}, + "switch_right_joycon"={}, + "playstation"={ + 0: "Cross Button", + 1: "Circle Button", + 2: "Square Button", + 3: "Triangle Button", + 4: "Menu", # Select + 5: "PS", + 6: "Pause", # Start + 7: "Left Stick", + 8: "Right Stick", + 9: "Left Button", + 10: "Right Button", + 11: "Dpad up", + 12: "Dpad down", + 13: "Dpad left", + 14: "Dpad right", + 15: "Microphone", + 20: "Touchpad", + }, + "generic"={ + 0: "A Button", + 1: "B Button", + 2: "X Button", + 3: "Y Button", + 4: "Pause", # back + 5: "Home", + 6: "Menu", # menu + 7: "Left Stick", + 8: "Right Stick", + 9: "Left Button", + 10: "Right Button", + 11: "Dpad up", + 12: "Dpad down", + 13: "Dpad left", + 14: "Dpad right", + 15: "Share", + }, + } diff --git a/src/menus/ActionInputIcon.tscn b/src/menus/ActionInputIcon.tscn index 8c008778..8153cf9a 100644 --- a/src/menus/ActionInputIcon.tscn +++ b/src/menus/ActionInputIcon.tscn @@ -6,13 +6,15 @@ [node name="ActionInputIcon" type="RichTextLabel"] visible = false clip_contents = false -custom_minimum_size = Vector2(32, 0) +custom_minimum_size = Vector2(50, 0) offset_top = -16.0 offset_right = 32.0 offset_bottom = 32.0 theme = ExtResource("1_v6qpj") bbcode_enabled = true -text = "a" +text = "[b]N" fit_content = true scroll_active = false script = ExtResource("2_lnakd") +joy_button = null +joy_axis = null diff --git a/src/menus/EditActionRow.gd b/src/menus/EditActionRow.gd index ad0557e5..8e2ef11b 100644 --- a/src/menus/EditActionRow.gd +++ b/src/menus/EditActionRow.gd @@ -18,28 +18,23 @@ func render_action_icons(): var joypad_inputs = InputHelper.get_joypad_inputs_for_action(action_name) U.remove_children(action_inputs) + # TODO if no action icon is found, we ought to remove the icon Log.pr("\n\nicons for", action_name) for inp in keyboard_inputs: var icon = input_icon_scene.instantiate() var key_str_mods = OS.get_keycode_string(inp.get_keycode_with_modifiers()) icon.input_text = key_str_mods - # TODO if no action icon is found, we ought to remove the icon action_inputs.add_child(icon) Log.pr("joy inputs", joypad_inputs) for inp in joypad_inputs: var icon = input_icon_scene.instantiate() if "axis" in inp: - var joy_axis_idx = inp.axis - Log.pr("joy_axis_idx", joy_axis_idx) - icon.input_text = "Joystick left" + icon.joy_axis = [inp.axis, inp.axis_value] else: var joy_button_idx = inp.button_index - Log.pr("joy_button_idx", joy_button_idx) - icon.input_text = "B Button" - # TODO if no action icon is found, we ought to remove the icon - action_inputs.add_child(icon) - + Log.pr("joy_button_idx", InputHelper.guess_device_name(), joy_button_idx) + icon.joy_button = [InputHelper.guess_device_name(), inp.button_index] - # TODO pull controller icons for the given inputs + action_inputs.add_child(icon)