using Godot; using Mr.BrickAdventures.Autoloads; namespace Mr.BrickAdventures.scripts.UI; public partial class InputSettings : Control { [Export] public VBoxContainer ActionsContainer { get; set; } [Export] public Button ResetButton { get; set; } [Export] public Control InputSettingsControl { get; set; } [Export] public PackedScene InputButtonScene { get; set; } private static readonly string[] RemappableActions = ["left", "right", "jump", "attack", "pause", "show_marketplace"]; private UIManager UIManager => UIManager.Instance; private ConfigFileHandler ConfigFileHandler => ConfigFileHandler.Instance; private string _rebindingAction; private Button _rebindingButton; private Label _rebindingLabel; public override void _Ready() { PopulateActions(); ResetButton.FocusMode = FocusModeEnum.All; ResetButton.Pressed += OnResetPressed; if (InputDeviceManager.Instance != null) InputDeviceManager.Instance.DeviceChanged += OnDeviceChanged; InputSettingsControl.VisibilityChanged += OnVisibilityChanged; } public override void _ExitTree() { if (InputDeviceManager.Instance != null) InputDeviceManager.Instance.DeviceChanged -= OnDeviceChanged; InputSettingsControl.VisibilityChanged -= OnVisibilityChanged; } public override void _UnhandledInput(InputEvent @event) { if (_rebindingAction != null) { if (@event is InputEventKey keyEvent && keyEvent.Pressed && !keyEvent.Echo) { GetViewport().SetInputAsHandled(); TryBind(_rebindingAction, _rebindingButton, _rebindingLabel, keyEvent); } else if (@event.IsActionReleased("ui_cancel")) { GetViewport().SetInputAsHandled(); CancelRebind(); } return; } if (!@event.IsActionReleased("ui_cancel")) return; if (!UIManager.IsScreenOnTop(InputSettingsControl)) return; UIManager.PopScreen(); } private void PopulateActions() { foreach (Node child in ActionsContainer.GetChildren()) child.QueueFree(); bool first = true; foreach (var action in RemappableActions) { var row = InputButtonScene.Instantiate