fix: InputSettings PhysicalKeycode, visibility guard, dead code, delegate save

This commit is contained in:
2026-03-19 03:42:47 +01:00
parent dc46769c11
commit 9043cfa63c

View File

@@ -10,6 +10,7 @@ public partial class InputSettings : Control
[Export] public Control InputSettingsControl { get; set; } [Export] public Control InputSettingsControl { get; set; }
[Export] public PackedScene InputButtonScene { get; set; } [Export] public PackedScene InputButtonScene { get; set; }
// When adding new game actions, update this list to make them remappable in settings.
private static readonly string[] RemappableActions = private static readonly string[] RemappableActions =
["left", "right", "jump", "attack", "pause", "show_marketplace"]; ["left", "right", "jump", "attack", "pause", "show_marketplace"];
@@ -40,6 +41,8 @@ public partial class InputSettings : Control
public override void _UnhandledInput(InputEvent @event) public override void _UnhandledInput(InputEvent @event)
{ {
if (!IsVisibleInTree()) return;
if (_rebindingAction != null) if (_rebindingAction != null)
{ {
if (@event is InputEventKey keyEvent && keyEvent.Pressed && !keyEvent.Echo) if (@event is InputEventKey keyEvent && keyEvent.Pressed && !keyEvent.Echo)
@@ -65,7 +68,6 @@ public partial class InputSettings : Control
foreach (Node child in ActionsContainer.GetChildren()) foreach (Node child in ActionsContainer.GetChildren())
child.QueueFree(); child.QueueFree();
bool first = true;
foreach (var action in RemappableActions) foreach (var action in RemappableActions)
{ {
var row = InputButtonScene.Instantiate<Button>(); var row = InputButtonScene.Instantiate<Button>();
@@ -83,11 +85,6 @@ public partial class InputSettings : Control
var capturedLabel = labelInput; var capturedLabel = labelInput;
var capturedRow = row; var capturedRow = row;
row.Pressed += () => OnRowPressed(capturedAction, capturedRow, capturedLabel); row.Pressed += () => OnRowPressed(capturedAction, capturedRow, capturedLabel);
if (first)
{
first = false;
}
} }
} }
@@ -104,7 +101,7 @@ public partial class InputSettings : Control
private void TryBind(string action, Button row, Label labelInput, InputEventKey keyEvent) private void TryBind(string action, Button row, Label labelInput, InputEventKey keyEvent)
{ {
var newKey = keyEvent.Keycode != Key.None ? keyEvent.Keycode : keyEvent.PhysicalKeycode; var newKey = keyEvent.PhysicalKeycode;
// Conflict check // Conflict check
foreach (var other in RemappableActions) foreach (var other in RemappableActions)
@@ -134,11 +131,10 @@ public partial class InputSettings : Control
if (ev is InputEventKey) if (ev is InputEventKey)
InputMap.ActionEraseEvent(action, ev); InputMap.ActionEraseEvent(action, ev);
} }
InputMap.ActionAddEvent(action, keyEvent); InputMap.ActionAddEvent(action, new InputEventKey { PhysicalKeycode = keyEvent.PhysicalKeycode });
// Persist // Persist
ConfigFileHandler.SettingsConfig.SetValue("input_settings", action, (long)newKey); SettingsManager.Instance.SaveInputSettings();
ConfigFileHandler.SettingsConfig.Save(ConfigFileHandler.SettingsPath);
labelInput.Text = OS.GetKeycodeString(newKey); labelInput.Text = OS.GetKeycodeString(newKey);
@@ -189,7 +185,7 @@ public partial class InputSettings : Control
foreach (var ev in InputMap.ActionGetEvents(action)) foreach (var ev in InputMap.ActionGetEvents(action))
{ {
if (ev is InputEventKey key) if (ev is InputEventKey key)
return key.Keycode != Key.None ? key.Keycode : key.PhysicalKeycode; return key.PhysicalKeycode;
} }
return Key.None; return Key.None;
} }