1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-26 06:28:35 +01:00

added a way to tell ui controls to ignore certain input types

This commit is contained in:
Ellpeck 2019-12-04 01:17:16 +01:00
parent d224d57cf2
commit f1702ee5b2

View file

@ -27,6 +27,10 @@ namespace MLEM.Ui {
public object[] LeftButtons = {Buttons.DPadLeft, Buttons.LeftThumbstickLeft};
public object[] RightButtons = {Buttons.DPadRight, Buttons.LeftThumbstickRight};
public int GamepadIndex = -1;
public bool HandleMouse = true;
public bool HandleKeyboard = true;
public bool HandleTouch = true;
public bool HandleGamepad = true;
public bool IsAutoNavMode { get; private set; }
@ -45,6 +49,7 @@ namespace MLEM.Ui {
this.ActiveRoot = this.System.GetRootElements().FirstOrDefault(root => root.CanSelectContent);
// MOUSE INPUT
if (this.HandleMouse) {
var mousedNow = this.GetElementUnderPos(this.Input.MousePosition.ToVector2());
if (mousedNow != this.MousedElement) {
if (this.MousedElement != null)
@ -66,9 +71,11 @@ namespace MLEM.Ui {
if (mousedNow != null)
this.System.OnElementSecondaryPressed?.Invoke(mousedNow);
}
}
// KEYBOARD INPUT
else if (this.KeyboardButtons.Any(this.Input.IsKeyPressed)) {
if (this.HandleKeyboard) {
if (this.KeyboardButtons.Any(this.Input.IsKeyPressed)) {
this.IsAutoNavMode = true;
if (this.SelectedElement?.Root != null) {
if (this.Input.IsModifierKeyDown(ModifierKey.Shift)) {
@ -88,9 +95,11 @@ namespace MLEM.Ui {
next = this.SelectedElement.GetTabNextElement(backward, next);
this.ActiveRoot?.SelectElement(next);
}
}
// TOUCH INPUT
else if (this.Input.GetGesture(GestureType.Tap, out var tap)) {
if (this.HandleTouch) {
if (this.Input.GetGesture(GestureType.Tap, out var tap)) {
this.IsAutoNavMode = false;
var tapped = this.GetElementUnderPos(tap.Position);
this.ActiveRoot?.SelectElement(tapped);
@ -103,9 +112,11 @@ namespace MLEM.Ui {
if (held != null)
this.System.OnElementSecondaryPressed?.Invoke(held);
}
}
// GAMEPAD INPUT
else if (this.GamepadButtons.Any(b => this.IsGamepadPressed(b))) {
if (this.HandleGamepad) {
if (this.GamepadButtons.Any(b => this.IsGamepadPressed(b))) {
this.IsAutoNavMode = true;
if (this.SelectedElement?.Root != null)
this.System.OnElementPressed?.Invoke(this.SelectedElement);
@ -123,6 +134,7 @@ namespace MLEM.Ui {
this.HandleGamepadNextElement(Direction2.Up);
}
}
}
public virtual Element GetElementUnderPos(Vector2 position, bool transform = true) {
foreach (var root in this.System.GetRootElements()) {