diff --git a/Demos/UiDemo.cs b/Demos/UiDemo.cs index c1c18da..b11d105 100644 --- a/Demos/UiDemo.cs +++ b/Demos/UiDemo.cs @@ -103,7 +103,7 @@ namespace Demos { root.AddChild(new Paragraph(Anchor.AutoLeft, 1, "Additionally, you can create custom formatting codes that contain [Grass] images or [Walk] sprite animations! Note that these images have to be square, or [Tree] bad things happen.")); - var animatedPar = root.AddChild(new Paragraph(Anchor.AutoLeft, 1, "Defining text animations as formatting codes is also possible, including [Wobbly]wobbly text[Unanimated] as well as a [Typing]dialogue-esc typing effect by default. Of course, more animations can be added though.")); + var animatedPar = root.AddChild(new Paragraph(Anchor.AutoLeft, 1, "Defining text animations as formatting codes is also possible, including [Wobbly]wobbly text[Unanimated] as well as a [Typing]dialogue-esque typing effect by default. Of course, more animations can be added though.")); root.AddChild(new Button(Anchor.AutoCenter, new Vector2(1, 10), "Reset Typing Animation") { // to reset any animation, simply change the paragraph's TimeIntoAnimation OnPressed = e => animatedPar.TimeIntoAnimation = TimeSpan.Zero @@ -209,7 +209,7 @@ namespace Demos { root.AddChild(ElementHelper.ImageButton(Anchor.AutoLeft, new Vector2(1, 10), tree, "Button with image")).PositionOffset = new Vector2(0, 1); root.AddChild(new Button(Anchor.AutoLeft, new Vector2(1, 10), "Disabled button") {IsDisabled = true}).PositionOffset = new Vector2(0, 1); - //root.AddChild(new Paragraph(Anchor.AutoLeft, 1, "This_is_a_really_long_line_to_see_if_splitting_without_spaces_works_properly._I_also_want_to_see_if_it_works_across_multiple_lines_or_just_on_the_first_one. But after this, I want the text to continue normally before changing_back_to_being_really_long_oh_yes")); + root.AddChild(new Paragraph(Anchor.AutoLeft, 1, "This_is_a_really_long_[Blue]line[White]_to_see_if_splitting_without_spaces_works_properly._I_also_want_to_see_if_it_works_[Blue]across[White]_multiple_lines_or_just_on_the_first_one. But after this, I want the text to [Blue]continue[White] normally before changing_back_to_being_really_long_[Blue]oh[White]_yes")); // Below are some querying examples that help you find certain elements easily diff --git a/MLEM/Extensions/SpriteFontExtensions.cs b/MLEM/Extensions/SpriteFontExtensions.cs index 88b0cb5..e346f47 100644 --- a/MLEM/Extensions/SpriteFontExtensions.cs +++ b/MLEM/Extensions/SpriteFontExtensions.cs @@ -36,7 +36,7 @@ namespace MLEM.Extensions { foreach (var word in line.Split(' ')) { if (widthFunc(word) * scale >= width) { if (curr.Length > 0) { - total.Append(curr.ToString(0, curr.Length - 1)).Append('\n'); + total.Append(curr.ToString(0, curr.Length)).Append('\n'); curr.Clear(); } var wordBuilder = new StringBuilder(); @@ -53,13 +53,13 @@ namespace MLEM.Extensions { if (widthFunc(curr.ToString()) * scale >= width) { var len = curr.Length - word.Length - 1; if (len > 0) { - total.Append(curr.ToString(0, len - 1)).Append('\n'); + total.Append(curr.ToString(0, len)).Append('\n'); curr.Remove(0, len); } } } } - total.Append(curr.ToString(0, curr.Length - 1)).Append('\n'); + total.Append(curr).Append('\n'); } return total.ToString(0, total.Length - 1); } diff --git a/MLEM/Formatting/TextFormatting.cs b/MLEM/Formatting/TextFormatting.cs index 31a2165..3c96213 100644 --- a/MLEM/Formatting/TextFormatting.cs +++ b/MLEM/Formatting/TextFormatting.cs @@ -89,9 +89,10 @@ namespace MLEM.Formatting { var animStart = 0; var innerOffset = new Vector2(); + var formatIndex = 0; for (var i = 0; i < unformattedText.Length; i++) { // check if the current character's index has a formatting code - if (formatting.TryGetValue(i, out var codes)) { + if (formatting.TryGetValue(formatIndex, out var codes)) { foreach (var code in codes) { // if so, apply it switch (code.CodeType) { @@ -134,6 +135,7 @@ namespace MLEM.Formatting { currAnim(settings, currFont, batch, unformattedText, i, animStart, cSt, pos + innerOffset + settings.DropShadowOffset * scale, settings.DropShadowColor, scale, depth, timeIntoAnimation); currAnim(settings, currFont, batch, unformattedText, i, animStart, cSt, pos + innerOffset, currColor, scale, depth, timeIntoAnimation); innerOffset.X += regularFont.MeasureString(cSt).X * scale; + formatIndex++; } } }