From 289e0e859789b8d78fc6b9874167fa8ff34b093f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 30 May 2021 17:57:39 +0200 Subject: [PATCH] added a simple way to change the action that is executed when a link is pressed inside a paragraph --- MLEM.Ui/Elements/Paragraph.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/MLEM.Ui/Elements/Paragraph.cs b/MLEM.Ui/Elements/Paragraph.cs index 479fcd0..e6adf4d 100644 --- a/MLEM.Ui/Elements/Paragraph.cs +++ b/MLEM.Ui/Elements/Paragraph.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -78,6 +79,11 @@ namespace MLEM.Ui.Elements { /// Use this event for setting this paragraph's text if it changes frequently. /// public TextCallback GetTextCallback; + /// + /// The action that is executed if objects inside of this paragraph are pressed. + /// By default, is executed. + /// + public Action LinkAction; /// /// Creates a new paragraph with the given settings. @@ -194,8 +200,13 @@ namespace MLEM.Ui.Elements { this.Token = token; this.textScale = textScale; this.OnPressed += e => { - foreach (var code in token.AppliedCodes.OfType()) - MlemPlatform.Current.OpenLinkOrFile(code.Match.Groups[1].Value); + foreach (var code in token.AppliedCodes.OfType()) { + if (this.Parent is Paragraph p && p.LinkAction != null) { + p.LinkAction.Invoke(this, code); + } else { + MlemPlatform.Current.OpenLinkOrFile(code.Match.Groups[1].Value); + } + } }; }