From a1e6ac85dccb83eb373d8b6da9b3903a14d55d8f Mon Sep 17 00:00:00 2001 From: Ivaylo Draganov Date: Fri, 29 Apr 2022 15:01:33 +0300 Subject: [PATCH] Add transient notifications pool --- OpenRA.Game/Settings.cs | 5 +++-- OpenRA.Game/TextNotification.cs | 4 ++-- OpenRA.Game/TextNotificationsManager.cs | 9 +++++++++ .../Logic/Ingame/IngameTransientNotificationsLogic.cs | 2 +- .../Widgets/TextNotificationsDisplayWidget.cs | 2 ++ 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index 9f501fda47..2af30ac3ba 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -37,7 +37,8 @@ namespace OpenRA public enum TextNotificationPoolFilters { None = 0, - Feedback = 1 + Feedback = 1, + Transients = 2 } public enum WorldViewport { Native, Close, Medium, Far } @@ -273,7 +274,7 @@ namespace OpenRA [Desc("Allow mods to enable the Discord service that can interact with a local Discord client.")] public bool EnableDiscordService = true; - public TextNotificationPoolFilters TextNotificationPoolFilters = TextNotificationPoolFilters.Feedback; + public TextNotificationPoolFilters TextNotificationPoolFilters = TextNotificationPoolFilters.Feedback | TextNotificationPoolFilters.Transients; } public class Settings diff --git a/OpenRA.Game/TextNotification.cs b/OpenRA.Game/TextNotification.cs index 8440cc6395..25d02618e1 100644 --- a/OpenRA.Game/TextNotification.cs +++ b/OpenRA.Game/TextNotification.cs @@ -14,7 +14,7 @@ using OpenRA.Primitives; namespace OpenRA { - public enum TextNotificationPool { System, Chat, Mission, Feedback } + public enum TextNotificationPool { System, Chat, Mission, Feedback, Transients } public class TextNotification : IEquatable { @@ -37,7 +37,7 @@ namespace OpenRA public bool CanIncrementOnDuplicate() { - return Pool == TextNotificationPool.Feedback || Pool == TextNotificationPool.System; + return Pool == TextNotificationPool.Feedback || Pool == TextNotificationPool.System || Pool == TextNotificationPool.Transients; } public static bool operator ==(TextNotification me, TextNotification other) { return me.GetHashCode() == other.GetHashCode(); } diff --git a/OpenRA.Game/TextNotificationsManager.cs b/OpenRA.Game/TextNotificationsManager.cs index d1e2b965d7..46aacbcab5 100644 --- a/OpenRA.Game/TextNotificationsManager.cs +++ b/OpenRA.Game/TextNotificationsManager.cs @@ -26,6 +26,14 @@ namespace OpenRA SystemMessageLabel = "Battlefield Control"; } + public static void AddTransientLine(string text) + { + if (string.IsNullOrEmpty(text)) + return; + + AddTextNotification(TextNotificationPool.Transients, SystemMessageLabel, text); + } + public static void AddFeedbackLine(string text) { AddTextNotification(TextNotificationPool.Feedback, SystemMessageLabel, text); @@ -69,6 +77,7 @@ namespace OpenRA return pool == TextNotificationPool.Chat || pool == TextNotificationPool.System || pool == TextNotificationPool.Mission || + (pool == TextNotificationPool.Transients && filters.HasFlag(TextNotificationPoolFilters.Transients)) || (pool == TextNotificationPool.Feedback && filters.HasFlag(TextNotificationPoolFilters.Feedback)); } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameTransientNotificationsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameTransientNotificationsLogic.cs index ab89de9895..4084d72472 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameTransientNotificationsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameTransientNotificationsLogic.cs @@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic static bool IsNotificationEligible(TextNotification notification) { - return notification.Pool == TextNotificationPool.Feedback; + return notification.Pool == TextNotificationPool.Transients || notification.Pool == TextNotificationPool.Feedback; } bool disposed = false; diff --git a/OpenRA.Mods.Common/Widgets/TextNotificationsDisplayWidget.cs b/OpenRA.Mods.Common/Widgets/TextNotificationsDisplayWidget.cs index e940b360b6..5e725235e3 100644 --- a/OpenRA.Mods.Common/Widgets/TextNotificationsDisplayWidget.cs +++ b/OpenRA.Mods.Common/Widgets/TextNotificationsDisplayWidget.cs @@ -28,6 +28,7 @@ namespace OpenRA.Mods.Common.Widgets public string SystemTemplate = "SYSTEM_LINE_TEMPLATE"; public string MissionTemplate = "CHAT_LINE_TEMPLATE"; public string FeedbackTemplate = "TRANSIENT_LINE_TEMPLATE"; + public string TransientsTemplate = "TRANSIENT_LINE_TEMPLATE"; readonly Dictionary templates = new Dictionary(); readonly List expirations = new List(); @@ -43,6 +44,7 @@ namespace OpenRA.Mods.Common.Widgets templates.Add(TextNotificationPool.System, Ui.LoadWidget(SystemTemplate, null, new WidgetArgs())); templates.Add(TextNotificationPool.Mission, Ui.LoadWidget(MissionTemplate, null, new WidgetArgs())); templates.Add(TextNotificationPool.Feedback, Ui.LoadWidget(FeedbackTemplate, null, new WidgetArgs())); + templates.Add(TextNotificationPool.Transients, Ui.LoadWidget(TransientsTemplate, null, new WidgetArgs())); // HACK: Assume that all templates use the same font var lineHeight = Game.Renderer.Fonts[templates[TextNotificationPool.Chat].Get("TEXT").Font].Measure("").Y;