From 4943a7b6f091a47241149cafc883e5237bec0bc6 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 9 Aug 2019 19:39:51 +0200 Subject: [PATCH] hiding elements --- MLEM.Ui/Elements/Element.cs | 13 +++++++++---- MLEM.Ui/UiSystem.cs | 12 ++++++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index e74d17f..eb89f39 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -50,6 +50,7 @@ namespace MLEM.Ui.Elements { public UiSystem System { get; private set; } public Element Parent { get; private set; } + public bool IsHidden; private readonly List children = new List(); private Rectangle area; @@ -221,13 +222,17 @@ namespace MLEM.Ui.Elements { } public virtual void Draw(GameTime time, SpriteBatch batch, Color color) { - foreach (var child in this.children) - child.Draw(time, batch, color); + foreach (var child in this.children) { + if (!child.IsHidden) + child.Draw(time, batch, color); + } } public virtual void DrawUnbound(GameTime time, SpriteBatch batch, Color color, BlendState blendState = null, SamplerState samplerState = null) { - foreach (var child in this.children) - child.DrawUnbound(time, batch, color, blendState, samplerState); + foreach (var child in this.children) { + if (!child.IsHidden) + child.DrawUnbound(time, batch, color, blendState, samplerState); + } } public void SetUiSystem(UiSystem system) { diff --git a/MLEM.Ui/UiSystem.cs b/MLEM.Ui/UiSystem.cs index 1294a0b..d2104fa 100644 --- a/MLEM.Ui/UiSystem.cs +++ b/MLEM.Ui/UiSystem.cs @@ -41,12 +41,16 @@ namespace MLEM.Ui { var col = color ?? Color.White; batch.Begin(SpriteSortMode.Deferred, blendState, samplerState, transformMatrix: Matrix.CreateScale(this.GlobalScale)); - foreach (var root in this.rootElements) - root.Element.Draw(time, batch, col); + foreach (var root in this.rootElements) { + if (!root.Element.IsHidden) + root.Element.Draw(time, batch, col); + } batch.End(); - foreach (var root in this.rootElements) - root.Element.DrawUnbound(time, batch, col, blendState, samplerState); + foreach (var root in this.rootElements) { + if (!root.Element.IsHidden) + root.Element.DrawUnbound(time, batch, col, blendState, samplerState); + } } public void Add(string name, Element root) {