From d9d220259975f650cd84b92bd59ca122f5c8b24d Mon Sep 17 00:00:00 2001 From: teinarss Date: Wed, 27 Mar 2019 19:17:02 +0100 Subject: [PATCH] System messages should be yellow to distinguish them from normal --- OpenRA.Game/Game.cs | 16 ++++++-- OpenRA.Game/Network/OrderManager.cs | 16 ++++---- OpenRA.Game/Network/UnitOrders.cs | 16 ++++---- .../Scripting/Global/MediaGlobal.cs | 2 +- .../Player/ConquestVictoryConditions.cs | 4 +- .../Player/StrategicVictoryConditions.cs | 4 +- .../Widgets/ChatDisplayWidget.cs | 40 ++++++++++--------- .../Widgets/Logic/Ingame/IngameChatLogic.cs | 14 ++++--- .../Widgets/Logic/Lobby/LobbyLogic.cs | 4 +- .../Widgets/Logic/Lobby/LobbyUtils.cs | 12 +++--- .../Widgets/Logic/MuteHotkeyLogic.cs | 4 +- .../WorldInteractionControllerWidget.cs | 8 ++-- mods/cnc/metrics.yaml | 2 + mods/d2k/metrics.yaml | 2 + mods/ra/metrics.yaml | 2 + mods/ts/metrics.yaml | 2 + 16 files changed, 87 insertions(+), 61 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 5f6871ba31..1c2eda76a5 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -465,6 +465,9 @@ namespace OpenRA Log.Write("nat", e.ToString()); } + chatMessageColor = ChromeMetrics.Get("ChatMessageColor"); + systemMessageColor = ChromeMetrics.Get("SystemMessageColor"); + ModData.LoadScreen.StartGame(args); } @@ -524,6 +527,8 @@ namespace OpenRA // Note: These delayed actions should only be used by widgets or disposing objects // - things that depend on a particular world should be queuing them on the world actor. static volatile ActionQueue delayedActions = new ActionQueue(); + static Color systemMessageColor; + static Color chatMessageColor; public static void RunAfterTick(Action a) { delayedActions.Add(a, RunTime); } public static void RunAfterDelay(int delayMilliseconds, Action a) { delayedActions.Add(a, RunTime + delayMilliseconds); } @@ -836,14 +841,19 @@ namespace OpenRA state = RunStatus.Success; } - public static void AddChatLine(Color color, string name, string text) + public static void AddSystemLine(string name, string text) { - OrderManager.AddChatLine(color, name, text); + OrderManager.AddChatLine(name, systemMessageColor, text, systemMessageColor); + } + + public static void AddChatLine(string name, Color nameColor, string text) + { + OrderManager.AddChatLine(name, nameColor, text, chatMessageColor); } public static void Debug(string s, params object[] args) { - AddChatLine(Color.White, "Debug", string.Format(s, args)); + AddSystemLine("Debug", string.Format(s, args)); } public static void Disconnect() diff --git a/OpenRA.Game/Network/OrderManager.cs b/OpenRA.Game/Network/OrderManager.cs index 989c162bfe..73f2313fcb 100644 --- a/OpenRA.Game/Network/OrderManager.cs +++ b/OpenRA.Game/Network/OrderManager.cs @@ -105,10 +105,10 @@ namespace OpenRA.Network localOrders.Add(order); } - public Action AddChatLine = (c, n, s) => { }; - void CacheChatLine(Color color, string name, string text) + public Action AddChatLine = (n, nc, s, tc) => { }; + void CacheChatLine(string name, Color nameColor, string text, Color textColor) { - chatCache.Add(new ChatLine(color, name, text)); + chatCache.Add(new ChatLine(name, nameColor, text, textColor)); } public void TickImmediate() @@ -219,12 +219,14 @@ namespace OpenRA.Network public readonly Color Color; public readonly string Name; public readonly string Text; + public readonly Color TextColor; - public ChatLine(Color c, string n, string t) + public ChatLine(string name, Color nameColor, string text, Color textColor) { - Color = c; - Name = n; - Text = t; + Color = nameColor; + Name = name; + Text = text; + TextColor = textColor; } } } diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs index 7de00d3dbb..237ac7cccd 100644 --- a/OpenRA.Game/Network/UnitOrders.cs +++ b/OpenRA.Game/Network/UnitOrders.cs @@ -40,7 +40,7 @@ namespace OpenRA.Network { // Server message case "Message": - Game.AddChatLine(Color.White, ServerChatName, order.TargetString); + Game.AddSystemLine(ServerChatName, order.TargetString); break; // Reports that the target player disconnected @@ -73,7 +73,7 @@ namespace OpenRA.Network if (orderManager.LocalClient != null && client != orderManager.LocalClient && client.Team > 0 && client.Team == orderManager.LocalClient.Team) suffix += " (Ally)"; - Game.AddChatLine(client.Color, client.Name + suffix, message); + Game.AddChatLine(client.Name + suffix, client.Color, message); break; } @@ -82,7 +82,7 @@ namespace OpenRA.Network { var prefix = order.ExtraData == uint.MaxValue ? "[Spectators] " : "[Team] "; if (orderManager.LocalClient != null && client.Team == orderManager.LocalClient.Team) - Game.AddChatLine(client.Color, prefix + client.Name, message); + Game.AddChatLine(prefix + client.Name, client.Color, message); break; } @@ -98,7 +98,7 @@ namespace OpenRA.Network { // Validate before adding the line if (client.IsObserver || (player != null && player.WinState != WinState.Undefined)) - Game.AddChatLine(client.Color, "[Spectators] " + client.Name, message); + Game.AddChatLine("[Spectators] " + client.Name, client.Color, message); break; } @@ -108,7 +108,7 @@ namespace OpenRA.Network && world.LocalPlayer.WinState == WinState.Undefined; if (valid && (isSameTeam || world.IsReplay)) - Game.AddChatLine(client.Color, "[Team" + (world.IsReplay ? " " + order.ExtraData : "") + "] " + client.Name, message); + Game.AddChatLine("[Team" + (world.IsReplay ? " " + order.ExtraData : "") + "] " + client.Name, client.Color, message); break; } @@ -138,7 +138,7 @@ namespace OpenRA.Network FieldLoader.GetValue("SaveSyncFrame", saveSyncFrame.Value.Value); } else - Game.AddChatLine(Color.White, ServerChatName, "The game has started."); + Game.AddSystemLine(ServerChatName, "The game has started."); Game.StartGame(orderManager.LobbyInfo.GlobalSettings.Map, WorldType.Regular); break; @@ -157,7 +157,7 @@ namespace OpenRA.Network case "GameSaved": if (!orderManager.World.IsReplay) - Game.AddChatLine(Color.White, ServerChatName, "Game saved"); + Game.AddSystemLine(ServerChatName, "Game saved"); foreach (var nsr in orderManager.World.WorldActor.TraitsImplementing()) nsr.GameSaved(orderManager.World); @@ -177,7 +177,7 @@ namespace OpenRA.Network if (orderManager.World.Paused != pause && world != null && world.LobbyInfo.NonBotClients.Count() > 1) { var pausetext = "The game is {0} by {1}".F(pause ? "paused" : "un-paused", client.Name); - Game.AddChatLine(Color.White, ServerChatName, pausetext); + Game.AddSystemLine(ServerChatName, pausetext); } orderManager.World.Paused = pause; diff --git a/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs index 63a2f041b3..209794735f 100644 --- a/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs @@ -195,7 +195,7 @@ namespace OpenRA.Mods.Common.Scripting return; var c = color.HasValue ? color.Value : Color.White; - Game.AddChatLine(c, prefix, text); + Game.AddChatLine(prefix, c, text); } [Desc("Displays a debug message to the player, if \"Show Map Debug Messages\" is checked in the settings.")] diff --git a/OpenRA.Mods.Common/Traits/Player/ConquestVictoryConditions.cs b/OpenRA.Mods.Common/Traits/Player/ConquestVictoryConditions.cs index 3c83f2076a..84dc4bc665 100644 --- a/OpenRA.Mods.Common/Traits/Player/ConquestVictoryConditions.cs +++ b/OpenRA.Mods.Common/Traits/Player/ConquestVictoryConditions.cs @@ -77,7 +77,7 @@ namespace OpenRA.Mods.Common.Traits if (info.SuppressNotifications) return; - Game.AddChatLine(Color.White, "Battlefield Control", player.PlayerName + " is defeated."); + Game.AddSystemLine("Battlefield Control", player.PlayerName + " is defeated."); Game.RunAfterDelay(info.NotificationDelay, () => { if (Game.IsCurrentWorld(player.World) && player == player.World.LocalPlayer) @@ -90,7 +90,7 @@ namespace OpenRA.Mods.Common.Traits if (info.SuppressNotifications) return; - Game.AddChatLine(Color.White, "Battlefield Control", player.PlayerName + " is victorious."); + Game.AddSystemLine("Battlefield Control", player.PlayerName + " is victorious."); Game.RunAfterDelay(info.NotificationDelay, () => { if (Game.IsCurrentWorld(player.World) && player == player.World.LocalPlayer) diff --git a/OpenRA.Mods.Common/Traits/Player/StrategicVictoryConditions.cs b/OpenRA.Mods.Common/Traits/Player/StrategicVictoryConditions.cs index 66dae62808..043fb76e55 100644 --- a/OpenRA.Mods.Common/Traits/Player/StrategicVictoryConditions.cs +++ b/OpenRA.Mods.Common/Traits/Player/StrategicVictoryConditions.cs @@ -116,7 +116,7 @@ namespace OpenRA.Mods.Common.Traits if (info.SuppressNotifications) return; - Game.AddChatLine(Color.White, "Battlefield Control", player.PlayerName + " is defeated."); + Game.AddSystemLine("Battlefield Control", player.PlayerName + " is defeated."); Game.RunAfterDelay(info.NotificationDelay, () => { if (Game.IsCurrentWorld(player.World) && player == player.World.LocalPlayer) @@ -129,7 +129,7 @@ namespace OpenRA.Mods.Common.Traits if (info.SuppressNotifications) return; - Game.AddChatLine(Color.White, "Battlefield Control", player.PlayerName + " is victorious."); + Game.AddSystemLine("Battlefield Control", player.PlayerName + " is victorious."); Game.RunAfterDelay(info.NotificationDelay, () => { if (Game.IsCurrentWorld(player.World) && player == player.World.LocalPlayer) diff --git a/OpenRA.Mods.Common/Widgets/ChatDisplayWidget.cs b/OpenRA.Mods.Common/Widgets/ChatDisplayWidget.cs index 84f3fc3b12..5354f68b10 100644 --- a/OpenRA.Mods.Common/Widgets/ChatDisplayWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ChatDisplayWidget.cs @@ -43,12 +43,12 @@ namespace OpenRA.Mods.Common.Widgets foreach (var line in recentLines.AsEnumerable().Reverse()) { var inset = 0; - string owner = null; + string name = null; - if (!string.IsNullOrEmpty(line.Owner)) + if (!string.IsNullOrEmpty(line.Name)) { - owner = line.Owner + ":"; - inset = font.Measure(owner).X + 5; + name = line.Name + ":"; + inset = font.Measure(name).X + 5; } var text = WidgetUtils.WrapText(line.Text, chatLogArea.Width - inset - 6, font); @@ -57,24 +57,24 @@ namespace OpenRA.Mods.Common.Widgets if (chatpos.Y < pos.Y) break; - if (owner != null) + if (name != null) { if (UseContrast) - font.DrawTextWithContrast(owner, chatpos, - line.Color, BackgroundColorDark, BackgroundColorLight, 1); + font.DrawTextWithContrast(name, chatpos, + line.NameColor, BackgroundColorDark, BackgroundColorLight, 1); else if (UseShadow) - font.DrawTextWithShadow(owner, chatpos, - line.Color, BackgroundColorDark, BackgroundColorLight, 1); + font.DrawTextWithShadow(name, chatpos, + line.NameColor, BackgroundColorDark, BackgroundColorLight, 1); else - font.DrawText(owner, chatpos, line.Color); + font.DrawText(name, chatpos, line.NameColor); } if (UseContrast) font.DrawTextWithContrast(text, chatpos + new int2(inset, 0), - Color.White, Color.Black, 1); + line.TextColor, Color.Black, 1); else if (UseShadow) font.DrawTextWithShadow(text, chatpos + new int2(inset, 0), - Color.White, Color.Black, 1); + line.TextColor, Color.Black, 1); else font.DrawText(text, chatpos + new int2(inset, 0), Color.White); } @@ -82,9 +82,9 @@ namespace OpenRA.Mods.Common.Widgets Game.Renderer.DisableScissor(); } - public void AddLine(Color c, string from, string text) + public void AddLine(string name, Color nameColor, string text, Color textColor) { - recentLines.Add(new ChatLine(from, text, Game.LocalTick + RemoveTime, c)); + recentLines.Add(new ChatLine(name, nameColor, text, textColor, Game.LocalTick + RemoveTime)); if (Notification != null) Game.Sound.Play(SoundType.UI, Notification); @@ -112,16 +112,18 @@ namespace OpenRA.Mods.Common.Widgets class ChatLine { - public readonly Color Color; - public readonly string Owner, Text; + public readonly Color NameColor; + public readonly Color TextColor; + public readonly string Name, Text; public readonly int Expiration; - public ChatLine(string owner, string text, int expiration, Color color) + public ChatLine(string name, Color nameColor, string text, Color textColor, int expiration) { - Owner = owner; + Name = name; Text = text; Expiration = expiration; - Color = color; + NameColor = nameColor; + TextColor = textColor; } } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs index cfa2220c35..fa8589e3f9 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs @@ -206,7 +206,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic chatScrollPanel.ScrollToBottom(); foreach (var chatLine in orderManager.ChatCache) - AddChatLine(chatLine.Color, chatLine.Name, chatLine.Text, true); + AddChatLine(chatLine.Name, chatLine.Color, chatLine.Text, chatLine.TextColor, true); orderManager.AddChatLine += AddChatLineWrapper; @@ -255,17 +255,17 @@ namespace OpenRA.Mods.Common.Widgets.Logic chatOverlay.Visible = true; } - public void AddChatLineWrapper(Color c, string from, string text) + public void AddChatLineWrapper(string name, Color nameColor, string text, Color textColor) { if (chatOverlayDisplay != null) - chatOverlayDisplay.AddLine(c, from, text); + chatOverlayDisplay.AddLine(name, nameColor, text, textColor); // HACK: Force disable the chat notification sound for the in-menu chat dialog // This works around our inability to disable the sounds for the in-game dialog when it is hidden - AddChatLine(c, from, text, chatOverlay == null); + AddChatLine(name, nameColor, text, textColor, chatOverlay == null); } - void AddChatLine(Color c, string from, string text, bool suppressSound) + void AddChatLine(string @from, Color nameColor, string text, Color textColor, bool suppressSound) { var template = chatTemplate.Clone(); var nameLabel = template.Get("NAME"); @@ -278,9 +278,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic var font = Game.Renderer.Fonts[nameLabel.Font]; var nameSize = font.Measure(from); - nameLabel.GetColor = () => c; + nameLabel.GetColor = () => nameColor; nameLabel.GetText = () => name; nameLabel.Bounds.Width = nameSize.X; + + textLabel.GetColor = () => textColor; textLabel.Bounds.X += nameSize.X; textLabel.Bounds.Width -= nameSize.X; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index 9abcd2fc53..e13fe5d094 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -475,10 +475,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic panel = PanelType.Players; } - void AddChatLine(Color c, string from, string text) + void AddChatLine(string name, Color nameColor, string text, Color textColor) { var template = (ContainerWidget)chatTemplate.Clone(); - LobbyUtils.SetupChatLine(template, c, DateTime.Now, from, text); + LobbyUtils.SetupChatLine(template, DateTime.Now, name, nameColor, text, textColor); var scrolledToBottom = lobbyChatPanel.ScrolledToBottom; lobbyChatPanel.AddChild(template); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index 9571be221a..c0e7934d4a 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -621,21 +621,23 @@ namespace OpenRA.Mods.Common.Widgets.Logic return address; } - public static void SetupChatLine(ContainerWidget template, Color c, DateTime time, string from, string text) + public static void SetupChatLine(ContainerWidget template, DateTime time, string name, Color nameColor, string text, Color textColor) { var nameLabel = template.Get("NAME"); var timeLabel = template.Get("TIME"); var textLabel = template.Get("TEXT"); - var name = from + ":"; + var nameText = name + ":"; var font = Game.Renderer.Fonts[nameLabel.Font]; - var nameSize = font.Measure(from); + var nameSize = font.Measure(nameText); timeLabel.GetText = () => "{0:D2}:{1:D2}".F(time.Hour, time.Minute); - nameLabel.GetColor = () => c; - nameLabel.GetText = () => name; + nameLabel.GetColor = () => nameColor; + nameLabel.GetText = () => nameText; nameLabel.Bounds.Width = nameSize.X; + + textLabel.GetColor = () => textColor; textLabel.Bounds.X += nameSize.X; textLabel.Bounds.Width -= nameSize.X; diff --git a/OpenRA.Mods.Common/Widgets/Logic/MuteHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MuteHotkeyLogic.cs index 33448bf193..93c746eb5d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MuteHotkeyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MuteHotkeyLogic.cs @@ -30,12 +30,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (Game.Settings.Sound.Mute) { Game.Sound.MuteAudio(); - Game.AddChatLine(Color.White, "Battlefield Control", "Audio muted"); + Game.AddChatLine("Battlefield Control", Color.White, "Audio muted"); } else { Game.Sound.UnmuteAudio(); - Game.AddChatLine(Color.White, "Battlefield Control", "Audio unmuted"); + Game.AddChatLine("Battlefield Control", Color.White, "Audio unmuted"); } return true; diff --git a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs index dbc43b4a0a..601780172e 100644 --- a/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/WorldInteractionControllerWidget.cs @@ -255,12 +255,12 @@ namespace OpenRA.Mods.Common.Widgets // Check if selecting actors on the screen has selected new units if (ownUnitsOnScreen.Count > World.Selection.Actors.Count()) - Game.AddChatLine(Color.White, "Battlefield Control", "Selected across screen"); + Game.AddSystemLine("Battlefield Control", "Selected across screen"); else { // Select actors in the world that have highest selection priority ownUnitsOnScreen = SelectActorsInWorld(World, null, player).SubsetWithHighestSelectionPriority().ToList(); - Game.AddChatLine(Color.White, "Battlefield Control", "Selected across map"); + Game.AddSystemLine("Battlefield Control", "Selected across map"); } World.Selection.Combine(World, ownUnitsOnScreen, false, false); @@ -281,12 +281,12 @@ namespace OpenRA.Mods.Common.Widgets // Check if selecting actors on the screen has selected new units if (newSelection.Count > World.Selection.Actors.Count()) - Game.AddChatLine(Color.White, "Battlefield Control", "Selected across screen"); + Game.AddSystemLine("Battlefield Control", "Selected across screen"); else { // Select actors in the world that have the same selection class as one of the already selected actors newSelection = SelectActorsInWorld(World, selectedClasses, player).ToList(); - Game.AddChatLine(Color.White, "Battlefield Control", "Selected across map"); + Game.AddSystemLine("Battlefield Control", "Selected across map"); } World.Selection.Combine(World, newSelection, true, false); diff --git a/mods/cnc/metrics.yaml b/mods/cnc/metrics.yaml index 6fd88eb70d..98e12977dd 100644 --- a/mods/cnc/metrics.yaml +++ b/mods/cnc/metrics.yaml @@ -10,3 +10,5 @@ Metrics: ChatLineSound: ChatLine ClickDisabledSound: ClickDisabledSound ClickSound: ClickSound + ChatMessageColor: FFFFFF + SystemMessageColor: FFFF00 diff --git a/mods/d2k/metrics.yaml b/mods/d2k/metrics.yaml index 57687d07bd..d438f51505 100644 --- a/mods/d2k/metrics.yaml +++ b/mods/d2k/metrics.yaml @@ -10,3 +10,5 @@ Metrics: ChatLineSound: ChatLine ClickDisabledSound: ClickDisabledSound ClickSound: ClickSound + ChatMessageColor: FFFFFF + SystemMessageColor: FFFF00 diff --git a/mods/ra/metrics.yaml b/mods/ra/metrics.yaml index 9df9256251..a4eafcd2f8 100644 --- a/mods/ra/metrics.yaml +++ b/mods/ra/metrics.yaml @@ -19,3 +19,5 @@ Metrics: ChatLineSound: ChatLine ClickDisabledSound: ClickDisabledSound ClickSound: ClickSound + ChatMessageColor: FFFFFF + SystemMessageColor: FFFF00 diff --git a/mods/ts/metrics.yaml b/mods/ts/metrics.yaml index a424ec2b0e..569a98ac41 100644 --- a/mods/ts/metrics.yaml +++ b/mods/ts/metrics.yaml @@ -6,3 +6,5 @@ Metrics: ChatLineSound: ChatLine ClickDisabledSound: ClickDisabledSound ClickSound: ClickSound + ChatMessageColor: FFFFFF + SystemMessageColor: FFFF00