Fix overlay chat lines expiration

It wasn't working right when the widget was hidden because it
wasn't receiving any Ticks. Instead of counting, we're now using
Game.LocalTick as the tick source.
This commit is contained in:
Pavlos Touboulidis
2014-04-26 03:18:46 +03:00
parent ddabe080cd
commit c099e6d09b

View File

@@ -22,7 +22,6 @@ namespace OpenRA.Widgets
public string Notification = ""; public string Notification = "";
const int logLength = 9; const int logLength = 9;
uint totalTicks;
List<ChatLine> recentLines = new List<ChatLine>(); List<ChatLine> recentLines = new List<ChatLine>();
public override Rectangle EventBounds { get { return Rectangle.Empty; } } public override Rectangle EventBounds { get { return Rectangle.Empty; } }
@@ -68,7 +67,7 @@ namespace OpenRA.Widgets
public void AddLine(Color c, string from, string text) public void AddLine(Color c, string from, string text)
{ {
recentLines.Add(new ChatLine(from, text, totalTicks + (uint)RemoveTime, c)); recentLines.Add(new ChatLine(from, text, Game.LocalTick + RemoveTime, c));
if (Notification != null) if (Notification != null)
Sound.Play(Notification); Sound.Play(Notification);
@@ -85,13 +84,11 @@ namespace OpenRA.Widgets
public override void Tick() public override void Tick()
{ {
totalTicks++;
if (RemoveTime == 0) if (RemoveTime == 0)
return; return;
// This takes advantage of the fact that recentLines is ordered by expiration, from sooner to later // This takes advantage of the fact that recentLines is ordered by expiration, from sooner to later
while (recentLines.Count > 0 && totalTicks >= recentLines[0].Expiration) while (recentLines.Count > 0 && Game.LocalTick >= recentLines[0].Expiration)
recentLines.RemoveAt(0); recentLines.RemoveAt(0);
} }
} }
@@ -100,9 +97,9 @@ namespace OpenRA.Widgets
{ {
public readonly Color Color; public readonly Color Color;
public readonly string Owner, Text; public readonly string Owner, Text;
public readonly uint Expiration; public readonly int Expiration;
public ChatLine(string owner, string text, uint expiration, Color color) public ChatLine(string owner, string text, int expiration, Color color)
{ {
Owner = owner; Owner = owner;
Text = text; Text = text;