From b270fe397707dc258e197b63b34be8bd5a53f412 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 27 May 2020 15:19:17 +0200 Subject: [PATCH] made link clusters be selected properly --- MLEM.Ui/Elements/Element.cs | 6 +++--- MLEM.Ui/Elements/Paragraph.cs | 21 ++++++++------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/MLEM.Ui/Elements/Element.cs b/MLEM.Ui/Elements/Element.cs index f41ec84..b3c8c05 100644 --- a/MLEM.Ui/Elements/Element.cs +++ b/MLEM.Ui/Elements/Element.cs @@ -250,11 +250,11 @@ namespace MLEM.Ui.Elements { /// /// Stores whether this element is currently being moused over. /// - public bool IsMouseOver { get; private set; } + public bool IsMouseOver { get; protected set; } /// /// Stores whether this element is its 's . /// - public bool IsSelected { get; private set; } + public bool IsSelected { get; protected set; } /// /// Event that is called after this element is drawn, but before its children are drawn @@ -768,7 +768,7 @@ namespace MLEM.Ui.Elements { /// The transformation matrix that is used for drawing public virtual void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) { this.System.OnElementDrawn?.Invoke(this, time, batch, alpha); - if (this.Controls.SelectedElement == this) + if (this.IsSelected) this.System.OnSelectedElementDrawn?.Invoke(this, time, batch, alpha); foreach (var child in this.GetRelevantChildren()) { diff --git a/MLEM.Ui/Elements/Paragraph.cs b/MLEM.Ui/Elements/Paragraph.cs index 4ad41d3..dd86630 100644 --- a/MLEM.Ui/Elements/Paragraph.cs +++ b/MLEM.Ui/Elements/Paragraph.cs @@ -232,6 +232,14 @@ namespace MLEM.Ui.Elements { public Link(Anchor anchor, Token token, Vector2 size, Link[] linkCluster) : base(anchor, size) { this.Token = token; this.LinkCluster = linkCluster; + this.OnSelected += e => { + foreach (var link in this.LinkCluster) + link.IsSelected = true; + }; + this.OnDeselected += e => { + foreach (var link in this.LinkCluster) + link.IsSelected = false; + }; this.OnPressed += e => { foreach (var code in token.AppliedCodes.OfType()) { try { @@ -243,19 +251,6 @@ namespace MLEM.Ui.Elements { }; } - /// - public override void Draw(GameTime time, SpriteBatch batch, float alpha, BlendState blendState, SamplerState samplerState, Matrix matrix) { - if (this.LinkCluster.Length > 1 && this.Controls.SelectedElement == this) { - // also draw the selection box around all other links in the cluster - foreach (var link in this.LinkCluster) { - if (link == this) - continue; - this.System.OnSelectedElementDrawn?.Invoke(link, time, batch, alpha); - } - } - base.Draw(time, batch, alpha, blendState, samplerState, matrix); - } - } }