Skip to content

Commit 40ca647

Browse files
cornerloanLifeHckr
andauthored
Custom remapping (#159)
* user can remap controls using custom keys issues being worked on still: - UI is not attempting to look clean or good yet - only one implementation, need to separate keyboard and controller into different tabs - need to ensure no duplicate keys for mapped inputs - remapping a key to the "accept" button causes the remapping popup to immediately reopen * controller remapping added, anti-dupes maybe works? I think the anti-duplicates works, but can use another set of eyes on it during our meeting on thursday. Believed issue: I think that InputMap isn't properly updating when being ran through the editor. WASDE are always invalid notes to change to. * no more duplicate controls -still not pretty looking -still can move around UI while inputting the new key selection * remap popup disables UI movement * everything works - needs an appearance revamp - should maybe allow user to remap inventory and pause key, since we disallow people to rebind to those keys * updated to include inventory, merged milestone1 * appearance revamp - ui cannot be maneuvered left and right in the tabs * Updated translations - still need to fix UI movement controls * we hate spaghetti - still can't figure out the UI maneuverability issue * Add translations Also adjusted control spacing to accommodate Chinese * Refactored control settings Fix neighbors in controls remapping Made ui_cancel end the input screen Simplified dictionaries and awkward reused strings Added documentation Standardized node names * Beautify controls screen Should def make custom tabs sooner than later. --------- Co-authored-by: LifeHckr <jarodthereal@gmail.com>
1 parent f4cf6b8 commit 40ca647

File tree

193 files changed

+3712
-341
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+3712
-341
lines changed

Globals/SaveSystem.cs

Lines changed: 237 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Linq;
23
using System.Text.Json;
34
using Godot;
@@ -13,14 +14,38 @@ public static class SaveSystem
1314
private static ConfigFile _curConfigData;
1415

1516
private const float DefaultVolume = 1f;
16-
private const string DefaultInput = "WASD";
17+
private const string DefaultInputType = "WASD";
18+
private const int DefaultInputKeyboardUp = 87; //W
19+
private const int DefaultInputKeyboardLeft = 65; //A
20+
private const int DefaultInputKeyboardDown = 83; //S
21+
private const int DefaultInputKeyboardRight = 68; //D
22+
private const int DefaultInputKeyboardSecondary = 4194325; //Shift
23+
private const int DefaultInputKeyboardInventory = 73; //I
24+
private const int DefaultInputControllerUp = 3; //Y
25+
private const int DefaultInputControllerLeft = 2; //X
26+
private const int DefaultInputControllerDown = 0; //A
27+
private const int DefaultInputControllerRight = 1; //B
28+
private const int DefaultInputControllerSecondary = 10; //right bumper
29+
private const int DefaultInputControllerInventory = 4; //back button
1730
private const string DefaultLanguage = "en";
1831
private const bool DefaultHighCon = false;
1932

2033
public enum ConfigSettings
2134
{
2235
Volume,
23-
InputKey,
36+
InputType,
37+
InputKeyboardUp,
38+
InputKeyboardLeft,
39+
InputKeyboardDown,
40+
InputKeyboardRight,
41+
InputKeyboardSecondary,
42+
InputKeyboardInventory,
43+
InputControllerUp,
44+
InputControllerLeft,
45+
InputControllerDown,
46+
InputControllerRight,
47+
InputControllerSecondary,
48+
InputControllerInventory,
2449
LanguageKey,
2550
HighContrast,
2651
}
@@ -32,7 +57,19 @@ private static void InitConfig()
3257
{
3358
_curConfigData = new ConfigFile();
3459
UpdateConfig(ConfigSettings.Volume, DefaultVolume);
35-
UpdateConfig(ConfigSettings.InputKey, DefaultInput);
60+
UpdateConfig(ConfigSettings.InputType, DefaultInputType);
61+
UpdateConfig(ConfigSettings.InputKeyboardUp, DefaultInputKeyboardUp);
62+
UpdateConfig(ConfigSettings.InputKeyboardLeft, DefaultInputKeyboardLeft);
63+
UpdateConfig(ConfigSettings.InputKeyboardDown, DefaultInputKeyboardDown);
64+
UpdateConfig(ConfigSettings.InputKeyboardRight, DefaultInputKeyboardRight);
65+
UpdateConfig(ConfigSettings.InputKeyboardSecondary, DefaultInputKeyboardSecondary);
66+
UpdateConfig(ConfigSettings.InputKeyboardInventory, DefaultInputKeyboardInventory);
67+
UpdateConfig(ConfigSettings.InputControllerUp, DefaultInputControllerUp);
68+
UpdateConfig(ConfigSettings.InputControllerLeft, DefaultInputControllerLeft);
69+
UpdateConfig(ConfigSettings.InputControllerDown, DefaultInputControllerDown);
70+
UpdateConfig(ConfigSettings.InputControllerRight, DefaultInputControllerRight);
71+
UpdateConfig(ConfigSettings.InputControllerSecondary, DefaultInputControllerSecondary);
72+
UpdateConfig(ConfigSettings.InputControllerInventory, DefaultInputControllerInventory);
3673
UpdateConfig(ConfigSettings.LanguageKey, DefaultLanguage);
3774
UpdateConfig(ConfigSettings.HighContrast, DefaultHighCon);
3875
}
@@ -51,9 +88,45 @@ public static void UpdateConfig(ConfigSettings setting, Variant value)
5188
case ConfigSettings.Volume:
5289
_curConfigData.SetValue("Options", "Volume", value);
5390
break;
54-
case ConfigSettings.InputKey:
91+
case ConfigSettings.InputType:
5592
_curConfigData.SetValue("Options", "InputKey", value);
5693
break;
94+
case ConfigSettings.InputKeyboardUp:
95+
_curConfigData.SetValue("Options", "InputKeyboardUp", value);
96+
break;
97+
case ConfigSettings.InputKeyboardLeft:
98+
_curConfigData.SetValue("Options", "InputKeyboardLeft", value);
99+
break;
100+
case ConfigSettings.InputKeyboardDown:
101+
_curConfigData.SetValue("Options", "InputKeyboardDown", value);
102+
break;
103+
case ConfigSettings.InputKeyboardRight:
104+
_curConfigData.SetValue("Options", "InputKeyboardRight", value);
105+
break;
106+
case ConfigSettings.InputKeyboardSecondary:
107+
_curConfigData.SetValue("Options", "InputKeyboardSecondary", value);
108+
break;
109+
case ConfigSettings.InputKeyboardInventory:
110+
_curConfigData.SetValue("Options", "InputKeyboardInventory", value);
111+
break;
112+
case ConfigSettings.InputControllerUp:
113+
_curConfigData.SetValue("Options", "InputControllerUp", value);
114+
break;
115+
case ConfigSettings.InputControllerLeft:
116+
_curConfigData.SetValue("Options", "InputControllerLeft", value);
117+
break;
118+
case ConfigSettings.InputControllerDown:
119+
_curConfigData.SetValue("Options", "InputControllerDown", value);
120+
break;
121+
case ConfigSettings.InputControllerRight:
122+
_curConfigData.SetValue("Options", "InputControllerRight", value);
123+
break;
124+
case ConfigSettings.InputControllerSecondary:
125+
_curConfigData.SetValue("Options", "InputControllerSecondary", value);
126+
break;
127+
case ConfigSettings.InputControllerInventory:
128+
_curConfigData.SetValue("Options", "InputControllerInventory", value);
129+
break;
57130
case ConfigSettings.LanguageKey:
58131
_curConfigData.SetValue("Options", "LanguageKey", value);
59132
break;
@@ -74,6 +147,7 @@ private static void AssertConfigFile()
74147
if (_curConfigData == null)
75148
{
76149
LoadConfigData();
150+
ApplySavedInputBindings();
77151
}
78152
}
79153

