Chat lines vanish after a set time in game

Also, Clear chat on join server
This commit is contained in:
alzeih
2010-07-23 18:16:03 +12:00
committed by Chris Forbes
parent 409416b55c
commit 9516235707
4 changed files with 27 additions and 2 deletions

View File

@@ -16,9 +16,12 @@ namespace OpenRA.Widgets
{ {
class ChatDisplayWidget : Widget class ChatDisplayWidget : Widget
{ {
public readonly int RemoveTime = 0;
const int logLength = 9; const int logLength = 9;
public string Notification = ""; public string Notification = "";
public bool DrawBackground = true; public bool DrawBackground = true;
int ticksUntilRemove = 0;
public List<ChatLine> recentLines = new List<ChatLine>(); public List<ChatLine> recentLines = new List<ChatLine>();
@@ -52,16 +55,35 @@ namespace OpenRA.Widgets
Game.Renderer.RgbaSpriteRenderer.Flush(); Game.Renderer.RgbaSpriteRenderer.Flush();
Game.Renderer.Device.DisableScissor(); Game.Renderer.Device.DisableScissor();
} }
public void AddLine(Color c, string from, string text) public void AddLine(Color c, string from, string text)
{ {
recentLines.Add(new ChatLine { Color = c, Owner = from, Text = text }); recentLines.Add(new ChatLine { Color = c, Owner = from, Text = text });
ticksUntilRemove = RemoveTime;
if (Notification != null) if (Notification != null)
Sound.Play(Notification); Sound.Play(Notification);
while (recentLines.Count > logLength) recentLines.RemoveAt(0); while (recentLines.Count > logLength) recentLines.RemoveAt(0);
} }
public void RemoveLine()
{
if (recentLines.Count > 0) recentLines.RemoveAt(0);
}
public void ClearChat()
{
recentLines = new List<ChatLine>();
}
public override void Tick (World world)
{
if (RemoveTime == 0) return;
if (--ticksUntilRemove > 0) return;
ticksUntilRemove = RemoveTime;
RemoveLine();
}
public override Widget Clone() { return new ChatDisplayWidget(this); } public override Widget Clone() { return new ChatDisplayWidget(this); }
} }

View File

@@ -54,6 +54,7 @@ namespace OpenRA.Widgets.Delegates
break; break;
case ConnectionState.Connected: case ConnectionState.Connected:
r.OpenWindow("SERVER_LOBBY"); r.OpenWindow("SERVER_LOBBY");
r.GetWidget("SERVER_LOBBY").GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat();
break; break;
} }
}; };

View File

@@ -181,6 +181,7 @@ Container@ROOT:
Height: 200 Height: 200
ClickThrough: True ClickThrough: True
DrawBackground: False DrawBackground: False
RemoveTime:250
ChatEntry@CHAT_ENTRY: ChatEntry@CHAT_ENTRY:
Id:CHAT_ENTRY Id:CHAT_ENTRY
X:250 X:250

View File

@@ -188,6 +188,7 @@ Container@ROOT:
Height: 200 Height: 200
ClickThrough: True ClickThrough: True
DrawBackground: False DrawBackground: False
RemoveTime:250
ChatEntry@CHAT_ENTRY: ChatEntry@CHAT_ENTRY:
Id:CHAT_ENTRY Id:CHAT_ENTRY
X:250 X:250