1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-24 17:29:23 +01:00

allow for underline and shadow codes to be mixed with font codes

This commit is contained in:
Ell 2021-05-18 16:19:40 +02:00
parent f94d471365
commit e916ddb7a8
4 changed files with 31 additions and 3 deletions

View file

@ -0,0 +1,17 @@
using System.Text.RegularExpressions;
namespace MLEM.Formatting.Codes {
/// <inheritdoc />
public class ResetFormattingCode : Code {
/// <inheritdoc />
public ResetFormattingCode(Match match, Regex regex) : base(match, regex) {
}
/// <inheritdoc />
public override bool EndsHere(Code other) {
return true;
}
}
}

View file

@ -6,13 +6,13 @@ using MLEM.Font;
namespace MLEM.Formatting.Codes {
/// <inheritdoc />
public class ShadowCode : FontCode {
public class ShadowCode : Code {
private readonly Color color;
private readonly Vector2 offset;
/// <inheritdoc />
public ShadowCode(Match match, Regex regex, Color color, Vector2 offset) : base(match, regex, null) {
public ShadowCode(Match match, Regex regex, Color color, Vector2 offset) : base(match, regex) {
this.color = color;
this.offset = offset;
}
@ -24,5 +24,10 @@ namespace MLEM.Formatting.Codes {
return false;
}
/// <inheritdoc />
public override bool EndsHere(Code other) {
return base.EndsHere(other) || other is ResetFormattingCode;
}
}
}

View file

@ -29,5 +29,10 @@ namespace MLEM.Formatting.Codes {
return false;
}
/// <inheritdoc />
public override bool EndsHere(Code other) {
return base.EndsHere(other) || other is ResetFormattingCode;
}
}
}

View file

@ -38,7 +38,8 @@ namespace MLEM.Formatting {
m.Groups[1].Success ? ColorHelper.FromHexString(m.Groups[1].Value) : Color.Black,
new Vector2(float.TryParse(m.Groups[2].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out var offset) ? offset : 2)));
this.Codes.Add(new Regex("<u>"), (f, m, r) => new UnderlineCode(m, r, 1 / 16F, 0.85F));
this.Codes.Add(new Regex("</(b|i|s|u|l)>"), (f, m, r) => new FontCode(m, r, null));
this.Codes.Add(new Regex("</(s|u|l)>"), (f, m, r) => new ResetFormattingCode(m, r));
this.Codes.Add(new Regex("</(b|i)>"), (f, m, r) => new FontCode(m, r, null));
// color codes
foreach (var c in typeof(Color).GetProperties()) {