Skip to content

Commit 069d690

Browse files
committed
add gamepad config and keyboard to gamepad mapping
1 parent 5e50208 commit 069d690

16 files changed

Lines changed: 523 additions & 148 deletions

File tree

lib/items/debug.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const VtItem = preload("res://lib/items/vt_item.gd")
66
@onready var item = get_parent()
77

88
func _process(delta: float) -> void:
9-
if not visible:
9+
if visible:
1010
return
1111

1212
queue_redraw()

lib/items/vt_item.tscn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ script = ExtResource("1_pu6sx")
88
centered = true
99

1010
[node name="Debug" type="Node2D" parent="."]
11-
visible = false
1211
script = ExtResource("3_wpqse")
1312

1413
[connection signal="drag_pressed" from="." to="." method="_on_drag_pressed"]

lib/preferences.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const Files = preload("res://lib/utils/files.gd")
44
const UserSettings = "user://settings.json"
55

66
var _data = {}
7+
@export var debug: bool = false
78

89
func _ready() -> void:
910
get_tree().node_added.connect(

lib/tracking/gamepad/config.gd

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
extends PanelContainer
2+
3+
const GamepadTracker = preload("./gamepad_tracker.gd")
4+
5+
@onready var gamepads: OptionButton = %GamepadIndex
6+
@onready var input_rec = %InputRecPopup
7+
8+
var tracker: GamepadTracker
9+
10+
func _ready() -> void:
11+
var joypads = Input.get_connected_joypads()
12+
for i in joypads:
13+
gamepads.add_item(Input.get_joy_name(i), i)
14+
15+
for meta in tracker.keyboard_mapping:
16+
var label = Label.new()
17+
label.text = meta.name
18+
label.size_flags_horizontal = Control.SIZE_EXPAND_FILL
19+
var edit = Button.new()
20+
edit.text = OS.get_keycode_string(meta.key)
21+
edit.size_flags_horizontal = Control.SIZE_EXPAND_FILL
22+
edit.focus_mode = Control.FOCUS_NONE
23+
edit.pressed.connect(
24+
func ():
25+
%Modal.show()
26+
%InputRecPopup.grab_focus()
27+
28+
var pressed: Array = await %InputRecPopup.input_recorded
29+
30+
if len(pressed) > 0:
31+
var key = pressed[0]
32+
edit.text = OS.get_keycode_string(key)
33+
meta.key = key
34+
%Modal.hide()
35+
)
36+
37+
%KeytoGamepad.add_child(label)
38+
%KeytoGamepad.add_child(edit)
39+
40+
_on_gamepad_index_item_selected(gamepads.selected)
41+
42+
func _on_gamepad_index_item_selected(index: int) -> void:
43+
var id = gamepads.get_item_id(index)
44+
if id == 9999: #kb
45+
id = -1
46+
tracker.gamepad_index = id
47+
%KeytoGamepad.visible = id == -1
48+
49+
func _on_dpad_mapping_toggled(toggled_on: bool) -> void:
50+
tracker.dpad_to_ls = toggled_on

lib/tracking/gamepad/config.gd.uid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
uid://ddqdj7ehf48j5

lib/tracking/gamepad/config.tscn

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[gd_scene load_steps=4 format=3 uid="uid://rx1k71lk3xi2"]
2+
3+
[ext_resource type="Script" uid="uid://ddqdj7ehf48j5" path="res://lib/tracking/gamepad/config.gd" id="1_ya4c7"]
4+
[ext_resource type="PackedScene" uid="uid://d2a67yxp08esv" path="res://ui/modal/modal.tscn" id="1_yo73d"]
5+
[ext_resource type="PackedScene" uid="uid://hpg52fgw7kdc" path="res://studio/hud/input_recorder/input_rec_popup.tscn" id="2_ya4c7"]
6+
7+
[node name="Config" type="PanelContainer"]
8+
anchors_preset = 15
9+
anchor_right = 1.0
10+
anchor_bottom = 1.0
11+
grow_horizontal = 2
12+
grow_vertical = 2
13+
script = ExtResource("1_ya4c7")
14+
15+
[node name="VBoxContainer" type="VBoxContainer" parent="."]
16+
layout_mode = 2
17+
18+
[node name="Label" type="Label" parent="VBoxContainer"]
19+
layout_mode = 2
20+
text = "Gamepad"
21+
22+
[node name="GamepadIndex" type="OptionButton" parent="VBoxContainer"]
23+
unique_name_in_owner = true
24+
layout_mode = 2
25+
selected = 0
26+
item_count = 1
27+
popup/item_0/text = "Keyboard"
28+
popup/item_0/id = 9999
29+
30+
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
31+
layout_mode = 2
32+
33+
[node name="DpadMapping" type="CheckButton" parent="VBoxContainer"]
34+
layout_mode = 2
35+
text = "Map DPad to Left Stick"
36+
37+
[node name="KeytoGamepad" type="GridContainer" parent="VBoxContainer"]
38+
unique_name_in_owner = true
39+
layout_mode = 2
40+
theme_override_constants/h_separation = 8
41+
columns = 4
42+
43+
[node name="Modal" parent="." instance=ExtResource("1_yo73d")]
44+
unique_name_in_owner = true
45+
layer = 10
46+
visible = false
47+
48+
[node name="CenterContainer" type="CenterContainer" parent="Modal"]
49+
anchors_preset = 15
50+
anchor_right = 1.0
51+
anchor_bottom = 1.0
52+
grow_horizontal = 2
53+
grow_vertical = 2
54+
55+
[node name="InputRecPopup" parent="Modal/CenterContainer" instance=ExtResource("2_ya4c7")]
56+
unique_name_in_owner = true
57+
layout_mode = 2
58+
allow_modifiers = false
59+
allow_mouse_buttons = false
60+
61+
[connection signal="item_selected" from="VBoxContainer/GamepadIndex" to="." method="_on_gamepad_index_item_selected"]
62+
[connection signal="toggled" from="VBoxContainer/DpadMapping" to="." method="_on_dpad_mapping_toggled"]

0 commit comments

Comments
 (0)