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

@@ -21,9 +21,8 @@ using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic
{
[ChromeLogicArgsHotkeys("OpenTeamChat", "OpenGeneralChat")]
public class IngameChatLogic : ChromeLogic
public class IngameChatLogic : ChromeLogic, INotificationHandler<TextNotification>
{
readonly OrderManager orderManager;
readonly Ruleset modRules;
readonly World world;
@@ -47,7 +46,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
[ObjectCreator.UseCtor]
public IngameChatLogic(Widget widget, OrderManager orderManager, World world, ModData modData, bool isMenuChat, Dictionary<string, MiniYaml> logicArgs)
{
this.orderManager = orderManager;
modRules = modData.DefaultRules;
this.isMenuChat = isMenuChat;
this.world = world;
@@ -209,12 +207,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
chatScrollPanel.RemoveChildren();
chatScrollPanel.ScrollToBottom();
foreach (var notification in orderManager.NotificationsCache)
foreach (var notification in TextNotificationsManager.Notifications)
if (IsNotificationEligible(notification))
AddNotification(notification, true);
orderManager.AddTextNotification += AddNotificationWrapper;
chatText.IsDisabled = () => !chatEnabled || (world.IsReplay && !Game.Settings.Debug.EnableDebugCommandsInReplays);
if (!isMenuChat)
@@ -260,7 +256,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Ui.ResetTooltips();
}
public void AddNotificationWrapper(TextNotification notification)
void INotificationHandler<TextNotification>.Handle(TextNotification notification)
{
if (!IsNotificationEligible(notification))
return;
@@ -315,18 +311,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
notification.Pool == TextNotificationPool.Mission;
}
bool disposed = false;
protected override void Dispose(bool disposing)
{
if (!disposed)
{
orderManager.AddTextNotification -= AddNotificationWrapper;
disposed = true;
}
base.Dispose(disposing);
}
bool IsNotificationMuted(TextNotification notification)
{
return Game.Settings.Game.HideReplayChat && world.IsReplay && notification.ClientId != TextNotificationsManager.SystemClientId;

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);
}
}
}

View File

@@ -20,7 +20,7 @@ using OpenRA.Widgets;
namespace OpenRA.Mods.Common.Widgets.Logic
{
public class LobbyLogic : ChromeLogic
public class LobbyLogic : ChromeLogic, INotificationHandler<TextNotification>
{
static readonly Action DoNothing = () => { };
@@ -125,7 +125,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
services = modData.Manifest.Get<WebServices>();
orderManager.AddTextNotification += AddChatLine;
Game.LobbyInfoChanged += UpdateCurrentMap;
Game.LobbyInfoChanged += UpdatePlayerList;
Game.LobbyInfoChanged += UpdateDiscordStatus;
@@ -493,7 +492,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
if (disposing && !disposed)
{
disposed = true;
orderManager.AddTextNotification -= AddChatLine;
Game.LobbyInfoChanged -= UpdateCurrentMap;
Game.LobbyInfoChanged -= UpdatePlayerList;
Game.LobbyInfoChanged -= UpdateDiscordStatus;
@@ -535,7 +533,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
}
}
void AddChatLine(TextNotification notification)
void INotificationHandler<TextNotification>.Handle(TextNotification notification)
{
var chatLine = chatTemplates[notification.Pool].Clone();
WidgetUtils.SetupTextNotification(chatLine, notification, lobbyChatPanel.Bounds.Width - lobbyChatPanel.ScrollbarWidth, true);