@@ -118,8 +192,80 @@ public static Variant GetConfigValue(ConfigSettings setting)
118192
{
119193
case ConfigSettings.Volume:
120194
return _curConfigData.GetValue("Options", "Volume", DefaultVolume);
121-
case ConfigSettings.InputKey:
122-
return _curConfigData.GetValue("Options", "InputKey", DefaultInput);
195+
case ConfigSettings.InputType:
196+
return _curConfigData.GetValue("Options", "InputKey", DefaultInputType);
197+
case ConfigSettings.InputKeyboardUp:
198+
return _curConfigData.GetValue(
199+
"Options",
200+
"InputKeyboardUp",
201+
DefaultInputKeyboardUp
202+
);
203+
case ConfigSettings.InputKeyboardLeft:
204+
return _curConfigData.GetValue(
205+
"Options",
206+
"InputKeyboardLeft",
207+
DefaultInputKeyboardLeft
208+
);
209+
case ConfigSettings.InputKeyboardDown:
210+
return _curConfigData.GetValue(
211+
"Options",
212+
"InputKeyboardDown",
213+
DefaultInputKeyboardDown
214+
);
215+
case ConfigSettings.InputKeyboardRight:
216+
return _curConfigData.GetValue(
217+
"Options",
218+
"InputKeyboardRight",
219+
DefaultInputKeyboardRight
220+
);
221+
case ConfigSettings.InputKeyboardSecondary:
222+
return _curConfigData.GetValue(
223+
"Options",
224+
"InputKeyboardSecondary",
225+
DefaultInputKeyboardSecondary
226+
);
227+
case ConfigSettings.InputKeyboardInventory:
228+
return _curConfigData.GetValue(
229+
"Options",
230+
"InputKeyboardInventory",
231+
DefaultInputKeyboardInventory
232+
);
233+
case ConfigSettings.InputControllerUp:
234+
return _curConfigData.GetValue(
235+
"Options",
236+
"InputControllerUp",
237+
DefaultInputControllerUp
238+
);
239+
case ConfigSettings.InputControllerLeft:
240+
return _curConfigData.GetValue(
241+
"Options",
242+
"InputControllerLeft",
243+
DefaultInputControllerLeft
244+
);
245+
case ConfigSettings.InputControllerDown:
246+
return _curConfigData.GetValue(
247+
"Options",
248+
"InputControllerDown",
249+
DefaultInputControllerDown
250+
);
251+
case ConfigSettings.InputControllerRight:
252+
return _curConfigData.GetValue(
253+
"Options",
254+
"InputControllerRight",
255+
DefaultInputControllerRight
256+
);
257+
case ConfigSettings.InputControllerSecondary:
258+
return _curConfigData.GetValue(
259+
"Options",
260+
"InputControllerSecondary",
261+
DefaultInputControllerSecondary
262+
);
263+
case ConfigSettings.InputControllerInventory:
264+
return _curConfigData.GetValue(
265+
"Options",
266+
"InputControllerInventory",
267+
DefaultInputControllerInventory
268+
);
123269
case ConfigSettings.LanguageKey:
124270
return _curConfigData.GetValue("Options", "LanguageKey", DefaultLanguage);
125271
case ConfigSettings.HighContrast:
@@ -212,5 +358,90 @@ public static void ClearSave()
212358
DirAccess.RemoveAbsolute(UserSavePath);
213359
}
214360

