mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-12-25 17:59:24 +01:00
Added subscript and superscript formatting codes
This commit is contained in:
parent
2e8a8244a3
commit
500736e20f
4 changed files with 32 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
24
MLEM/Formatting/Codes/SubSupCode.cs
Normal file
24
MLEM/Formatting/Codes/SubSupCode.cs
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
|
|
Loading…
Reference in a new issue