Skip to content

Commit 8492756

Browse files
authored
Merge pull request #102 from Project-Funk-Engine/ControllerSupport
Controller support
2 parents d6ea540 + b3faba1 commit 8492756

19 files changed

+306
-96
lines changed

Globals/translations.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CONTROLS_TITLE_TYPE_QWER,QWERT,QWERT
1010
CONTROLS_TITLE_TYPE_ARROW,Arrow,箭头键
1111
CONTROLS_TITLE_SELECTED,Selected,已选择
1212
CONTROLS_WASD_BUTTON,WASD,WASD
13+
CONTROLS_CONTROLLER_BUTTON,Controller,控制杆
1314
CONTROLS_QWER_BUTTON,QWER,QWER
1415
CONTROLS_ARROW_BUTTON,Arrow Keys,箭头键
1516
CONTROLS_RETURN_BUTTON,Return,返回

project.godot

Lines changed: 85 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,24 @@ project/assembly_name="Funk Engine"
3939

4040
[game]
4141

42-
input_scheme="ARROWS"
4342

4443
[input]
4544

45+
ui_accept={
46+
"deadzone": 0.5,
47+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194309,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
48+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194310,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
49+
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":32,"physical_keycode":0,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
50+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null)
51+
]
52+
}
53+
ui_cancel={
54+
"deadzone": 0.5,
55+
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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,"location":0,"echo":false,"script":null)
56+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":true,"script":null)
57+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":true,"script":null)
58+
]
59+
}
4660
ui_left={
4761
"deadzone": 0.5,
4862
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
@@ -75,55 +89,106 @@ ui_down={
7589
, 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":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
7690
]
7791
}
78-
arrowUp={
92+
ARROWS_arrowUp={
7993
"deadzone": 0.5,
80-
"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":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
81-
, 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":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
82-
, 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":0,"physical_keycode":88,"key_label":0,"unicode":120,"location":0,"echo":false,"script":null)
83-
, 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":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null)
94+
"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":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
8495
, 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":0,"physical_keycode":50,"key_label":0,"unicode":50,"location":0,"echo":false,"script":null)
8596
]
8697
}
87-
arrowDown={
98+
ARROWS_arrowDown={
8899
"deadzone": 0.5,
89-
"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":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
90-
, 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":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
91-
, 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":0,"physical_keycode":67,"key_label":0,"unicode":99,"location":0,"echo":false,"script":null)
92-
, 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":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
100+
"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":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
93101
, 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":0,"physical_keycode":51,"key_label":0,"unicode":51,"location":0,"echo":false,"script":null)
94102
]
95103
}
96-
arrowLeft={
104+
ARROWS_arrowLeft={
97105
"deadzone": 0.5,
98-
"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":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
99-
, 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":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
100-
, 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":0,"physical_keycode":90,"key_label":0,"unicode":122,"location":0,"echo":false,"script":null)
101-
, 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":0,"physical_keycode":81,"key_label":0,"unicode":113,"location":0,"echo":false,"script":null)
106+
"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":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
102107
, 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":0,"physical_keycode":49,"key_label":0,"unicode":49,"location":0,"echo":false,"script":null)
103108
]
104109
}
105-
arrowRight={
110+
ARROWS_arrowRight={
106111
"deadzone": 0.5,
107112
"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":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
108-
, 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":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
109-
, 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":0,"physical_keycode":86,"key_label":0,"unicode":118,"location":0,"echo":false,"script":null)
110-
, 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":0,"physical_keycode":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null)
111113
, 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":0,"physical_keycode":52,"key_label":0,"unicode":52,"location":0,"echo":false,"script":null)
112114
]
113115
}
114116
Pause={
115117
"deadzone": 0.5,
116118
"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":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
119+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":true,"script":null)
117120
]
118121
}
119122
Inventory={
120123
"deadzone": 0.5,
121124
"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":0,"physical_keycode":73,"key_label":0,"unicode":105,"location":0,"echo":false,"script":null)
125+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":4,"pressure":0.0,"pressed":true,"script":null)
122126
]
123127
}
124128
Secondary={
125129
"deadzone": 0.5,
126130
"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":0,"physical_keycode":4194325,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
131+
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":10,"pressure":0.0,"pressed":true,"script":null)
132+
]
133+
}
134+
CONTROLLER_arrowUp={
135+
"deadzone": 0.5,
136+
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":3,"pressure":0.0,"pressed":true,"script":null)
137+
]
138+
}
139+
CONTROLLER_arrowDown={
140+
"deadzone": 0.5,
141+
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":true,"script":null)
142+
]
143+
}
144+
CONTROLLER_arrowLeft={
145+
"deadzone": 0.5,
146+
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":2,"pressure":0.0,"pressed":true,"script":null)
147+
]
148+
}
149+
CONTROLLER_arrowRight={
150+
"deadzone": 0.5,
151+
"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":true,"script":null)
152+
]
153+
}
154+
WASD_arrowUp={
155+
"deadzone": 0.5,
156+
"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":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
157+
]
158+
}
159+
WASD_arrowDown={
160+
"deadzone": 0.5,
161+
"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":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
162+
]
163+
}
164+
WASD_arrowLeft={
165+
"deadzone": 0.5,
166+
"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":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
167+
]
168+
}
169+
WASD_arrowRight={
170+
"deadzone": 0.5,
171+
"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":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
172+
]
173+
}
174+
QWERT_arrowUp={
175+
"deadzone": 0.5,
176+
"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":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
177+
]
178+
}
179+
QWERT_arrowDown={
180+
"deadzone": 0.5,
181+
"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":0,"physical_keycode":69,"key_label":0,"unicode":101,"location":0,"echo":false,"script":null)
182+
]
183+
}
184+
QWERT_arrowLeft={
185+
"deadzone": 0.5,
186+
"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":0,"physical_keycode":81,"key_label":0,"unicode":113,"location":0,"echo":false,"script":null)
187+
]
188+
}
189+
QWERT_arrowRight={
190+
"deadzone": 0.5,
191+
"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":0,"physical_keycode":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null)
127192
]
128193
}
129194

