From 0c74dfc38efa3859b8aabbed67b5111e6c61ab66 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 5 Dec 2019 14:59:53 +0100 Subject: [PATCH] allow for ui element removal during its update --- MLEM.Ui/Elements/Element.cs | 3 ++- MLEM.Ui/UiSystem.cs | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index b8d058b..e14157a 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -442,7 +442,8 @@ namespace MLEM.Ui.Elements { this.System.OnElementUpdated?.Invoke(this, time); foreach (var child in this.GetRelevantChildren()) - child.Update(time); + if (child.System != null) + child.Update(time); } public virtual void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) { diff --git a/MLEM.Ui/UiSystem.cs b/MLEM.Ui/UiSystem.cs index c592b90..a69b417 100644 --- a/MLEM.Ui/UiSystem.cs +++ b/MLEM.Ui/UiSystem.cs @@ -98,8 +98,9 @@ namespace MLEM.Ui { public void Update(GameTime time) { this.Controls.Update(); - foreach (var root in this.rootElements) - root.Element.Update(time); + for (var i = this.rootElements.Count - 1; i >= 0; i--) { + this.rootElements[i].Element.Update(time); + } } public void DrawEarly(GameTime time, SpriteBatch batch) {