From fa5c8d083ed2ed2204583d37e8778144358738b5 Mon Sep 17 00:00:00 2001 From: Pavlos Touboulidis Date: Fri, 25 Apr 2014 17:34:00 +0300 Subject: [PATCH] Fix chat line expiration The chat display overlay would remove one chat line every X ticks. It will now keep track of the time each chat line has to be removed and act accordingly. For example, if 3 chat lines are added with 1 second difference from each other, they will be removed one after the other, with the same 1 second difference. --- OpenRA.Game/Widgets/ChatDisplayWidget.cs | 28 +++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/OpenRA.Game/Widgets/ChatDisplayWidget.cs b/OpenRA.Game/Widgets/ChatDisplayWidget.cs index ea0ecda348..d7e5e964bf 100644 --- a/OpenRA.Game/Widgets/ChatDisplayWidget.cs +++ b/OpenRA.Game/Widgets/ChatDisplayWidget.cs @@ -22,7 +22,7 @@ namespace OpenRA.Widgets public string Notification = ""; const int logLength = 9; - int ticksUntilRemove = 0; + uint totalTicks; internal List recentLines = new List(); @@ -69,8 +69,7 @@ namespace OpenRA.Widgets public void AddLine(Color c, string from, string text) { - recentLines.Add(new ChatLine { Color = c, Owner = from, Text = text }); - ticksUntilRemove = RemoveTime; + recentLines.Add(new ChatLine(from, text, totalTicks + (uint)RemoveTime, c)); if (Notification != null) Sound.Play(Notification); @@ -92,20 +91,29 @@ namespace OpenRA.Widgets public override void Tick() { + totalTicks++; + if (RemoveTime == 0) return; - if (--ticksUntilRemove > 0) - return; - - ticksUntilRemove = RemoveTime; - RemoveLine(); + // This takes advantage of the fact that recentLines is ordered by expiration, from sooner to later + while (recentLines.Count > 0 && totalTicks >= recentLines [0].Expiration) + recentLines.RemoveAt(0); } } class ChatLine { - public Color Color = Color.White; - public string Owner, Text; + public readonly Color Color; + public readonly string Owner, Text; + public readonly uint Expiration; + + public ChatLine(string owner, string text, uint expiration, Color color) + { + this.Owner = owner; + this.Text = text; + this.Expiration = expiration; + this.Color = color; + } } } \ No newline at end of file