fix: InputSettings PhysicalKeycode, visibility guard, dead code, delegate save
This commit is contained in:
@@ -10,6 +10,7 @@ public partial class InputSettings : Control
|
||||
[Export] public Control InputSettingsControl { 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 =
|
||||
["left", "right", "jump", "attack", "pause", "show_marketplace"];
|
||||
|
||||
@@ -40,6 +41,8 @@ public partial class InputSettings : Control
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (!IsVisibleInTree()) return;
|
||||
|
||||
if (_rebindingAction != null)
|
||||
{
|
||||
if (@event is InputEventKey keyEvent && keyEvent.Pressed && !keyEvent.Echo)
|
||||
@@ -65,7 +68,6 @@ public partial class InputSettings : Control
|
||||
foreach (Node child in ActionsContainer.GetChildren())
|
||||
child.QueueFree();
|
||||
|
||||
bool first = true;
|
||||
foreach (var action in RemappableActions)
|
||||
{
|
||||
var row = InputButtonScene.Instantiate<Button>();
|
||||
@@ -83,11 +85,6 @@ public partial class InputSettings : Control
|
||||
var capturedLabel = labelInput;
|
||||
var capturedRow = row;
|
||||
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)
|
||||
{
|
||||
var newKey = keyEvent.Keycode != Key.None ? keyEvent.Keycode : keyEvent.PhysicalKeycode;
|
||||
var newKey = keyEvent.PhysicalKeycode;
|
||||
|
||||
// Conflict check
|
||||
foreach (var other in RemappableActions)
|
||||
@@ -134,11 +131,10 @@ public partial class InputSettings : Control
|
||||
if (ev is InputEventKey)
|
||||
InputMap.ActionEraseEvent(action, ev);
|
||||
}
|
||||
InputMap.ActionAddEvent(action, keyEvent);
|
||||
InputMap.ActionAddEvent(action, new InputEventKey { PhysicalKeycode = keyEvent.PhysicalKeycode });
|
||||
|
||||
// Persist
|
||||
ConfigFileHandler.SettingsConfig.SetValue("input_settings", action, (long)newKey);
|
||||
ConfigFileHandler.SettingsConfig.Save(ConfigFileHandler.SettingsPath);
|
||||
SettingsManager.Instance.SaveInputSettings();
|
||||
|
||||
labelInput.Text = OS.GetKeycodeString(newKey);
|
||||
|
||||
@@ -189,7 +185,7 @@ public partial class InputSettings : Control
|
||||
foreach (var ev in InputMap.ActionGetEvents(action))
|
||||
{
|
||||
if (ev is InputEventKey key)
|
||||
return key.Keycode != Key.None ? key.Keycode : key.PhysicalKeycode;
|
||||
return key.PhysicalKeycode;
|
||||
}
|
||||
return Key.None;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user