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");
|
readonly string chatLineSound = ChromeMetrics.Get<string>("ChatLineSound");
|
||||||
|
|
||||||
TextNotification lastLine;
|
|
||||||
int repetitions;
|
|
||||||
bool chatEnabled;
|
bool chatEnabled;
|
||||||
|
|
||||||
readonly bool isMenuChat;
|
readonly bool isMenuChat;
|
||||||
@@ -211,8 +209,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
chatScrollPanel.RemoveChildren();
|
chatScrollPanel.RemoveChildren();
|
||||||
chatScrollPanel.ScrollToBottom();
|
chatScrollPanel.ScrollToBottom();
|
||||||
|
|
||||||
foreach (var chatLine in orderManager.NotificationsCache)
|
foreach (var notification in orderManager.NotificationsCache)
|
||||||
AddChatLine(chatLine, true);
|
if (IsNotificationEligible(notification))
|
||||||
|
AddNotification(notification, true);
|
||||||
|
|
||||||
orderManager.AddTextNotification += AddNotificationWrapper;
|
orderManager.AddTextNotification += AddNotificationWrapper;
|
||||||
|
|
||||||
@@ -261,36 +260,19 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
Ui.ResetTooltips();
|
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))
|
chatOverlayDisplay?.AddNotification(notification);
|
||||||
{
|
|
||||||
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);
|
|
||||||
|
|
||||||
// HACK: Force disable the chat notification sound for the in-menu chat dialog
|
// 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
|
// 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();
|
var chatLine = templates[notification.Pool].Clone();
|
||||||
WidgetUtils.SetupTextNotification(chatLine, notification, chatScrollPanel.Bounds.Width - chatScrollPanel.ScrollbarWidth, isMenuChat && !world.IsReplay);
|
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;
|
bool disposed = false;
|
||||||
protected override void Dispose(bool disposing)
|
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, "DEBUG_WIDGETS", worldRoot, new WidgetArgs());
|
||||||
|
Game.LoadWidget(world, "TRANSIENTS_PANEL", worldRoot, new WidgetArgs());
|
||||||
|
|
||||||
world.GameOver += () =>
|
world.GameOver += () =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
public string ChatTemplate = "CHAT_LINE_TEMPLATE";
|
public string ChatTemplate = "CHAT_LINE_TEMPLATE";
|
||||||
public string SystemTemplate = "SYSTEM_LINE_TEMPLATE";
|
public string SystemTemplate = "SYSTEM_LINE_TEMPLATE";
|
||||||
public string MissionTemplate = "SYSTEM_LINE_TEMPLATE";
|
public string MissionTemplate = "SYSTEM_LINE_TEMPLATE";
|
||||||
public string FeedbackTemplate = "SYSTEM_LINE_TEMPLATE";
|
public string FeedbackTemplate = "TRANSIENT_LINE_TEMPLATE";
|
||||||
readonly Dictionary<TextNotificationPool, Widget> templates = new Dictionary<TextNotificationPool, Widget>();
|
readonly Dictionary<TextNotificationPool, Widget> templates = new Dictionary<TextNotificationPool, Widget>();
|
||||||
|
|
||||||
readonly List<int> expirations = new List<int>();
|
readonly List<int> expirations = new List<int>();
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ Container@CHAT_PANEL:
|
|||||||
Chat: CHAT_LINE_TEMPLATE
|
Chat: CHAT_LINE_TEMPLATE
|
||||||
System: SYSTEM_LINE_TEMPLATE
|
System: SYSTEM_LINE_TEMPLATE
|
||||||
Mission: SYSTEM_LINE_TEMPLATE
|
Mission: SYSTEM_LINE_TEMPLATE
|
||||||
Feedback: SYSTEM_LINE_TEMPLATE
|
|
||||||
Children:
|
Children:
|
||||||
Container@CHAT_OVERLAY:
|
Container@CHAT_OVERLAY:
|
||||||
Width: PARENT_RIGHT - 24
|
Width: PARENT_RIGHT - 24
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ Container@CHAT_CONTAINER:
|
|||||||
Chat: CHAT_LINE_TEMPLATE
|
Chat: CHAT_LINE_TEMPLATE
|
||||||
System: SYSTEM_LINE_TEMPLATE
|
System: SYSTEM_LINE_TEMPLATE
|
||||||
Mission: SYSTEM_LINE_TEMPLATE
|
Mission: SYSTEM_LINE_TEMPLATE
|
||||||
Feedback: SYSTEM_LINE_TEMPLATE
|
|
||||||
Children:
|
Children:
|
||||||
Container@CHAT_CHROME:
|
Container@CHAT_CHROME:
|
||||||
X: 15
|
X: 15
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ Container@PERF_WIDGETS:
|
|||||||
Background@GRAPH_BG:
|
Background@GRAPH_BG:
|
||||||
Logic: AddFactionSuffixLogic
|
Logic: AddFactionSuffixLogic
|
||||||
X: 5
|
X: 5
|
||||||
Y: WINDOW_BOTTOM - HEIGHT - 56
|
Y: WINDOW_BOTTOM - HEIGHT - 156
|
||||||
Width: 220
|
Width: 220
|
||||||
Height: 220
|
Height: 220
|
||||||
Background: panel-black
|
Background: panel-black
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ Container@SERVER_LOBBY:
|
|||||||
Chat: CHAT_LINE_TEMPLATE
|
Chat: CHAT_LINE_TEMPLATE
|
||||||
System: SYSTEM_LINE_TEMPLATE
|
System: SYSTEM_LINE_TEMPLATE
|
||||||
Mission: SYSTEM_LINE_TEMPLATE
|
Mission: SYSTEM_LINE_TEMPLATE
|
||||||
Feedback: SYSTEM_LINE_TEMPLATE
|
Feedback: TRANSIENT_LINE_TEMPLATE
|
||||||
X: (WINDOW_RIGHT - WIDTH) / 2
|
X: (WINDOW_RIGHT - WIDTH) / 2
|
||||||
Y: (WINDOW_BOTTOM - 560) / 2
|
Y: (WINDOW_BOTTOM - 560) / 2
|
||||||
Width: 900
|
Width: 900
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ Container@DISPLAY_PANEL:
|
|||||||
Width: 200
|
Width: 200
|
||||||
Height: 20
|
Height: 20
|
||||||
Font: Regular
|
Font: Regular
|
||||||
Text: UI Feedback in Chat
|
Text: UI Feedback in Transients Panel
|
||||||
Label@VIDEO_TITLE:
|
Label@VIDEO_TITLE:
|
||||||
Y: 190
|
Y: 190
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
|
|||||||
@@ -115,6 +115,7 @@ ChromeLayout:
|
|||||||
cnc|chrome/gamesave-loading.yaml
|
cnc|chrome/gamesave-loading.yaml
|
||||||
cnc|chrome/ingame.yaml
|
cnc|chrome/ingame.yaml
|
||||||
cnc|chrome/ingame-chat.yaml
|
cnc|chrome/ingame-chat.yaml
|
||||||
|
common|chrome/ingame-transients.yaml
|
||||||
cnc|chrome/ingame-menu.yaml
|
cnc|chrome/ingame-menu.yaml
|
||||||
cnc|chrome/ingame-debug.yaml
|
cnc|chrome/ingame-debug.yaml
|
||||||
cnc|chrome/ingame-infochat.yaml
|
cnc|chrome/ingame-infochat.yaml
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ Container@CHAT_PANEL:
|
|||||||
Chat: CHAT_LINE_TEMPLATE
|
Chat: CHAT_LINE_TEMPLATE
|
||||||
System: SYSTEM_LINE_TEMPLATE
|
System: SYSTEM_LINE_TEMPLATE
|
||||||
Mission: SYSTEM_LINE_TEMPLATE
|
Mission: SYSTEM_LINE_TEMPLATE
|
||||||
Feedback: SYSTEM_LINE_TEMPLATE
|
|
||||||
Children:
|
Children:
|
||||||
Container@CHAT_OVERLAY:
|
Container@CHAT_OVERLAY:
|
||||||
Width: PARENT_RIGHT - 24
|
Width: PARENT_RIGHT - 24
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ Container@CHAT_CONTAINER:
|
|||||||
Chat: CHAT_LINE_TEMPLATE
|
Chat: CHAT_LINE_TEMPLATE
|
||||||
System: SYSTEM_LINE_TEMPLATE
|
System: SYSTEM_LINE_TEMPLATE
|
||||||
Mission: SYSTEM_LINE_TEMPLATE
|
Mission: SYSTEM_LINE_TEMPLATE
|
||||||
Feedback: SYSTEM_LINE_TEMPLATE
|
|
||||||
Children:
|
Children:
|
||||||
Container@CHAT_CHROME:
|
Container@CHAT_CHROME:
|
||||||
X: 20
|
X: 20
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ Container@PERF_WIDGETS:
|
|||||||
ClickThrough: true
|
ClickThrough: true
|
||||||
Background: dialog4
|
Background: dialog4
|
||||||
X: 10
|
X: 10
|
||||||
Y: WINDOW_BOTTOM - 265
|
Y: WINDOW_BOTTOM - HEIGHT - 156
|
||||||
Width: 210
|
Width: 210
|
||||||
Height: 210
|
Height: 210
|
||||||
Children:
|
Children:
|
||||||
|
|||||||
13
mods/common/chrome/ingame-transients.yaml
Normal file
13
mods/common/chrome/ingame-transients.yaml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
Container@TRANSIENTS_PANEL:
|
||||||
|
X: 5
|
||||||
|
Y: WINDOW_BOTTOM - HEIGHT - 55
|
||||||
|
Width: 550
|
||||||
|
Height: 80
|
||||||
|
Logic: IngameTransientNotificationsLogic
|
||||||
|
Children:
|
||||||
|
TextNotificationsDisplay@TRANSIENTS_DISPLAY:
|
||||||
|
Width: PARENT_RIGHT
|
||||||
|
Height: PARENT_BOTTOM
|
||||||
|
RemoveTime: 100
|
||||||
|
LogLength: 5
|
||||||
|
HideOverflow: False
|
||||||
@@ -4,7 +4,7 @@ Background@SERVER_LOBBY:
|
|||||||
Chat: CHAT_LINE_TEMPLATE
|
Chat: CHAT_LINE_TEMPLATE
|
||||||
System: SYSTEM_LINE_TEMPLATE
|
System: SYSTEM_LINE_TEMPLATE
|
||||||
Mission: SYSTEM_LINE_TEMPLATE
|
Mission: SYSTEM_LINE_TEMPLATE
|
||||||
Feedback: SYSTEM_LINE_TEMPLATE
|
Feedback: TRANSIENT_LINE_TEMPLATE
|
||||||
X: (WINDOW_RIGHT - WIDTH) / 2
|
X: (WINDOW_RIGHT - WIDTH) / 2
|
||||||
Y: (WINDOW_BOTTOM - HEIGHT) / 2
|
Y: (WINDOW_BOTTOM - HEIGHT) / 2
|
||||||
Width: 900
|
Width: 900
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ Container@DISPLAY_PANEL:
|
|||||||
Width: 200
|
Width: 200
|
||||||
Height: 20
|
Height: 20
|
||||||
Font: Regular
|
Font: Regular
|
||||||
Text: UI Feedback in Chat
|
Text: UI Feedback in Transients Panel
|
||||||
Label@VIDEO_TITLE:
|
Label@VIDEO_TITLE:
|
||||||
Y: 190
|
Y: 190
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
|
|||||||
@@ -37,3 +37,19 @@ Container@SYSTEM_LINE_TEMPLATE:
|
|||||||
WordWrap: True
|
WordWrap: True
|
||||||
Shadow: True
|
Shadow: True
|
||||||
TextColor: FFFF00
|
TextColor: FFFF00
|
||||||
|
|
||||||
|
Container@TRANSIENT_LINE_TEMPLATE:
|
||||||
|
Width: PARENT_RIGHT
|
||||||
|
Height: 16
|
||||||
|
Children:
|
||||||
|
Label@TIME:
|
||||||
|
X: 5
|
||||||
|
Width: 37
|
||||||
|
Height: 16
|
||||||
|
Shadow: True
|
||||||
|
Label@TEXT:
|
||||||
|
X: 5
|
||||||
|
Height: 16
|
||||||
|
WordWrap: True
|
||||||
|
Shadow: True
|
||||||
|
TextColor: AFEEEE
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ Assemblies:
|
|||||||
ChromeLayout:
|
ChromeLayout:
|
||||||
common|chrome/ingame.yaml
|
common|chrome/ingame.yaml
|
||||||
common|chrome/ingame-chat.yaml
|
common|chrome/ingame-chat.yaml
|
||||||
|
common|chrome/ingame-transients.yaml
|
||||||
common|chrome/ingame-fmvplayer.yaml
|
common|chrome/ingame-fmvplayer.yaml
|
||||||
d2k|chrome/ingame-menu.yaml
|
d2k|chrome/ingame-menu.yaml
|
||||||
common|chrome/ingame-info.yaml
|
common|chrome/ingame-info.yaml
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ Assemblies:
|
|||||||
ChromeLayout:
|
ChromeLayout:
|
||||||
common|chrome/ingame.yaml
|
common|chrome/ingame.yaml
|
||||||
common|chrome/ingame-chat.yaml
|
common|chrome/ingame-chat.yaml
|
||||||
|
common|chrome/ingame-transients.yaml
|
||||||
common|chrome/ingame-fmvplayer.yaml
|
common|chrome/ingame-fmvplayer.yaml
|
||||||
common|chrome/ingame-info.yaml
|
common|chrome/ingame-info.yaml
|
||||||
common|chrome/ingame-infoscripterror.yaml
|
common|chrome/ingame-infoscripterror.yaml
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ Assemblies:
|
|||||||
ChromeLayout:
|
ChromeLayout:
|
||||||
common|chrome/ingame.yaml
|
common|chrome/ingame.yaml
|
||||||
common|chrome/ingame-chat.yaml
|
common|chrome/ingame-chat.yaml
|
||||||
|
common|chrome/ingame-transients.yaml
|
||||||
common|chrome/ingame-fmvplayer.yaml
|
common|chrome/ingame-fmvplayer.yaml
|
||||||
common|chrome/ingame-menu.yaml
|
common|chrome/ingame-menu.yaml
|
||||||
common|chrome/ingame-info.yaml
|
common|chrome/ingame-info.yaml
|
||||||
|
|||||||
Reference in New Issue
Block a user