diff --git a/CHANGELOG.md b/CHANGELOG.md index 010a3b9..5620938 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ Fixes Improvements - Increased TextFormatter macro recursion limit to 64 +- Allow changing the default values used by default TextFormatter codes ### MLEM.Ui Fixes diff --git a/MLEM/Formatting/TextFormatter.cs b/MLEM/Formatting/TextFormatter.cs index 11c1880..92c6e01 100644 --- a/MLEM/Formatting/TextFormatter.cs +++ b/MLEM/Formatting/TextFormatter.cs @@ -28,6 +28,52 @@ namespace MLEM.Formatting { /// public readonly Dictionary Macros = new Dictionary(); + /// + /// The line thickness used by this text formatter, which determines how the default -based formatting codes are drawn. + /// Note that this value only has an effect on the default formatting codes created through the constructor. + /// + public float LineThickness = 1 / 16F; + /// + /// The underline offset used by this text formatter, which determines how the default is drawn. + /// Note that this value only has an effect on the default formatting codes created through the constructor. + /// + public float UnderlineOffset = 0.85F; + /// + /// The strikethrough offset used by this text formatter, which determines how the default 's strikethrough variant is drawn. + /// Note that this value only has an effect on the default formatting codes created through the constructor. + /// + public float StrikethroughOffset = 0.55F; + /// + /// The default subscript offset used by this text formatter, which determines how the default is drawn if no custom value is used. + /// Note that this value only has an effect on the default formatting codes created through the constructor. + /// + public float DefaultSubOffset = 0.15F; + /// + /// The default superscript offset used by this text formatter, which determines how the default is drawn if no custom value is used. + /// Note that this value only has an effect on the default formatting codes created through the constructor. + /// + public float DefaultSupOffset = -0.25F; + /// + /// The default shadow color used by this text formatter, which determines how the default is drawn if no custom value is used. + /// Note that this value only has an effect on the default formatting codes created through the constructor. + /// + public Color DefaultShadowColor = Color.Black; + /// + /// The default shadow offset used by this text formatter, which determines how the default is drawn if no custom value is used. + /// Note that this value only has an effect on the default formatting codes created through the constructor. + /// + public Vector2 DefaultShadowOffset = new Vector2(2); + /// + /// The default wobbly modifier used by this text formatter, which determines how the default is drawn if no custom value is used. + /// Note that this value only has an effect on the default formatting codes created through the constructor. + /// + public float DefaultWobblyModifier = 5; + /// + /// The default wobbly modifier used by this text formatter, which determines how the default is drawn if no custom value is used. + /// Note that this value only has an effect on the default formatting codes created through the constructor. + /// + public float DefaultWobblyHeight = 1 / 8F; + /// /// Creates a new text formatter with an optional set of default formatting codes. /// @@ -41,14 +87,14 @@ namespace MLEM.Formatting { this.Codes.Add(new Regex(""), (f, m, r) => new FontCode(m, r, fnt => fnt.Bold)); this.Codes.Add(new Regex(""), (f, m, r) => new FontCode(m, r, fnt => fnt.Italic)); this.Codes.Add(new Regex(@""), (f, m, r) => new ShadowCode(m, r, - 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 UnderlineCode(m, r, 1 / 16F, 0.55F)); + m.Groups[1].Success ? ColorHelper.FromHexString(m.Groups[1].Value) : this.DefaultShadowColor, + float.TryParse(m.Groups[2].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out var offset) ? new Vector2(offset) : this.DefaultShadowOffset)); + this.Codes.Add(new Regex(""), (f, m, r) => new UnderlineCode(m, r, this.LineThickness, this.UnderlineOffset)); + this.Codes.Add(new Regex(""), (f, m, r) => new UnderlineCode(m, r, this.LineThickness, this.StrikethroughOffset)); this.Codes.Add(new Regex(@""), (f, m, r) => new SubSupCode(m, r, - float.TryParse(m.Groups[1].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out var off) ? off : 0.15F)); + float.TryParse(m.Groups[1].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out var off) ? off : this.DefaultSubOffset)); this.Codes.Add(new Regex(@""), (f, m, r) => new SubSupCode(m, r, - float.TryParse(m.Groups[1].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out var off) ? -off : -0.25F)); + float.TryParse(m.Groups[1].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out var off) ? -off : this.DefaultSupOffset)); } // color codes @@ -65,8 +111,8 @@ namespace MLEM.Formatting { // animation codes if (hasAnimations) { this.Codes.Add(new Regex(@""), (f, m, r) => new WobblyCode(m, r, - float.TryParse(m.Groups[1].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out var mod) ? mod : 5, - float.TryParse(m.Groups[2].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out var heightMod) ? heightMod : 1 / 8F)); + float.TryParse(m.Groups[1].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out var mod) ? mod : this.DefaultWobblyModifier, + float.TryParse(m.Groups[2].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out var heightMod) ? heightMod : this.DefaultWobblyHeight)); } // control codes