Move Text handling to its own class
This commit is contained in:
@@ -474,11 +474,6 @@ namespace OpenRA
|
||||
|
||||
JoinLocal();
|
||||
|
||||
ChromeMetrics.TryGet("ChatMessageColor", out chatMessageColor);
|
||||
ChromeMetrics.TryGet("SystemMessageColor", out systemMessageColor);
|
||||
if (!ChromeMetrics.TryGet("SystemMessageLabel", out systemMessageLabel))
|
||||
systemMessageLabel = "Battlefield Control";
|
||||
|
||||
ModData.LoadScreen.StartGame(args);
|
||||
}
|
||||
|
||||
@@ -559,9 +554,6 @@ 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 = Color.White;
|
||||
static Color chatMessageColor = Color.White;
|
||||
static string systemMessageLabel;
|
||||
|
||||
public static void RunAfterTick(Action a) { delayedActions.Add(a, RunTime); }
|
||||
public static void RunAfterDelay(int delayMilliseconds, Action a) { delayedActions.Add(a, RunTime + delayMilliseconds); }
|
||||
@@ -579,7 +571,7 @@ namespace OpenRA
|
||||
Log.Write("debug", "Taking screenshot " + path);
|
||||
|
||||
Renderer.SaveScreenshot(path);
|
||||
Debug("Saved screenshot " + filename);
|
||||
TextNotificationsManager.Debug("Saved screenshot " + filename);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -911,26 +903,6 @@ namespace OpenRA
|
||||
state = RunStatus.Success;
|
||||
}
|
||||
|
||||
public static void AddSystemLine(string text)
|
||||
{
|
||||
AddSystemLine(systemMessageLabel, text);
|
||||
}
|
||||
|
||||
public static void AddSystemLine(string name, string 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)
|
||||
{
|
||||
AddSystemLine("Debug", string.Format(s, args));
|
||||
}
|
||||
|
||||
public static void Disconnect()
|
||||
{
|
||||
OrderManager.World?.TraitDict.PrintReport();
|
||||
|
||||
@@ -212,8 +212,8 @@ namespace OpenRA
|
||||
Log.Write("debug", e.ToString());
|
||||
|
||||
// HACK: this can hopefully go away in the future
|
||||
Game.Debug("Ignoring malformed order that would have crashed the game");
|
||||
Game.Debug("Please file a bug report and include the replay from this match");
|
||||
TextNotificationsManager.Debug("Ignoring malformed order that would have crashed the game");
|
||||
TextNotificationsManager.Debug("Please file a bug report and include the replay from this match");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace OpenRA.Network
|
||||
{
|
||||
// Server message
|
||||
case "Message":
|
||||
Game.AddSystemLine(order.TargetString);
|
||||
TextNotificationsManager.AddSystemLine(order.TargetString);
|
||||
break;
|
||||
|
||||
// Reports that the target player disconnected
|
||||
@@ -70,7 +70,7 @@ namespace OpenRA.Network
|
||||
if (orderManager.LocalClient != null && client != orderManager.LocalClient && client.Team > 0 && client.Team == orderManager.LocalClient.Team)
|
||||
suffix += " (Ally)";
|
||||
|
||||
Game.AddChatLine(client.Name + suffix, client.Color, message);
|
||||
TextNotificationsManager.AddChatLine(client.Name + suffix, client.Color, message);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace OpenRA.Network
|
||||
{
|
||||
var prefix = order.ExtraData == uint.MaxValue ? "[Spectators] " : "[Team] ";
|
||||
if (orderManager.LocalClient != null && client.Team == orderManager.LocalClient.Team)
|
||||
Game.AddChatLine(prefix + client.Name, client.Color, message);
|
||||
TextNotificationsManager.AddChatLine(prefix + client.Name, client.Color, message);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -93,7 +93,7 @@ namespace OpenRA.Network
|
||||
{
|
||||
// Validate before adding the line
|
||||
if (client.IsObserver || (player != null && player.WinState != WinState.Undefined))
|
||||
Game.AddChatLine("[Spectators] " + client.Name, client.Color, message);
|
||||
TextNotificationsManager.AddChatLine("[Spectators] " + client.Name, client.Color, message);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -103,7 +103,7 @@ namespace OpenRA.Network
|
||||
&& world.LocalPlayer != null && world.LocalPlayer.WinState == WinState.Undefined;
|
||||
|
||||
if (valid && (isSameTeam || world.IsReplay))
|
||||
Game.AddChatLine("[Team" + (world.IsReplay ? " " + order.ExtraData : "") + "] " + client.Name, client.Color, message);
|
||||
TextNotificationsManager.AddChatLine("[Team" + (world.IsReplay ? " " + order.ExtraData : "") + "] " + client.Name, client.Color, message);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -133,7 +133,7 @@ namespace OpenRA.Network
|
||||
FieldLoader.GetValue<int>("SaveSyncFrame", saveSyncFrame.Value.Value);
|
||||
}
|
||||
else
|
||||
Game.AddSystemLine("The game has started.");
|
||||
TextNotificationsManager.AddSystemLine("The game has started.");
|
||||
|
||||
Game.StartGame(orderManager.LobbyInfo.GlobalSettings.Map, WorldType.Regular);
|
||||
break;
|
||||
@@ -151,7 +151,7 @@ namespace OpenRA.Network
|
||||
|
||||
case "GameSaved":
|
||||
if (!orderManager.World.IsReplay)
|
||||
Game.AddSystemLine("Game saved");
|
||||
TextNotificationsManager.AddSystemLine("Game saved");
|
||||
|
||||
foreach (var nsr in orderManager.World.WorldActor.TraitsImplementing<INotifyGameSaved>())
|
||||
nsr.GameSaved(orderManager.World);
|
||||
@@ -171,7 +171,7 @@ namespace OpenRA.Network
|
||||
if (orderManager.World.Paused != pause && world != null && world.LobbyInfo.NonBotClients.Count() > 1)
|
||||
{
|
||||
var pausetext = $"The game is {(pause ? "paused" : "un-paused")} by {client.Name}";
|
||||
Game.AddSystemLine(pausetext);
|
||||
TextNotificationsManager.AddSystemLine(pausetext);
|
||||
}
|
||||
|
||||
orderManager.World.Paused = pause;
|
||||
|
||||
@@ -188,9 +188,9 @@ namespace OpenRA.Orders
|
||||
static Order CheckSameOrder(IOrderTargeter iot, Order order)
|
||||
{
|
||||
if (order == null && iot.OrderID != null)
|
||||
Game.Debug("BUG: in order targeter - decided on {0} but then didn't order", iot.OrderID);
|
||||
TextNotificationsManager.Debug("BUG: in order targeter - decided on {0} but then didn't order", iot.OrderID);
|
||||
else if (order != null && iot.OrderID != order.OrderString)
|
||||
Game.Debug("BUG: in order targeter - decided on {0} but ordered {1}", iot.OrderID, order.OrderString);
|
||||
TextNotificationsManager.Debug("BUG: in order targeter - decided on {0} but ordered {1}", iot.OrderID, order.OrderString);
|
||||
return order;
|
||||
}
|
||||
|
||||
|
||||
51
OpenRA.Game/TextNotificationsManager.cs
Normal file
51
OpenRA.Game/TextNotificationsManager.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2021 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of
|
||||
* the License, or (at your option) any later version. For more
|
||||
* information, see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Primitives;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public static class TextNotificationsManager
|
||||
{
|
||||
static Color systemMessageColor = Color.White;
|
||||
static Color chatMessageColor = Color.White;
|
||||
static string systemMessageLabel;
|
||||
|
||||
static TextNotificationsManager()
|
||||
{
|
||||
ChromeMetrics.TryGet("ChatMessageColor", out chatMessageColor);
|
||||
ChromeMetrics.TryGet("SystemMessageColor", out systemMessageColor);
|
||||
if (!ChromeMetrics.TryGet("SystemMessageLabel", out systemMessageLabel))
|
||||
systemMessageLabel = "Battlefield Control";
|
||||
}
|
||||
|
||||
public static void AddSystemLine(string text)
|
||||
{
|
||||
AddSystemLine(systemMessageLabel, text);
|
||||
}
|
||||
|
||||
public static void AddSystemLine(string name, string text)
|
||||
{
|
||||
Game.OrderManager.AddChatLine(name, systemMessageColor, text, systemMessageColor);
|
||||
}
|
||||
|
||||
public static void AddChatLine(string name, Color nameColor, string text)
|
||||
{
|
||||
Game.OrderManager.AddChatLine(name, nameColor, text, chatMessageColor);
|
||||
}
|
||||
|
||||
public static void Debug(string s, params object[] args)
|
||||
{
|
||||
AddSystemLine("Debug", string.Format(s, args));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -226,7 +226,7 @@ namespace OpenRA
|
||||
|
||||
if (right.TryGetClrValue(out int c))
|
||||
{
|
||||
Game.Debug("Support for facing calculations mixing Angle with integers is deprecated. Make sure all facing calculations use Angle");
|
||||
TextNotificationsManager.Debug("Support for facing calculations mixing Angle with integers is deprecated. Make sure all facing calculations use Angle");
|
||||
return new LuaCustomClrObject(a + FromFacing(c));
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ namespace OpenRA
|
||||
|
||||
if (right.TryGetClrValue(out int c))
|
||||
{
|
||||
Game.Debug("Support for facing calculations mixing Angle with integers is deprecated. Make sure all facing calculations use Angle");
|
||||
TextNotificationsManager.Debug("Support for facing calculations mixing Angle with integers is deprecated. Make sure all facing calculations use Angle");
|
||||
return new LuaCustomClrObject(a - FromFacing(c));
|
||||
}
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace OpenRA
|
||||
switch (key.ToString())
|
||||
{
|
||||
case "Length": return Length;
|
||||
case "Range": Game.Debug("WDist.Range is deprecated. Use WDist.Length instead"); return Length;
|
||||
case "Range": TextNotificationsManager.Debug("WDist.Range is deprecated. Use WDist.Length instead"); return Length;
|
||||
default: throw new LuaException($"WDist does not define a member '{key}'");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user