Rework chat line templates and logic

- Extract chat line templates and logic so they can be reused across widgets
- Make text notification styling entirely template driven (by removing chat color configuration and making color optional for `TextNotification`)
- Add a new TextNotificationsDisplay widget (based on and replacing ChatDisplayWidget)
- Add timestamp support to text notifications
This commit is contained in:
Ivaylo Draganov
2021-06-15 17:32:21 +03:00
committed by Matthias Mailänder
parent 8416dc3f2d
commit 9e92340ea7
20 changed files with 330 additions and 363 deletions

View File

@@ -21,16 +21,18 @@ namespace OpenRA
public readonly TextNotificationPool Pool;
public readonly string Prefix;
public readonly string Text;
public readonly Color PrefixColor;
public readonly Color TextColor;
public readonly Color? PrefixColor;
public readonly Color? TextColor;
public readonly DateTime Time;
public TextNotification(TextNotificationPool pool, string prefix, string text, Color prefixColor, Color textColor)
public TextNotification(TextNotificationPool pool, string prefix, string text, Color? prefixColor, Color? textColor)
{
Pool = pool;
Prefix = prefix;
Text = text;
PrefixColor = prefixColor;
TextColor = textColor;
Time = DateTime.Now;
}
public bool CanIncrementOnDuplicate()
@@ -38,19 +40,17 @@ namespace OpenRA
return Pool == TextNotificationPool.Feedback || Pool == TextNotificationPool.System;
}
public bool Equals(TextNotification other)
{
return other != null && other.GetHashCode() == GetHashCode();
}
public static bool operator ==(TextNotification me, TextNotification other) { return me.GetHashCode() == other.GetHashCode(); }
public override bool Equals(object obj)
{
return obj is TextNotification && Equals((TextNotification)obj);
}
public static bool operator !=(TextNotification me, TextNotification other) { return !(me == other); }
public bool Equals(TextNotification other) { return other == this; }
public override bool Equals(object obj) { return obj is TextNotification notification && Equals(notification); }
public override int GetHashCode()
{
return string.Format("{0}{1}{2}", Prefix, Text, Pool).GetHashCode();
return HashCode.Combine(Prefix, Text, (int)Pool);
}
}
}

View File

@@ -16,33 +16,29 @@ namespace OpenRA
{
public static class TextNotificationsManager
{
static Color systemMessageColor = Color.White;
static Color chatMessageColor = Color.White;
static string systemMessageLabel;
static readonly string SystemMessageLabel;
public static long ChatDisabledUntil { get; internal set; }
static TextNotificationsManager()
{
ChromeMetrics.TryGet("ChatMessageColor", out chatMessageColor);
ChromeMetrics.TryGet("SystemMessageColor", out systemMessageColor);
if (!ChromeMetrics.TryGet("SystemMessageLabel", out systemMessageLabel))
systemMessageLabel = "Battlefield Control";
if (!ChromeMetrics.TryGet("SystemMessageLabel", out SystemMessageLabel))
SystemMessageLabel = "Battlefield Control";
}
public static void AddFeedbackLine(string text)
{
AddTextNotification(TextNotificationPool.Feedback, systemMessageLabel, text, systemMessageColor, systemMessageColor);
AddTextNotification(TextNotificationPool.Feedback, SystemMessageLabel, text);
}
public static void AddSystemLine(string text)
{
AddSystemLine(systemMessageLabel, text);
AddSystemLine(SystemMessageLabel, text);
}
public static void AddSystemLine(string prefix, string text)
{
AddTextNotification(TextNotificationPool.System, prefix, text, systemMessageColor, systemMessageColor);
AddTextNotification(TextNotificationPool.System, prefix, text);
}
public static void AddChatLine(string prefix, string text, Color? prefixColor = null, Color? textColor = null)
@@ -58,7 +54,7 @@ namespace OpenRA
static void AddTextNotification(TextNotificationPool pool, string prefix, string text, Color? prefixColor = null, Color? textColor = null)
{
if (IsPoolEnabled(pool))
Game.OrderManager.AddTextNotification(new TextNotification(pool, prefix, text, prefixColor ?? chatMessageColor, textColor ?? chatMessageColor));
Game.OrderManager.AddTextNotification(new TextNotification(pool, prefix, text, prefixColor, textColor));
}
static bool IsPoolEnabled(TextNotificationPool pool)