Cache chat conversations in the lobby and in-game
This preserves the chat content from the lobby and makes it available in-game, and also makes all chat content available to the end-game dialog.
This commit is contained in:
@@ -9,8 +9,9 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
@@ -19,13 +20,16 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
class LeaveMapLogic
|
||||
{
|
||||
enum Tab { Objectives, Chat };
|
||||
|
||||
Tab currentTab;
|
||||
|
||||
OrderManager orderManager;
|
||||
bool newChatMessage;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public LeaveMapLogic(Widget widget, World world)
|
||||
public LeaveMapLogic(Widget widget, World world, OrderManager orderManager)
|
||||
{
|
||||
this.orderManager = orderManager;
|
||||
|
||||
widget.Get<LabelWidget>("VERSION_LABEL").Text = Game.modData.Manifest.Mod.Version;
|
||||
|
||||
var showStats = false;
|
||||
@@ -70,7 +74,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
chatButton.IsHighlighted = () => currentTab == Tab.Chat || (newChatMessage && Game.LocalTick % 50 < 25);
|
||||
|
||||
Game.BeforeGameStart += UnregisterChatNotification;
|
||||
Game.AddChatLine += NotifyNewChatMessage;
|
||||
orderManager.AddChatLine += NotifyNewChatMessage;
|
||||
}
|
||||
|
||||
var statsButton = dialog.Get<ButtonWidget>("STATS_BUTTON");
|
||||
@@ -130,7 +134,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
|
||||
void UnregisterChatNotification()
|
||||
{
|
||||
Game.AddChatLine -= NotifyNewChatMessage;
|
||||
orderManager.AddChatLine -= NotifyNewChatMessage;
|
||||
Game.BeforeGameStart -= UnregisterChatNotification;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
{
|
||||
public class IngameChatLogic
|
||||
{
|
||||
readonly OrderManager orderManager;
|
||||
readonly Ruleset modRules;
|
||||
|
||||
readonly ContainerWidget chatOverlay;
|
||||
@@ -38,6 +39,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
[ObjectCreator.UseCtor]
|
||||
public IngameChatLogic(Widget widget, OrderManager orderManager, World world, Ruleset modRules)
|
||||
{
|
||||
this.orderManager = orderManager;
|
||||
this.modRules = modRules;
|
||||
|
||||
chatTraits = world.WorldActor.TraitsImplementing<INotifyChat>().ToList();
|
||||
@@ -125,7 +127,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
chatScrollPanel.RemoveChildren();
|
||||
chatScrollPanel.ScrollToBottom();
|
||||
|
||||
Game.AddChatLine += AddChatLine;
|
||||
foreach (var chatLine in orderManager.ChatCache)
|
||||
AddChatLine(chatLine.Color, chatLine.Name, chatLine.Text, true);
|
||||
|
||||
orderManager.AddChatLine += AddChatLineWrapper;
|
||||
Game.BeforeGameStart += UnregisterEvents;
|
||||
|
||||
CloseChat();
|
||||
@@ -133,7 +138,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
void UnregisterEvents()
|
||||
{
|
||||
Game.AddChatLine -= AddChatLine;
|
||||
orderManager.AddChatLine -= AddChatLineWrapper;
|
||||
Game.BeforeGameStart -= UnregisterEvents;
|
||||
}
|
||||
|
||||
@@ -156,9 +161,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
chatOverlay.Visible = true;
|
||||
}
|
||||
|
||||
public void AddChatLine(Color c, string from, string text)
|
||||
public void AddChatLineWrapper(Color c, string from, string text)
|
||||
{
|
||||
if (!inDialog)
|
||||
AddChatLine(c, from, text, false);
|
||||
}
|
||||
|
||||
void AddChatLine(Color c, string from, string text, bool replayCache)
|
||||
{
|
||||
if (!(inDialog || replayCache))
|
||||
chatOverlayDisplay.AddLine(c, from, text);
|
||||
|
||||
var template = chatTemplate.Clone();
|
||||
@@ -193,7 +203,8 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
if (scrolledToBottom)
|
||||
chatScrollPanel.ScrollToBottom(smooth: true);
|
||||
|
||||
Sound.PlayNotification(modRules, null, "Sounds", "ChatLine", null);
|
||||
if (!replayCache)
|
||||
Sound.PlayNotification(modRules, null, "Sounds", "ChatLine", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,10 +84,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
|
||||
void CloseWindow()
|
||||
{
|
||||
orderManager.AddChatLine -= AddChatLine;
|
||||
Game.LobbyInfoChanged -= UpdateCurrentMap;
|
||||
Game.LobbyInfoChanged -= UpdatePlayerList;
|
||||
Game.BeforeGameStart -= OnGameStart;
|
||||
Game.AddChatLine -= AddChatLine;
|
||||
Game.ConnectionStateChanged -= ConnectionStateChanged;
|
||||
|
||||
Ui.CloseWindow();
|
||||
@@ -104,10 +104,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
this.skirmishMode = skirmishMode;
|
||||
this.modRules = modRules;
|
||||
|
||||
orderManager.AddChatLine += AddChatLine;
|
||||
Game.LobbyInfoChanged += UpdateCurrentMap;
|
||||
Game.LobbyInfoChanged += UpdatePlayerList;
|
||||
Game.BeforeGameStart += OnGameStart;
|
||||
Game.AddChatLine += AddChatLine;
|
||||
Game.ConnectionStateChanged += ConnectionStateChanged;
|
||||
|
||||
var name = lobby.GetOrNull<LabelWidget>("SERVER_NAME");
|
||||
|
||||
Reference in New Issue
Block a user