1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-26 14:38:34 +01:00

made button inputs more generic to allow for broader usage

This commit is contained in:
Ellpeck 2020-03-17 19:13:33 +01:00
parent f4f7df0eb8
commit 054dc8c932

View file

@ -21,9 +21,9 @@ namespace MLEM.Ui {
private readonly Dictionary<string, Element> selectedElements = new Dictionary<string, Element>(); private readonly Dictionary<string, Element> selectedElements = new Dictionary<string, Element>();
public Element SelectedElement => this.GetSelectedElement(this.ActiveRoot); public Element SelectedElement => this.GetSelectedElement(this.ActiveRoot);
public Buttons[] GamepadButtons = {Buttons.A}; public object[] KeyboardButtons = {Keys.Space, Keys.Enter};
public Buttons[] SecondaryGamepadButtons = {Buttons.X}; public object[] GamepadButtons = {Buttons.A};
public Keys[] KeyboardButtons = {Keys.Space, Keys.Enter}; public object[] SecondaryGamepadButtons = {Buttons.X};
public object[] UpButtons = {Buttons.DPadUp, Buttons.LeftThumbstickUp}; public object[] UpButtons = {Buttons.DPadUp, Buttons.LeftThumbstickUp};
public object[] DownButtons = {Buttons.DPadDown, Buttons.LeftThumbstickDown}; public object[] DownButtons = {Buttons.DPadDown, Buttons.LeftThumbstickDown};
public object[] LeftButtons = {Buttons.DPadLeft, Buttons.LeftThumbstickLeft}; public object[] LeftButtons = {Buttons.DPadLeft, Buttons.LeftThumbstickLeft};
@ -76,7 +76,7 @@ namespace MLEM.Ui {
// KEYBOARD INPUT // KEYBOARD INPUT
if (this.HandleKeyboard) { if (this.HandleKeyboard) {
if (this.KeyboardButtons.Any(this.Input.IsKeyPressed)) { if (this.KeyboardButtons.Any(this.IsAnyPressed)) {
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) { if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) {
if (this.Input.IsModifierKeyDown(ModifierKey.Shift)) { if (this.Input.IsModifierKeyDown(ModifierKey.Shift)) {
// secondary action on element using space or enter // secondary action on element using space or enter
@ -116,19 +116,19 @@ namespace MLEM.Ui {
// GAMEPAD INPUT // GAMEPAD INPUT
if (this.HandleGamepad) { if (this.HandleGamepad) {
if (this.GamepadButtons.Any(b => this.IsGamepadPressed(b))) { if (this.GamepadButtons.Any(this.IsAnyPressed)) {
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed)
this.System.OnElementPressed?.Invoke(this.SelectedElement); this.System.OnElementPressed?.Invoke(this.SelectedElement);
} else if (this.SecondaryGamepadButtons.Any(b => this.IsGamepadPressed(b))) { } else if (this.SecondaryGamepadButtons.Any(this.IsAnyPressed)) {
if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed) if (this.SelectedElement?.Root != null && this.SelectedElement.CanBePressed)
this.System.OnElementSecondaryPressed?.Invoke(this.SelectedElement); this.System.OnElementSecondaryPressed?.Invoke(this.SelectedElement);
} else if (this.DownButtons.Any(this.IsGamepadPressed)) { } else if (this.DownButtons.Any(this.IsAnyPressed)) {
this.HandleGamepadNextElement(Direction2.Down); this.HandleGamepadNextElement(Direction2.Down);
} else if (this.LeftButtons.Any(this.IsGamepadPressed)) { } else if (this.LeftButtons.Any(this.IsAnyPressed)) {
this.HandleGamepadNextElement(Direction2.Left); this.HandleGamepadNextElement(Direction2.Left);
} else if (this.RightButtons.Any(this.IsGamepadPressed)) { } else if (this.RightButtons.Any(this.IsAnyPressed)) {
this.HandleGamepadNextElement(Direction2.Right); this.HandleGamepadNextElement(Direction2.Right);
} else if (this.UpButtons.Any(this.IsGamepadPressed)) { } else if (this.UpButtons.Any(this.IsAnyPressed)) {
this.HandleGamepadNextElement(Direction2.Up); this.HandleGamepadNextElement(Direction2.Up);
} }
} }
@ -220,7 +220,7 @@ namespace MLEM.Ui {
} }
} }
private bool IsGamepadPressed(object button) { private bool IsAnyPressed(object button) {
return this.Input.IsPressed(button, this.GamepadIndex); return this.Input.IsPressed(button, this.GamepadIndex);
} }