361+
public static void ApplySavedInputBindings()
362+
{
363+
InputMap.ActionEraseEvents("WASD_arrowUp");
364+
InputMap.ActionEraseEvents("WASD_arrowDown");
365+
InputMap.ActionEraseEvents("WASD_arrowRight");
366+
InputMap.ActionEraseEvents("WASD_arrowLeft");
367+
InputMap.ActionEraseEvents("WASD_secondaryPlacement");
368+
InputMap.ActionEraseEvents("WASD_inventory");
369+
InputMap.ActionEraseEvents("CONTROLLER_arrowUp");
370+
InputMap.ActionEraseEvents("CONTROLLER_arrowDown");
371+
InputMap.ActionEraseEvents("CONTROLLER_arrowLeft");
372+
InputMap.ActionEraseEvents("CONTROLLER_arrowRight");
373+
InputMap.ActionEraseEvents("CONTROLLER_secondaryPlacement");
374+
InputMap.ActionEraseEvents("CONTROLLER_inventory");
375+
376+
// Keyboard bindings
377+
AddKeyBinding("WASD_arrowUp", GetConfigValue(ConfigSettings.InputKeyboardUp).ToString());
378+
AddKeyBinding(
379+
"WASD_arrowDown",
380+
GetConfigValue(ConfigSettings.InputKeyboardDown).ToString()
381+
);
382+
AddKeyBinding(
383+
"WASD_arrowLeft",
384+
GetConfigValue(ConfigSettings.InputKeyboardLeft).ToString()
385+
);
386+
AddKeyBinding(
387+
"WASD_arrowRight",
388+
GetConfigValue(ConfigSettings.InputKeyboardRight).ToString()
389+
);
390+
AddKeyBinding(
391+
"WASD_secondaryPlacement",
392+
GetConfigValue(ConfigSettings.InputKeyboardSecondary).ToString()
393+
);
394+
AddKeyBinding(
395+
"WASD_inventory",
396+
GetConfigValue(ConfigSettings.InputKeyboardInventory).ToString()
397+
);
398+
399+
// Controller bindings
400+
AddJoypadBinding(
401+
"CONTROLLER_arrowUp",
402+
GetConfigValue(ConfigSettings.InputControllerUp).ToString()
403+
);
404+
AddJoypadBinding(
405+
"CONTROLLER_arrowDown",
406+
GetConfigValue(ConfigSettings.InputControllerDown).ToString()
407+
);
408+
AddJoypadBinding(
409+
"CONTROLLER_arrowLeft",
410+
GetConfigValue(ConfigSettings.InputControllerLeft).ToString()
411+
);
412+
AddJoypadBinding(
413+
"CONTROLLER_arrowRight",
414+
GetConfigValue(ConfigSettings.InputControllerRight).ToString()
415+
);
416+
AddJoypadBinding(
417+
"CONTROLLER_secondaryPlacement",
418+
GetConfigValue(ConfigSettings.InputControllerSecondary).ToString()
419+
);
420+
AddJoypadBinding(
421+
"CONTROLLER_inventory",
422+
GetConfigValue(ConfigSettings.InputControllerInventory).ToString()
423+
);
424+
}
425+
426+
private static void AddKeyBinding(string action, string keyString)
427+
{
428+
Key key = (Key)Enum.Parse(typeof(Key), keyString, ignoreCase: true);
429+
InputEventKey inputEvent = new InputEventKey { PhysicalKeycode = key };
430+
InputMap.ActionAddEvent(action, inputEvent);
431+
}
432+
433+
private static void AddJoypadBinding(string action, string buttonString)
434+
{
435+
if (Enum.TryParse<JoyButton>(buttonString, true, out JoyButton button))
436+
{
437+
InputEventJoypadButton inputEvent = new InputEventJoypadButton { ButtonIndex = button };
438+
InputMap.ActionAddEvent(action, inputEvent);
439+
}
440+
else
441+
{
442+
GD.PushWarning($"Could not parse joypad button: {buttonString}");
443+
}
444+
}
445+
215446
#endregion
216447
}

