From 614603089e27d62461617d961fad8d48388168f2 Mon Sep 17 00:00:00 2001 From: Ivaylo Draganov Date: Tue, 13 Dec 2022 11:49:58 +0200 Subject: [PATCH] Define and measure duration for text notifications in milliseconds During a game notification duration should be the same regardless of game speed. Switch to using wall-clock time defined in milliseconds instead of game ticks. Also use the opportunity to rename the field to "Duration" because "RemoveTime" is not so clear. --- ...extNotificationsDisplayWidgetRemoveTime.cs | 39 +++++++++++++++++++ OpenRA.Mods.Common/UpdateRules/UpdatePath.cs | 8 +++- .../Widgets/TextNotificationsDisplayWidget.cs | 10 ++--- mods/cnc/chrome/ingame-chat.yaml | 2 +- mods/common/chrome/ingame-chat.yaml | 2 +- mods/common/chrome/ingame-transients.yaml | 2 +- mods/ts/chrome/ingame-transients.yaml | 2 +- 7 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 OpenRA.Mods.Common/UpdateRules/Rules/20221203/TextNotificationsDisplayWidgetRemoveTime.cs diff --git a/OpenRA.Mods.Common/UpdateRules/Rules/20221203/TextNotificationsDisplayWidgetRemoveTime.cs b/OpenRA.Mods.Common/UpdateRules/Rules/20221203/TextNotificationsDisplayWidgetRemoveTime.cs new file mode 100644 index 0000000000..dfb45dbfcf --- /dev/null +++ b/OpenRA.Mods.Common/UpdateRules/Rules/20221203/TextNotificationsDisplayWidgetRemoveTime.cs @@ -0,0 +1,39 @@ +#region Copyright & License Information +/* + * Copyright 2007-2022 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 System.Collections.Generic; + +namespace OpenRA.Mods.Common.UpdateRules.Rules +{ + public class TextNotificationsDisplayWidgetRemoveTime : UpdateRule + { + public override string Name => "Change name and unit of RemoveTime field of TextNotificationsDisplayWidget."; + + public override string Description => + "Change the field name from RemoveTime to DisplayDurationMs and convert the value from ticks to milliseconds"; + + public override IEnumerable UpdateChromeNode(ModData modData, MiniYamlNode chromeNode) + { + if (!chromeNode.KeyMatches("TextNotificationsDisplay")) + yield break; + + foreach (var field in chromeNode.ChildrenMatching("RemoveTime")) + { + field.RenameKey("DisplayDurationMs"); + + var durationMilliseconds = field.NodeValue() * 40; + field.ReplaceValue(FieldSaver.FormatValue(durationMilliseconds)); + } + + yield break; + } + } +} diff --git a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs index d4731567a2..e5465bd55c 100644 --- a/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs +++ b/OpenRA.Mods.Common/UpdateRules/UpdatePath.cs @@ -72,9 +72,8 @@ namespace OpenRA.Mods.Common.UpdateRules new RemoveLaysTerrain(), }), - new UpdatePath("release-20210321", new UpdateRule[] + new UpdatePath("release-20210321", "playtest-20221203", new UpdateRule[] { - // Bleed only changes here new RenameMPTraits(), new RemovePlayerHighlightPalette(), new ReplaceWithColoredOverlayPalette(), @@ -97,6 +96,11 @@ namespace OpenRA.Mods.Common.UpdateRules new UnhardcodeBaseBuilderBotModule(), new UnhardcodeVeteranProductionIconOverlay(), new RenameContrailProperties(), + }), + + new UpdatePath("playtest-20221203", new UpdateRule[] + { + new TextNotificationsDisplayWidgetRemoveTime(), }) }; diff --git a/OpenRA.Mods.Common/Widgets/TextNotificationsDisplayWidget.cs b/OpenRA.Mods.Common/Widgets/TextNotificationsDisplayWidget.cs index 31a616ba24..72261ccb38 100644 --- a/OpenRA.Mods.Common/Widgets/TextNotificationsDisplayWidget.cs +++ b/OpenRA.Mods.Common/Widgets/TextNotificationsDisplayWidget.cs @@ -18,7 +18,7 @@ namespace OpenRA.Mods.Common.Widgets { public class TextNotificationsDisplayWidget : Widget { - public readonly int RemoveTime = 0; + public readonly int DisplayDurationMs = 0; public readonly int ItemSpacing = 4; public readonly int BottomSpacing = 0; public readonly int LogLength = 8; @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Widgets public string TransientsTemplate = "TRANSIENT_LINE_TEMPLATE"; readonly Dictionary templates = new Dictionary(); - readonly List expirations = new List(); + readonly List expirations = new List(); Rectangle overflowDrawBounds = Rectangle.Empty; public override Rectangle EventBounds => Rectangle.Empty; @@ -96,7 +96,7 @@ namespace OpenRA.Mods.Common.Widgets } AddChild(notificationWidget); - expirations.Add(Game.LocalTick + RemoveTime); + expirations.Add(Game.RunTime + DisplayDurationMs); while (Children.Count > LogLength) RemoveNotification(); @@ -127,11 +127,11 @@ namespace OpenRA.Mods.Common.Widgets public override void Tick() { - if (RemoveTime == 0) + if (DisplayDurationMs == 0) return; // This takes advantage of the fact that recentLines is ordered by expiration, from sooner to later - while (Children.Count > 0 && Game.LocalTick >= expirations[0]) + while (Children.Count > 0 && Game.RunTime >= expirations[0]) RemoveNotification(); } } diff --git a/mods/cnc/chrome/ingame-chat.yaml b/mods/cnc/chrome/ingame-chat.yaml index bc0b3293bd..10534417d8 100644 --- a/mods/cnc/chrome/ingame-chat.yaml +++ b/mods/cnc/chrome/ingame-chat.yaml @@ -19,7 +19,7 @@ Container@CHAT_PANEL: TextNotificationsDisplay@CHAT_DISPLAY: Width: PARENT_RIGHT Height: PARENT_BOTTOM - RemoveTime: 250 + DisplayDurationMs: 10000 BottomSpacing: 3 Container@CHAT_CHROME: Width: PARENT_RIGHT diff --git a/mods/common/chrome/ingame-chat.yaml b/mods/common/chrome/ingame-chat.yaml index 0d2a819c4e..c2b26a93da 100644 --- a/mods/common/chrome/ingame-chat.yaml +++ b/mods/common/chrome/ingame-chat.yaml @@ -19,7 +19,7 @@ Container@CHAT_PANEL: TextNotificationsDisplay@CHAT_DISPLAY: Width: PARENT_RIGHT Height: PARENT_BOTTOM - RemoveTime: 250 + DisplayDurationMs: 10000 BottomSpacing: 3 Container@CHAT_CHROME: Width: PARENT_RIGHT diff --git a/mods/common/chrome/ingame-transients.yaml b/mods/common/chrome/ingame-transients.yaml index b6f3313ae4..df5124ec08 100644 --- a/mods/common/chrome/ingame-transients.yaml +++ b/mods/common/chrome/ingame-transients.yaml @@ -8,6 +8,6 @@ Container@TRANSIENTS_PANEL: TextNotificationsDisplay@TRANSIENTS_DISPLAY: Width: PARENT_RIGHT Height: PARENT_BOTTOM - RemoveTime: 100 + DisplayDurationMs: 4000 LogLength: 5 HideOverflow: False diff --git a/mods/ts/chrome/ingame-transients.yaml b/mods/ts/chrome/ingame-transients.yaml index b3a36878f1..dbfafeffec 100644 --- a/mods/ts/chrome/ingame-transients.yaml +++ b/mods/ts/chrome/ingame-transients.yaml @@ -8,6 +8,6 @@ Container@TRANSIENTS_PANEL: TextNotificationsDisplay@TRANSIENTS_DISPLAY: Width: PARENT_RIGHT Height: PARENT_BOTTOM - RemoveTime: 100 + DisplayDurationMs: 4000 LogLength: 5 HideOverflow: False