mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-22 20:58:34 +01:00
allow a paragraph to modify its rendered text for animations
This commit is contained in:
parent
e37cfed757
commit
3f36093957
1 changed files with 6 additions and 2 deletions
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue