Chat lines vanish after a set time in game
Also, Clear chat on join server
This commit is contained in:
@@ -16,9 +16,12 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
class ChatDisplayWidget : Widget
|
||||
{
|
||||
public readonly int RemoveTime = 0;
|
||||
|
||||
const int logLength = 9;
|
||||
public string Notification = "";
|
||||
public bool DrawBackground = true;
|
||||
int ticksUntilRemove = 0;
|
||||
|
||||
public List<ChatLine> recentLines = new List<ChatLine>();
|
||||
|
||||
@@ -56,6 +59,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;
|
||||
|
||||
if (Notification != null)
|
||||
Sound.Play(Notification);
|
||||
@@ -63,6 +67,24 @@ namespace OpenRA.Widgets
|
||||
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); }
|
||||
}
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ namespace OpenRA.Widgets.Delegates
|
||||
break;
|
||||
case ConnectionState.Connected:
|
||||
r.OpenWindow("SERVER_LOBBY");
|
||||
r.GetWidget("SERVER_LOBBY").GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat();
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -181,6 +181,7 @@ Container@ROOT:
|
||||
Height: 200
|
||||
ClickThrough: True
|
||||
DrawBackground: False
|
||||
RemoveTime:250
|
||||
ChatEntry@CHAT_ENTRY:
|
||||
Id:CHAT_ENTRY
|
||||
X:250
|
||||
|
||||
@@ -188,6 +188,7 @@ Container@ROOT:
|
||||
Height: 200
|
||||
ClickThrough: True
|
||||
DrawBackground: False
|
||||
RemoveTime:250
|
||||
ChatEntry@CHAT_ENTRY:
|
||||
Id:CHAT_ENTRY
|
||||
X:250
|
||||
|
||||
Reference in New Issue
Block a user