Globals/Translations/Translations.csv

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ 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,控制杆
13+
CONTROLS_CONTROLLER,Controller,控制杆
14+
CONTROLS_KEYBOARD,Keyboard,键盘
1415
CONTROLS_QWER_BUTTON,QWER,QWER
1516
CONTROLS_ARROW_BUTTON,Arrow Keys,箭头键
1617
CONTROLS_RETURN_BUTTON,Return,返回
18+
CONTROLS_CHOOSE_SCHEME,Choose Control Scheme,选择控制方式
19+
CONTROLS_CHOOSE_BUTTON,Choose new button,选择输入按钮
1720
ESCAPE_MENU_RESUME,Resume,继续
1821
ESCAPE_MENU_QUIT,Quit,退出
1922
ESCAPE_MENU_TITLE,Quit to Title,返回标题

Scenes/BattleDirector/Scripts/NotePlacementBar.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,10 @@ public Note NotePlaced()
209209
{
210210
if (!CanPlaceNote())
211211
GD.PushWarning("Note is attempting placement without a full bar!");
212-
Note placedNote = GetNote(Input.IsActionPressed("Secondary"));
212+
string inputType = SaveSystem
213+
.GetConfigValue(SaveSystem.ConfigSettings.InputType)
214+
.ToString();
215+
Note placedNote = GetNote(Input.IsActionPressed(inputType + "_secondaryPlacement"));
213216
CurrentBarValue -= placedNote.CostModifier * MaxValue;
214217
ClearColors();
215218
return placedNote;

Scenes/NoteManager/Scripts/InputHandler.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ public override void _Ready()
5858
public override void _Process(double delta)
5959
{
6060
//TODO: Add change control scheme signal, so we don't query each frame.
61-
string scheme = SaveSystem.GetConfigValue(SaveSystem.ConfigSettings.InputKey).As<string>();
61+
string scheme = SaveSystem.GetConfigValue(SaveSystem.ConfigSettings.InputType).As<string>();
6262
if (Input.GetConnectedJoypads().Count <= 0 && scheme == "CONTROLLER")
6363
{
64-
SaveSystem.UpdateConfig(SaveSystem.ConfigSettings.InputKey, "ARROWS");
64+
SaveSystem.UpdateConfig(SaveSystem.ConfigSettings.InputType, "WASD");
6565
}
6666

6767
foreach (var arrow in Arrows)
@@ -83,7 +83,7 @@ public override void _UnhandledInput(InputEvent @event)
8383
{
8484
if (@event is InputEventJoypadButton)
8585
{ //Force Controller if controller was pressed
86-
SaveSystem.UpdateConfig(SaveSystem.ConfigSettings.InputKey, "CONTROLLER");
86+
SaveSystem.UpdateConfig(SaveSystem.ConfigSettings.InputType, "CONTROLLER");
8787
}
8888
}
8989

Scenes/UI/Remapping/Assets/0.png

1.77 KB
Loading
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://du6l1dklrpnoc"
6+
path="res://.godot/imported/0.png-540ce6679faede97a0ff081ab0106872.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://Scenes/UI/Remapping/Assets/0.png"
14+
dest_files=["res://.godot/imported/0.png-540ce6679faede97a0ff081ab0106872.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/hdr_compression=1
22+
compress/normal_map=0
23+
compress/channel_pack=0
24+
mipmaps/generate=false
25+
mipmaps/limit=-1
26+
roughness/mode=0
27+
roughness/src_normal=""
28+
process/fix_alpha_border=true
29+
process/premult_alpha=false
30+
process/normal_map_invert_y=false
31+
process/hdr_as_srgb=false
32+
process/hdr_clamp_exposure=false
33+
process/size_limit=0
34+
detect_3d/compress_to=1

Scenes/UI/Remapping/Assets/1.png

1.36 KB
Loading

0 commit comments

Comments
 (0)