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

@@ -62,12 +62,12 @@ namespace OpenRA.Server
{ {
try try
{ {
motd.Text = GetData(new Uri(masterServerUrl + "motd.php?v=" + ClientVersion)); motd.SetText(GetData(new Uri(masterServerUrl + "motd.php?v=" + ClientVersion)));
motd.ResetScroll(); motd.ResetScroll();
} }
catch catch
{ {
motd.Text = "Welcome to OpenRA. MOTD unable to be loaded from server."; motd.SetText("Welcome to OpenRA. MOTD unable to be loaded from server.");
motd.ResetScroll(); motd.ResetScroll();
} }
} }

View File

@@ -9,6 +9,8 @@ namespace OpenRA.Widgets
class ScrollingTextWidget : Widget class ScrollingTextWidget : Widget
{ {
public string Text = ""; public string Text = "";
private string ScrollingText = "";
public string Background = null; public string Background = null;
public bool Bold = false; public bool Bold = false;
@@ -44,6 +46,11 @@ namespace OpenRA.Widgets
public override void Tick(World world) public override void Tick(World world)
{ {
if (Text != "")
{
ScrollingText = Text;
Text = "";
}
UpdateScrollBuffer(); UpdateScrollBuffer();
} }
@@ -65,19 +72,25 @@ namespace OpenRA.Widgets
ScrollTick = 0; ScrollTick = 0;
ScrollBuffer = ""; ScrollBuffer = "";
if (Text.Substring(Text.Length - 4, 3) != " ") if (ScrollingText.Substring(ScrollingText.Length - 4, 3) != " ")
{ {
Text += " "; ScrollingText += " ";
} }
int tempScrollLocation = ScrollLocation; int tempScrollLocation = ScrollLocation;
for (int i = 0; i < ScrollLength; ++i) for (int i = 0; i < ScrollLength; ++i)
{ {
ScrollBuffer += Text.Substring(tempScrollLocation, 1); ScrollBuffer += ScrollingText.Substring(tempScrollLocation, 1);
tempScrollLocation = (tempScrollLocation + 1) % Text.Length; 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) public override void DrawInner(World world)