Add a transients panel with corresponding chrome logic and a notification template
This commit is contained in:
committed by
Matthias Mailänder
parent
9e92340ea7
commit
01d47566cc
@@ -40,8 +40,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
|
||||
readonly string chatLineSound = ChromeMetrics.Get<string>("ChatLineSound");
|
||||
|
||||
TextNotification lastLine;
|
||||
int repetitions;
|
||||
bool chatEnabled;
|
||||
|
||||
readonly bool isMenuChat;
|
||||
@@ -211,8 +209,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
chatScrollPanel.RemoveChildren();
|
||||
chatScrollPanel.ScrollToBottom();
|
||||
|
||||
foreach (var chatLine in orderManager.NotificationsCache)
|
||||
AddChatLine(chatLine, true);
|
||||
foreach (var notification in orderManager.NotificationsCache)
|
||||
if (IsNotificationEligible(notification))
|
||||
AddNotification(notification, true);
|
||||
|
||||
orderManager.AddTextNotification += AddNotificationWrapper;
|
||||
|
||||
@@ -261,36 +260,19 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
Ui.ResetTooltips();
|
||||
}
|
||||
|
||||
public void AddNotificationWrapper(TextNotification chatLine)
|
||||
public void AddNotificationWrapper(TextNotification notification)
|
||||
{
|
||||
var chatLineToDisplay = chatLine;
|
||||
if (!IsNotificationEligible(notification))
|
||||
return;
|
||||
|
||||
if (chatLine.CanIncrementOnDuplicate() && chatLine.Equals(lastLine))
|
||||
{
|
||||
repetitions++;
|
||||
chatLineToDisplay = new TextNotification(
|
||||
chatLine.Pool,
|
||||
chatLine.Prefix,
|
||||
$"{chatLine.Text} ({repetitions + 1})",
|
||||
chatLine.PrefixColor,
|
||||
chatLine.TextColor);
|
||||
|
||||
chatScrollPanel.RemoveChild(chatScrollPanel.Children[chatScrollPanel.Children.Count - 1]);
|
||||
chatOverlayDisplay?.RemoveMostRecentNotification();
|
||||
}
|
||||
else
|
||||
repetitions = 0;
|
||||
|
||||
lastLine = chatLine;
|
||||
|
||||
chatOverlayDisplay?.AddNotification(chatLineToDisplay);
|
||||
chatOverlayDisplay?.AddNotification(notification);
|
||||
|
||||
// HACK: Force disable the chat notification sound for the in-menu chat dialog
|
||||
// This works around our inability to disable the sounds for the in-game dialog when it is hidden
|
||||
AddChatLine(chatLineToDisplay, chatOverlay == null);
|
||||
AddNotification(notification, chatOverlay == null);
|
||||
}
|
||||
|
||||
void AddChatLine(TextNotification notification, bool suppressSound)
|
||||
void AddNotification(TextNotification notification, bool suppressSound)
|
||||
{
|
||||
var chatLine = templates[notification.Pool].Clone();
|
||||
WidgetUtils.SetupTextNotification(chatLine, notification, chatScrollPanel.Bounds.Width - chatScrollPanel.ScrollbarWidth, isMenuChat && !world.IsReplay);
|
||||
@@ -325,6 +307,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsNotificationEligible(TextNotification notification)
|
||||
{
|
||||
return notification.Pool == TextNotificationPool.Chat ||
|
||||
notification.Pool == TextNotificationPool.System ||
|
||||
notification.Pool == TextNotificationPool.Mission;
|
||||
}
|
||||
|
||||
bool disposed = false;
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2021 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;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
public class IngameTransientNotificationsLogic : ChromeLogic
|
||||
{
|
||||
readonly OrderManager orderManager;
|
||||
readonly Ruleset modRules;
|
||||
|
||||
readonly TextNotificationsDisplayWidget displayWidget;
|
||||
|
||||
readonly string transientLineSound;
|
||||
|
||||
TextNotification lastLine;
|
||||
int repetitions;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public IngameTransientNotificationsLogic(Widget widget, OrderManager orderManager, 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)
|
||||
{
|
||||
if (!IsNotificationEligible(notification))
|
||||
return;
|
||||
|
||||
var lineToDisplay = notification;
|
||||
|
||||
if (displayWidget.Children.Count > 0 && notification.CanIncrementOnDuplicate() && notification == lastLine)
|
||||
{
|
||||
repetitions++;
|
||||
lineToDisplay = new TextNotification(
|
||||
notification.Pool,
|
||||
notification.Prefix,
|
||||
$"{notification.Text} ({repetitions + 1})",
|
||||
notification.PrefixColor,
|
||||
notification.TextColor);
|
||||
|
||||
displayWidget.RemoveMostRecentNotification();
|
||||
}
|
||||
else
|
||||
repetitions = 0;
|
||||
|
||||
lastLine = notification;
|
||||
|
||||
AddNotification(lineToDisplay);
|
||||
}
|
||||
|
||||
void AddNotification(TextNotification notification, bool suppressSound = false)
|
||||
{
|
||||
displayWidget.AddNotification(notification);
|
||||
|
||||
if (!suppressSound && !string.IsNullOrEmpty(transientLineSound))
|
||||
Game.Sound.PlayNotification(modRules, null, "Sounds", transientLineSound, null);
|
||||
}
|
||||
|
||||
static bool IsNotificationEligible(TextNotification notification)
|
||||
{
|
||||
return notification.Pool == TextNotificationPool.Feedback;
|
||||
}
|
||||
|
||||
bool disposed = false;
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposed)
|
||||
{
|
||||
orderManager.AddTextNotification -= AddNotificationWrapper;
|
||||
disposed = true;
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,6 +54,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
|
||||
Game.LoadWidget(world, "DEBUG_WIDGETS", worldRoot, new WidgetArgs());
|
||||
Game.LoadWidget(world, "TRANSIENTS_PANEL", worldRoot, new WidgetArgs());
|
||||
|
||||
world.GameOver += () =>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user