Update TextNotificationsManager to use Ui.Send

This commit is contained in:
tomas
2022-07-12 17:46:20 +02:00
committed by Gustas
parent b0329aad35
commit 5f4ed5f16b
6 changed files with 25 additions and 55 deletions

View File

@@ -10,14 +10,12 @@
#endregion
using System.Collections.Generic;
using OpenRA.Network;
using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic
{
public class IngameTransientNotificationsLogic : ChromeLogic
public class IngameTransientNotificationsLogic : ChromeLogic, INotificationHandler<TextNotification>
{
readonly OrderManager orderManager;
readonly Ruleset modRules;
readonly TextNotificationsDisplayWidget displayWidget;
@@ -28,22 +26,19 @@ namespace OpenRA.Mods.Common.Widgets.Logic
int repetitions;
[ObjectCreator.UseCtor]
public IngameTransientNotificationsLogic(Widget widget, OrderManager orderManager, ModData modData, Dictionary<string, MiniYaml> logicArgs)
public IngameTransientNotificationsLogic(Widget widget, ModData modData, Dictionary<string, MiniYaml> logicArgs)
{
this.orderManager = orderManager;
modRules = modData.DefaultRules;
displayWidget = widget.Get<TextNotificationsDisplayWidget>("TRANSIENTS_DISPLAY");
orderManager.AddTextNotification += AddNotificationWrapper;
if (logicArgs.TryGetValue("TransientLineSound", out var yaml))
transientLineSound = yaml.Value;
else
ChromeMetrics.TryGet("TransientLineSound", out transientLineSound);
}
public void AddNotificationWrapper(TextNotification notification)
void INotificationHandler<TextNotification>.Handle(TextNotification notification)
{
if (!IsNotificationEligible(notification))
return;
@@ -83,17 +78,5 @@ namespace OpenRA.Mods.Common.Widgets.Logic
{
return notification.Pool == TextNotificationPool.Transients || notification.Pool == TextNotificationPool.Feedback;
}
bool disposed = false;
protected override void Dispose(bool disposing)
{
if (!disposed)
{
orderManager.AddTextNotification -= AddNotificationWrapper;
disposed = true;
}
base.Dispose(disposing);
}
}
}