diff --git a/.gitignore b/.gitignore
index 78ff2f1..372ee7e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
.idea
+.vs
bin
obj
packages
diff --git a/MLEM/Formatting/Token.cs b/MLEM/Formatting/Token.cs
index 9b47836..cb88810 100644
--- a/MLEM/Formatting/Token.cs
+++ b/MLEM/Formatting/Token.cs
@@ -33,6 +33,22 @@ namespace MLEM.Formatting {
///
public string DisplayString => this.ModifiedSubstring ?? this.Substring;
///
+ /// The range of characters that are visible within this token, based on indices.
+ /// First value is the starting index of the visible range, second is the length.
+ ///
+ public Point DisplayVisibleRange { get; set; }
+ ///
+ /// Whether this token is entirely visible or not.
+ ///
+ public bool FullyVisible
+ {
+ get => DisplayVisibleRange.X <= 0 && DisplayVisibleRange.X + DisplayVisibleRange.Y >= DisplayString.Length;
+ set
+ {
+ DisplayVisibleRange = value ? new Point(0, DisplayString.Length) : Point.Zero;
+ }
+ }
+ ///
/// The , but split at newline characters
///
public string[] SplitDisplayString { get; internal set; }
@@ -50,6 +66,7 @@ namespace MLEM.Formatting {
this.RawIndex = rawIndex;
this.Substring = substring;
this.RawSubstring = rawSubstring;
+ this.FullyVisible = true;
foreach (var code in appliedCodes)
code.Token = this;
@@ -107,12 +124,18 @@ namespace MLEM.Formatting {
/// The character to draw
/// A single-character string that contains the character to draw
/// The index within this token that the character is at
+ /// The literal index within the token's display string this character is at.
/// The position to draw the token at
/// The font to use to draw
/// The color to draw with
/// The scale to draw at
/// The depth to draw at
- public void DrawCharacter(GameTime time, SpriteBatch batch, char c, string cString, int indexInToken, Vector2 pos, GenericFont font, Color color, float scale, float depth) {
+ public void DrawCharacter(GameTime time, SpriteBatch batch, char c, string cString, int indexInToken, int displayIndex, Vector2 pos, GenericFont font, Color color, float scale, float depth) {
+
+ //If display index not within visible span, we don't draw.
+ if (displayIndex < DisplayVisibleRange.X || displayIndex >= DisplayVisibleRange.X + DisplayVisibleRange.Y)
+ return;
+
foreach (var code in this.AppliedCodes) {
if (code.DrawCharacter(time, batch, c, cString, indexInToken, ref pos, font, ref color, ref scale, depth))
return;
diff --git a/MLEM/Formatting/TokenizedString.cs b/MLEM/Formatting/TokenizedString.cs
index 9dd2cef..1cebcdd 100644
--- a/MLEM/Formatting/TokenizedString.cs
+++ b/MLEM/Formatting/TokenizedString.cs
@@ -117,6 +117,8 @@ namespace MLEM.Formatting {
var token = this.Tokens[t];
var drawFont = token.GetFont(font);
var drawColor = token.GetColor(color);
+ int literalIndex = 0;
+
for (var l = 0; l < token.SplitDisplayString.Length; l++) {
var line = token.SplitDisplayString[l];
for (var i = 0; i < line.Length; i++) {
@@ -125,13 +127,16 @@ namespace MLEM.Formatting {
token.DrawSelf(time, batch, pos + innerOffset, drawFont, color, scale, depth);
var cString = c.ToCachedString();
- token.DrawCharacter(time, batch, c, cString, i, pos + innerOffset, drawFont, drawColor, scale, depth);
+ token.DrawCharacter(time, batch, c, cString, i, literalIndex, pos + innerOffset, drawFont, drawColor, scale, depth);
innerOffset.X += drawFont.MeasureString(cString).X * scale;
+
+ literalIndex++;
}
// only split at a new line, not between tokens!
if (l < token.SplitDisplayString.Length - 1) {
innerOffset.X = token.InnerOffsets[l] * scale;
innerOffset.Y += font.LineHeight * scale;
+ literalIndex++;
}
}
}