1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 20:58:34 +01:00

added a simple way to change the action that is executed when a link is pressed inside a paragraph

This commit is contained in:
Ell 2021-05-30 17:57:39 +02:00
parent d146e80cf6
commit 289e0e8597

View file

@ -1,3 +1,4 @@
using System;
using System.Linq; using System.Linq;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics; 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. /// Use this event for setting this paragraph's text if it changes frequently.
/// </summary> /// </summary>
public TextCallback GetTextCallback; public TextCallback GetTextCallback;
/// <summary>
/// The action that is executed if <see cref="Link"/> objects inside of this paragraph are pressed.
/// By default, <see cref="MlemPlatform.OpenLinkOrFile"/> is executed.
/// </summary>
public Action<Link, LinkCode> LinkAction;
/// <summary> /// <summary>
/// Creates a new paragraph with the given settings. /// Creates a new paragraph with the given settings.
@ -194,8 +200,13 @@ namespace MLEM.Ui.Elements {
this.Token = token; this.Token = token;
this.textScale = textScale; this.textScale = textScale;
this.OnPressed += e => { this.OnPressed += e => {
foreach (var code in token.AppliedCodes.OfType<LinkCode>()) foreach (var code in token.AppliedCodes.OfType<LinkCode>()) {
if (this.Parent is Paragraph p && p.LinkAction != null) {
p.LinkAction.Invoke(this, code);
} else {
MlemPlatform.Current.OpenLinkOrFile(code.Match.Groups[1].Value); MlemPlatform.Current.OpenLinkOrFile(code.Match.Groups[1].Value);
}
}
}; };
} }