From e916ddb7a8ec6c3e022305d70514ae35c1b7c66a Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 18 May 2021 16:19:40 +0200 Subject: [PATCH] allow for underline and shadow codes to be mixed with font codes --- MLEM/Formatting/Codes/ResetFormattingCode.cs | 17 +++++++++++++++++ MLEM/Formatting/Codes/ShadowCode.cs | 9 +++++++-- MLEM/Formatting/Codes/UnderlineCode.cs | 5 +++++ MLEM/Formatting/TextFormatter.cs | 3 ++- 4 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 MLEM/Formatting/Codes/ResetFormattingCode.cs diff --git a/MLEM/Formatting/Codes/ResetFormattingCode.cs b/MLEM/Formatting/Codes/ResetFormattingCode.cs new file mode 100644 index 0000000..0a1103b --- /dev/null +++ b/MLEM/Formatting/Codes/ResetFormattingCode.cs @@ -0,0 +1,17 @@ +using System.Text.RegularExpressions; + +namespace MLEM.Formatting.Codes { + /// + public class ResetFormattingCode : Code { + + /// + public ResetFormattingCode(Match match, Regex regex) : base(match, regex) { + } + + /// + public override bool EndsHere(Code other) { + return true; + } + + } +} \ No newline at end of file diff --git a/MLEM/Formatting/Codes/ShadowCode.cs b/MLEM/Formatting/Codes/ShadowCode.cs index c50a086..d7dba53 100644 --- a/MLEM/Formatting/Codes/ShadowCode.cs +++ b/MLEM/Formatting/Codes/ShadowCode.cs @@ -6,13 +6,13 @@ using MLEM.Font; namespace MLEM.Formatting.Codes { /// - public class ShadowCode : FontCode { + public class ShadowCode : Code { private readonly Color color; private readonly Vector2 offset; /// - 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; } + /// + public override bool EndsHere(Code other) { + return base.EndsHere(other) || other is ResetFormattingCode; + } + } } \ No newline at end of file diff --git a/MLEM/Formatting/Codes/UnderlineCode.cs b/MLEM/Formatting/Codes/UnderlineCode.cs index 806575d..1a53004 100644 --- a/MLEM/Formatting/Codes/UnderlineCode.cs +++ b/MLEM/Formatting/Codes/UnderlineCode.cs @@ -29,5 +29,10 @@ namespace MLEM.Formatting.Codes { return false; } + /// + public override bool EndsHere(Code other) { + return base.EndsHere(other) || other is ResetFormattingCode; + } + } } \ No newline at end of file diff --git a/MLEM/Formatting/TextFormatter.cs b/MLEM/Formatting/TextFormatter.cs index 8fcc7bc..2a24fdb 100644 --- a/MLEM/Formatting/TextFormatter.cs +++ b/MLEM/Formatting/TextFormatter.cs @@ -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(""), (f, m, r) => new UnderlineCode(m, r, 1 / 16F, 0.85F)); - this.Codes.Add(new Regex(""), (f, m, r) => new FontCode(m, r, null)); + this.Codes.Add(new Regex(""), (f, m, r) => new ResetFormattingCode(m, r)); + this.Codes.Add(new Regex(""), (f, m, r) => new FontCode(m, r, null)); // color codes foreach (var c in typeof(Color).GetProperties()) {