Button remapping work
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
using Chickensoft.AutoInject;
|
||||
using Chickensoft.Introspection;
|
||||
using Chickensoft.Serialization;
|
||||
using Godot;
|
||||
using NathanHoad;
|
||||
using System.Linq;
|
||||
|
||||
namespace Zennysoft.Game.Ma;
|
||||
|
||||
@@ -15,7 +16,12 @@ public partial class OptionsMenu : Control
|
||||
[Node] public HSlider MasterVolumeSlider { get; set; }
|
||||
[Node] public HSlider MusicVolumeSlider { get; set; }
|
||||
[Node] public HSlider SFXVolumeSlider { get; set; }
|
||||
[Node] public Button SaveAndExitButton { get; set; }
|
||||
|
||||
[Node] public InputMapper Controller { get; set; }
|
||||
[Node] public TabContainer TabContainer { get; set; }
|
||||
[Node] public Label PressToGoBackLabel { get; set; }
|
||||
|
||||
[Node] public CanvasLayer CanvasLayer { get; set; }
|
||||
|
||||
public OptionsData OptionsData;
|
||||
|
||||
@@ -48,11 +54,65 @@ public partial class OptionsMenu : Control
|
||||
|
||||
ResolutionOptions.ItemSelected += ResolutionOptions_ItemSelected;
|
||||
|
||||
SaveAndExitButton.ButtonUp += SaveAndExitButton_ButtonUp;
|
||||
TabContainer.TabChanged += TabContainer_TabChanged;
|
||||
|
||||
_masterBusIndex = AudioServer.GetBusIndex("Master");
|
||||
_musicBusIndex = AudioServer.GetBusIndex("MUSIC");
|
||||
_sfxBusIndex = AudioServer.GetBusIndex("SFX");
|
||||
|
||||
VisibilityChanged += OptionsMenu_VisibilityChanged;
|
||||
|
||||
InputHelper.JoypadInputChanged += (string action, InputEvent input) =>
|
||||
{
|
||||
if (GameInputs.Interact == action)
|
||||
{
|
||||
var interactInputs = InputHelper.GetLabelForInput(InputHelper.GetJoypadInputForAction(GameInputs.Interact));
|
||||
PressToGoBackLabel.Text = $"Press {interactInputs} to save and exit.";
|
||||
}
|
||||
};
|
||||
|
||||
InputHelper.KeyboardInputChanged += (string action, InputEvent input) =>
|
||||
{
|
||||
if (GameInputs.Interact == action)
|
||||
{
|
||||
var interactInputs = InputHelper.GetLabelForInput(InputHelper.GetKeyboardInputForAction(GameInputs.Interact));
|
||||
PressToGoBackLabel.Text = $"Press {interactInputs} to save and exit.";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void TabContainer_TabChanged(long tab)
|
||||
{
|
||||
if (tab == 0)
|
||||
MasterVolumeSlider.GrabFocus();
|
||||
if (tab == 1)
|
||||
Controller.MoveForwardKeyboard.GrabFocus();
|
||||
}
|
||||
|
||||
private void OptionsMenu_VisibilityChanged() => CanvasLayer.Visible = !CanvasLayer.Visible;
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
var interactInputs = InputHelper.GetKeyboardOrJoypadInputsForAction(GameInputs.Interact);
|
||||
if (interactInputs.Any(x => x.IsMatch(@event)))
|
||||
{
|
||||
AcceptEvent();
|
||||
SaveAndExitMenu();
|
||||
}
|
||||
|
||||
var leftTab = InputHelper.GetKeyboardOrJoypadInputsForAction(GameInputs.StrafeLeft);
|
||||
if (leftTab.Any(x => x.IsMatch(@event)))
|
||||
{
|
||||
AcceptEvent();
|
||||
TabContainer.CurrentTab = Mathf.Max(0, TabContainer.CurrentTab - 1);
|
||||
}
|
||||
|
||||
var rightTab = InputHelper.GetKeyboardOrJoypadInputsForAction(GameInputs.StrafeRight);
|
||||
if (rightTab.Any(x => x.IsMatch(@event)))
|
||||
{
|
||||
AcceptEvent();
|
||||
TabContainer.CurrentTab = Mathf.Min(TabContainer.GetTabCount() - 1, TabContainer.CurrentTab + 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void ResolutionOptions_ItemSelected(long index)
|
||||
@@ -71,7 +131,7 @@ public partial class OptionsMenu : Control
|
||||
DisplayServer.WindowSetMode(_windowModes[optionsData.ScreenResolution]);
|
||||
}
|
||||
|
||||
private void SaveAndExitButton_ButtonUp() => EmitSignal(SignalName.OptionsMenuExited);
|
||||
private void SaveAndExitMenu() => EmitSignal(SignalName.OptionsMenuExited);
|
||||
|
||||
private void MasterVolumeSlider_Changed(double valueChanged)
|
||||
{
|
||||
@@ -90,20 +150,4 @@ public partial class OptionsMenu : Control
|
||||
OptionsData.SFXVolumeLevel = valueChanged;
|
||||
AudioServer.SetBusVolumeDb(_sfxBusIndex, Mathf.LinearToDb((float)valueChanged));
|
||||
}
|
||||
}
|
||||
|
||||
[Meta, Id("options_data")]
|
||||
public partial class OptionsData : Node
|
||||
{
|
||||
[Save("MasterVolume")]
|
||||
public required double MasterVolumeLevel { get; set; }
|
||||
|
||||
[Save("MusicVolume")]
|
||||
public required double MusicVolumeLevel { get; set; }
|
||||
|
||||
[Save("SFXVolume")]
|
||||
public required double SFXVolumeLevel { get; set; }
|
||||
|
||||
[Save("ScreenResolution")]
|
||||
public required int ScreenResolution { get; set; }
|
||||
}
|
||||
Reference in New Issue
Block a user