From 76bba86b0c6988e293db620ac05d9fbc336d476c Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 17 Sep 2019 19:30:54 +0200 Subject: [PATCH] fixed a ui system crash when there is no active root --- MLEM.Ui/UiControls.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/MLEM.Ui/UiControls.cs b/MLEM.Ui/UiControls.cs index faeb306..110fe5d 100644 --- a/MLEM.Ui/UiControls.cs +++ b/MLEM.Ui/UiControls.cs @@ -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); }