mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 06:28:35 +01:00
modified link codes to use paragraphs' OnPressed
This commit is contained in:
parent
7f0a8289e3
commit
fad06f28be
2 changed files with 14 additions and 14 deletions
|
@ -66,15 +66,18 @@ namespace MLEM.Ui.Elements {
|
|||
this.CanBeMoused = false;
|
||||
|
||||
this.Formatter = new TextFormatter(() => this.BoldFont, () => this.ItalicFont);
|
||||
this.Formatter.Codes.Add(new Regex("<l ([^>]+)>"), (f, m, r) => new LinkCode(m, r, 1 / 16F, 0.85F, t => t == this.HoveredToken, l => {
|
||||
if (!this.Input.IsPressed(MouseButton.Left))
|
||||
this.Formatter.Codes.Add(new Regex("<l ([^>]+)>"), (f, m, r) => new LinkCode(m, r, 1 / 16F, 0.85F, t => t == this.HoveredToken));
|
||||
this.OnPressed += e => {
|
||||
if (this.HoveredToken == null)
|
||||
return;
|
||||
try {
|
||||
Process.Start(l.Match.Groups[1].Value);
|
||||
} catch (Exception) {
|
||||
// ignored
|
||||
foreach (var code in this.HoveredToken.AppliedCodes.OfType<LinkCode>()) {
|
||||
try {
|
||||
Process.Start(code.Match.Groups[1].Value);
|
||||
} catch (Exception) {
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
}));
|
||||
};
|
||||
}
|
||||
|
||||
protected override Vector2 CalcActualSize(RectangleF parentArea) {
|
||||
|
|
|
@ -7,22 +7,19 @@ using MLEM.Font;
|
|||
namespace MLEM.Formatting.Codes {
|
||||
public class LinkCode : UnderlineCode {
|
||||
|
||||
private readonly Action<LinkCode> onSelected;
|
||||
private readonly Func<Token, bool> isSelected;
|
||||
|
||||
public LinkCode(Match match, Regex regex, float thickness, float yOffset, Func<Token, bool> isSelected, Action<LinkCode> onSelected) : base(match, regex, thickness, yOffset) {
|
||||
this.onSelected = onSelected;
|
||||
public LinkCode(Match match, Regex regex, float thickness, float yOffset, Func<Token, bool> isSelected) : base(match, regex, thickness, yOffset) {
|
||||
this.isSelected = isSelected;
|
||||
}
|
||||
|
||||
public override void Update(GameTime time) {
|
||||
if (this.isSelected(this.Token))
|
||||
this.onSelected(this);
|
||||
public bool IsSelected() {
|
||||
return this.isSelected(this.Token);
|
||||
}
|
||||
|
||||
public override bool DrawCharacter(GameTime time, SpriteBatch batch, char c, string cString, int indexInToken, ref Vector2 pos, GenericFont font, ref Color color, ref float scale, float depth) {
|
||||
// since we inherit from UnderlineCode, we can just call base if selected
|
||||
return this.isSelected(this.Token) && base.DrawCharacter(time, batch, c, cString, indexInToken, ref pos, font, ref color, ref scale, depth);
|
||||
return this.IsSelected() && base.DrawCharacter(time, batch, c, cString, indexInToken, ref pos, font, ref color, ref scale, depth);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue