1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-05-10 11:28:44 +02:00

Added subscript and superscript formatting codes

This commit is contained in:
Ell 2023-01-07 22:02:22 +01:00
parent 2e8a8244a3
commit 500736e20f
4 changed files with 32 additions and 1 deletions

View file

@ -22,6 +22,7 @@ Additions
- Added TokenizedString.GetArea
- Added InputHandler.WasPressedForLess and related methods as well as InputHandler.IsPressedIgnoreRepeats
- Added RandomExtensions.NextSingle with minimum and maximum values
- Added subscript and superscript formatting codes
- **Added the ability to find paths to one of multiple goals using AStar**
Improvements

View file

@ -18,7 +18,7 @@ namespace Demos {
"You can write in <b>bold</i>, <i>italics</i>, <u>with an underline</u>, <st>strikethrough</st>, with a <s #000000 4>drop shadow</s> whose <s #ff0000 4>color</s> and <s #000000 10>offset</s> you can modify in each application of the code, or with various types of <b>combined <c Pink>formatting</c> codes</b>.\n\n" +
"You can apply <c CornflowerBlue>custom</c> <c Yellow>colors</c> to text, including all default <c Orange>MonoGame colors</c> and <c #aabb00>inline custom colors</c>.\n\n" +
"You can also use animations like <a wobbly>a wobbly one</a>, as well as create custom ones using the <a wobbly>Code class</a>.\n\n" +
"You can also display <i grass> icons in your text!\n\n" +
"You can also display <i grass> icons in your text, and use super<sup>script</sup> or sub<sub>script</sub> formatting!\n\n" +
"Additionally, the text formatter has various methods for interacting with the text, like custom behaviors when hovering over certain parts, and more.";
private const float Scale = 0.5F;
private const float Width = 0.9F;

View file

@ -0,0 +1,24 @@
using System.Text.RegularExpressions;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MLEM.Font;
namespace MLEM.Formatting.Codes {
/// <inheritdoc />
public class SubSupCode : Code {
private readonly float offset;
/// <inheritdoc />
public SubSupCode(Match match, Regex regex, float offset) : base(match, regex) {
this.offset = offset;
}
/// <inheritdoc />
public override bool DrawCharacter(GameTime time, SpriteBatch batch, int codePoint, string character, Token token, int indexInToken, ref Vector2 pos, GenericFont font, ref Color color, ref float scale, float depth) {
pos.Y += this.offset * font.LineHeight * scale;
return false;
}
}
}

View file

@ -58,6 +58,12 @@ namespace MLEM.Formatting {
// control codes
this.Codes.Add(new Regex(@"</(\w+)>"), (f, m, r) => new SimpleEndCode(m, r, m.Groups[1].Value));
// superscript and subscript codes
this.Codes.Add(new Regex(@"<sub(?: ([+-.0-9]+))?>"), (f, m, r) => new SubSupCode(m, r,
float.TryParse(m.Groups[1].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out var off) ? off : 0.15F));
this.Codes.Add(new Regex(@"<sup(?: ([+-.0-9]+))?>"), (f, m, r) => new SubSupCode(m, r,
float.TryParse(m.Groups[1].Value, NumberStyles.Number, CultureInfo.InvariantCulture, out var off) ? -off : -0.25F));
// macros
this.Macros.Add(new Regex("~"), (f, m, r) => GenericFont.Nbsp.ToString());
this.Macros.Add(new Regex("<n>"), (f, m, r) => '\n'.ToString());