scenes/ChartViewport/scripts/ChartManager.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public NoteArrow AddArrowToLane(
9696
)
9797
{
9898
var newNote = CreateNote(type, note, beat); //TODO: Notes on track have unqiue visuals
99-
var loopArrow = CreateNote(type, note, beat + BeatsPerLoop); //Create a dummy arrow for looping visuals
99+
var loopArrow = CreateNote(type, note, beat, 1); //Create a dummy arrow for looping visuals
100100
if (colorOverride != default)
101101
{
102102
newNote.SelfModulate = colorOverride;
@@ -106,15 +106,17 @@ public NoteArrow AddArrowToLane(
106106
return newNote;
107107
}
108108

109-
private NoteArrow CreateNote(ArrowType arrow, Note note, int beat = 0)
109+
private NoteArrow CreateNote(ArrowType arrow, Note note, int beat = 0, int loopOffset = 0)
110110
{
111111
var noteScene = ResourceLoader.Load<PackedScene>("res://scenes/NoteManager/note.tscn");
112112
NoteArrow newArrow = noteScene.Instantiate<NoteArrow>();
113113
newArrow.Init(IH.Arrows[(int)arrow], beat, note);
114114
newArrow.OutlineSprite.Modulate = IH.Arrows[(int)arrow].Color;
115115

116116
_arrowGroup.AddChild(newArrow);
117-
newArrow.Bounds = (float)(beat / TrueBeatsPerLoop * (ChartLength / 2));
117+
newArrow.Bounds = (float)(
118+
beat / TrueBeatsPerLoop * (ChartLength / 2) + loopOffset * (ChartLength / 2)
119+
);
118120
newArrow.Position += Vector2.Right * newArrow.Bounds * 10; //temporary fix for notes spawning and instantly calling loop from originating at 0,0
119121
return newArrow;
120122
}

scenes/NoteManager/scripts/InputHandler.cs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -81,43 +81,32 @@ public void FeedbackEffect(ArrowType arrow, string text)
8181
public override void _Ready()
8282
{
8383
InitializeArrowCheckers();
84-
LoadControlScheme();
8584
}
8685

87-
private void LoadControlScheme()
86+
public override void _UnhandledInput(InputEvent @event)
8887
{
89-
string scheme = SaveSystem.GetConfigValue(SaveSystem.ConfigSettings.InputKey).As<string>();
90-
foreach (var arrow in Arrows)
91-
{
92-
var events = InputMap.ActionGetEvents(arrow.Key);
93-
foreach (var inputEvent in events)
94-
{
95-
InputMap.ActionEraseEvent(arrow.Key, inputEvent);
96-
}
97-
}
98-
99-
var selectedScheme = ControlSchemes.Schemes[scheme];
100-
foreach (var arrow in Arrows)
88+
if (@event is InputEventJoypadButton)
10189
{
102-
if (selectedScheme.ContainsKey(arrow.Key))
103-
{
104-
InputEventKey eventKey = new InputEventKey();
105-
eventKey.Keycode = (Key)Enum.Parse(typeof(Key), selectedScheme[arrow.Key]);
106-
InputMap.ActionAddEvent(arrow.Key, eventKey);
107-
}
90+
SaveSystem.UpdateConfig(SaveSystem.ConfigSettings.InputKey, "CONTROLLER");
10891
}
10992
}
11093

11194
public override void _Process(double delta)
11295
{
96+
string scheme = SaveSystem.GetConfigValue(SaveSystem.ConfigSettings.InputKey).As<string>();
97+
if (Input.GetConnectedJoypads().Count <= 0 && scheme == "CONTROLLER")
98+
{
99+
SaveSystem.UpdateConfig(SaveSystem.ConfigSettings.InputKey, "ARROWS");
100+
}
101+
113102
foreach (var arrow in Arrows)
114103
{
115-
if (Input.IsActionJustPressed(arrow.Key))
104+
if (Input.IsActionJustPressed(scheme + "_" + arrow.Key))
116105
{
117106
EmitSignal(nameof(NotePressed), (int)arrow.Type);
118107
arrow.Node.SetPressed(true);
119108
}
120-
else if (Input.IsActionJustReleased(arrow.Key))
109+
else if (Input.IsActionJustReleased(scheme + "_" + arrow.Key))
121110
{
122111
EmitSignal(nameof(NoteReleased), (int)arrow.Type);
123112
arrow.Node.SetPressed(false);

scenes/Options/OptionsMenu.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public override void _Ready()
4848

4949
public override void _Input(InputEvent @event)
5050
{
51-
if (@event.IsActionPressed("Pause"))
51+
if (@event.IsActionPressed("ui_cancel"))
5252
{
5353
CloseMenu();
5454
GetViewport().SetInputAsHandled();

0 commit comments

Comments
 (0)