Strip newlines from scrolling text. Frame-friendly update of scrolling text

This commit is contained in:
Caleb Anderson
2010-10-07 23:11:11 -05:00
committed by Chris Forbes
parent 92c30b89f8
commit ef4f478e10
2 changed files with 21 additions and 8 deletions

View File

@@ -9,6 +9,8 @@ namespace OpenRA.Widgets
class ScrollingTextWidget : Widget
{
public string Text = "";
private string ScrollingText = "";
public string Background = null;
public bool Bold = false;
@@ -44,6 +46,11 @@ namespace OpenRA.Widgets
public override void Tick(World world)
{
if (Text != "")
{
ScrollingText = Text;
Text = "";
}
UpdateScrollBuffer();
}
@@ -65,21 +72,27 @@ namespace OpenRA.Widgets
ScrollTick = 0;
ScrollBuffer = "";
if (Text.Substring(Text.Length - 4, 3) != " ")
if (ScrollingText.Substring(ScrollingText.Length - 4, 3) != " ")
{
Text += " ";
ScrollingText += " ";
}
int tempScrollLocation = ScrollLocation;
for (int i = 0; i < ScrollLength; ++i)
{
ScrollBuffer += Text.Substring(tempScrollLocation, 1);
tempScrollLocation = (tempScrollLocation + 1) % Text.Length;
ScrollBuffer += ScrollingText.Substring(tempScrollLocation, 1);
tempScrollLocation = (tempScrollLocation + 1) % ScrollingText.Length;
}
ScrollLocation = (ScrollLocation + 1) % Text.Length;
ScrollLocation = (ScrollLocation + 1) % ScrollingText.Length;
}
public void SetText(string newText)
{
Text = newText.Replace("\n", " ");
Text = Text.Replace("\r", "");
}
public override void DrawInner(World world)
{
var bg = GetBackground();