mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +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.CanBeMoused = false;
|
||||||
|
|
||||||
this.Formatter = new TextFormatter(() => this.BoldFont, () => this.ItalicFont);
|
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 => {
|
this.Formatter.Codes.Add(new Regex("<l ([^>]+)>"), (f, m, r) => new LinkCode(m, r, 1 / 16F, 0.85F, t => t == this.HoveredToken));
|
||||||
if (!this.Input.IsPressed(MouseButton.Left))
|
this.OnPressed += e => {
|
||||||
|
if (this.HoveredToken == null)
|
||||||
return;
|
return;
|
||||||
|
foreach (var code in this.HoveredToken.AppliedCodes.OfType<LinkCode>()) {
|
||||||
try {
|
try {
|
||||||
Process.Start(l.Match.Groups[1].Value);
|
Process.Start(code.Match.Groups[1].Value);
|
||||||
} catch (Exception) {
|
} catch (Exception) {
|
||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
}));
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Vector2 CalcActualSize(RectangleF parentArea) {
|
protected override Vector2 CalcActualSize(RectangleF parentArea) {
|
||||||
|
|
|
@ -7,22 +7,19 @@ using MLEM.Font;
|
||||||
namespace MLEM.Formatting.Codes {
|
namespace MLEM.Formatting.Codes {
|
||||||
public class LinkCode : UnderlineCode {
|
public class LinkCode : UnderlineCode {
|
||||||
|
|
||||||
private readonly Action<LinkCode> onSelected;
|
|
||||||
private readonly Func<Token, bool> isSelected;
|
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) {
|
public LinkCode(Match match, Regex regex, float thickness, float yOffset, Func<Token, bool> isSelected) : base(match, regex, thickness, yOffset) {
|
||||||
this.onSelected = onSelected;
|
|
||||||
this.isSelected = isSelected;
|
this.isSelected = isSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(GameTime time) {
|
public bool IsSelected() {
|
||||||
if (this.isSelected(this.Token))
|
return this.isSelected(this.Token);
|
||||||
this.onSelected(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
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
|
// 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