System messages should be yellow to distinguish them from normal

This commit is contained in:
teinarss
2019-03-27 19:17:02 +01:00
committed by abcdefg30
parent db487e1264
commit d9d2202599
16 changed files with 87 additions and 61 deletions

View File

@@ -465,6 +465,9 @@ namespace OpenRA
Log.Write("nat", e.ToString());
}
chatMessageColor = ChromeMetrics.Get<Color>("ChatMessageColor");
systemMessageColor = ChromeMetrics.Get<Color>("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()

View File

@@ -105,10 +105,10 @@ namespace OpenRA.Network
localOrders.Add(order);
}
public Action<Color, string, string> AddChatLine = (c, n, s) => { };
void CacheChatLine(Color color, string name, string text)
public Action<string, Color, string, Color> 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;
}
}
}

View File

@@ -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<int>("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<INotifyGameSaved>())
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;

View File

@@ -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.")]

View File

@@ -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)

View File

@@ -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)

View File

@@ -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;
}
}
}

View File

@@ -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<LabelWidget>("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;

View File

@@ -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);

View File

@@ -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<LabelWidget>("NAME");
var timeLabel = template.Get<LabelWidget>("TIME");
var textLabel = template.Get<LabelWidget>("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;

View File

@@ -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;

View File

@@ -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);

View File

@@ -10,3 +10,5 @@ Metrics:
ChatLineSound: ChatLine
ClickDisabledSound: ClickDisabledSound
ClickSound: ClickSound
ChatMessageColor: FFFFFF
SystemMessageColor: FFFF00

View File

@@ -10,3 +10,5 @@ Metrics:
ChatLineSound: ChatLine
ClickDisabledSound: ClickDisabledSound
ClickSound: ClickSound
ChatMessageColor: FFFFFF
SystemMessageColor: FFFF00

View File

@@ -19,3 +19,5 @@ Metrics:
ChatLineSound: ChatLine
ClickDisabledSound: ClickDisabledSound
ClickSound: ClickSound
ChatMessageColor: FFFFFF
SystemMessageColor: FFFF00

View File

@@ -6,3 +6,5 @@ Metrics:
ChatLineSound: ChatLine
ClickDisabledSound: ClickDisabledSound
ClickSound: ClickSound
ChatMessageColor: FFFFFF
SystemMessageColor: FFFF00