1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-25 01:39:23 +01:00

fixed a ui system crash when there is no active root

This commit is contained in:
Ellpeck 2019-09-17 19:30:54 +02:00
parent b699333434
commit 76bba86b0c

View file

@ -17,7 +17,7 @@ namespace MLEM.Ui {
public RootElement ActiveRoot { get; private set; }
public Element MousedElement { get; private set; }
public Element SelectedElement => this.ActiveRoot.SelectedElement;
public Element SelectedElement => this.ActiveRoot?.SelectedElement;
public Buttons[] GamepadButtons = {Buttons.A};
public Buttons[] SecondaryGamepadButtons = {Buttons.X};
@ -58,7 +58,7 @@ namespace MLEM.Ui {
if (this.Input.IsMouseButtonPressed(MouseButton.Left)) {
this.IsAutoNavMode = false;
var selectedNow = mousedNow != null && mousedNow.CanBeSelected ? mousedNow : null;
this.ActiveRoot.SelectElement(selectedNow);
this.ActiveRoot?.SelectElement(selectedNow);
if (mousedNow != null)
this.System.OnElementPressed?.Invoke(mousedNow);
} else if (this.Input.IsMouseButtonPressed(MouseButton.Right)) {
@ -86,20 +86,20 @@ namespace MLEM.Ui {
var next = this.GetTabNextElement(backward);
if (this.SelectedElement?.Root != null)
next = this.SelectedElement.GetTabNextElement(backward, next);
this.ActiveRoot.SelectElement(next);
this.ActiveRoot?.SelectElement(next);
}
// TOUCH INPUT
else if (this.Input.GetGesture(GestureType.Tap, out var tap)) {
this.IsAutoNavMode = false;
var tapped = this.GetElementUnderPos(tap.Position.ToPoint());
this.ActiveRoot.SelectElement(tapped);
this.ActiveRoot?.SelectElement(tapped);
if (tapped != null)
this.System.OnElementPressed?.Invoke(tapped);
} else if (this.Input.GetGesture(GestureType.Hold, out var hold)) {
this.IsAutoNavMode = false;
var held = this.GetElementUnderPos(hold.Position.ToPoint());
this.ActiveRoot.SelectElement(held);
this.ActiveRoot?.SelectElement(held);
if (held != null)
this.System.OnElementSecondaryPressed?.Invoke(held);
}