From 3f3609395726963354760193dfbce414ab8f5019 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Mon, 3 Feb 2020 23:42:30 +0100 Subject: [PATCH] allow a paragraph to modify its rendered text for animations --- MLEM.Ui/Elements/Paragraph.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/MLEM.Ui/Elements/Paragraph.cs b/MLEM.Ui/Elements/Paragraph.cs index 42e7c53..98ce958 100644 --- a/MLEM.Ui/Elements/Paragraph.cs +++ b/MLEM.Ui/Elements/Paragraph.cs @@ -36,6 +36,7 @@ namespace MLEM.Ui.Elements { } public bool AutoAdjustWidth; public TextCallback GetTextCallback; + public TextModifier RenderedTextModifier = text => text; public TimeSpan TimeIntoAnimation; public Paragraph(Anchor anchor, float width, TextCallback textCallback, bool centerText = false) @@ -83,13 +84,14 @@ namespace MLEM.Ui.Elements { var pos = this.DisplayArea.Location; var sc = this.TextScale * this.Scale; + var toRender = this.RenderedTextModifier(this.splitText); var color = this.TextColor.OrDefault(Color.White) * alpha; // if we don't have any formatting codes, then we don't need to do complex drawing if (this.Formatting.Count <= 0) { - this.RegularFont.Value.DrawString(batch, this.splitText, pos, color, 0, Vector2.Zero, sc, SpriteEffects.None, 0); + this.RegularFont.Value.DrawString(batch, toRender, pos, color, 0, Vector2.Zero, sc, SpriteEffects.None, 0); } else { // if we have formatting codes, we should do it - this.RegularFont.Value.DrawFormattedString(batch, pos, this.splitText, this.Formatting, color, sc, this.BoldFont.Value, this.ItalicFont.Value, 0, this.TimeIntoAnimation, this.FormatSettings); + this.RegularFont.Value.DrawFormattedString(batch, pos, toRender, this.Formatting, color, sc, this.BoldFont.Value, this.ItalicFont.Value, 0, this.TimeIntoAnimation, this.FormatSettings); } base.Draw(time, batch, alpha, blendState, samplerState, matrix); } @@ -105,5 +107,7 @@ namespace MLEM.Ui.Elements { public delegate string TextCallback(Paragraph paragraph); + public delegate string TextModifier(string text); + } } \ No newline at end of file