From a1efb28f0b22c7e8990f208038e99b649e16429f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Wed, 14 Jun 2023 19:10:52 +0200 Subject: [PATCH] Add lobby sounds for leave, join and option change --- OpenRA.Game/Network/UnitOrders.cs | 13 +++++++- OpenRA.Game/TextNotification.cs | 2 +- OpenRA.Game/TextNotificationsManager.cs | 24 +++++++++++--- .../Widgets/Logic/Lobby/LobbyLogic.cs | 32 +++++++++++++++++-- mods/cnc/chrome/lobby.yaml | 2 ++ mods/common/chrome/lobby.yaml | 2 ++ mods/common/languages/en.ftl | 6 ++-- mods/common/metrics.yaml | 3 ++ 8 files changed, 73 insertions(+), 11 deletions(-) diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs index b869caa8ef..f647b33d96 100644 --- a/OpenRA.Game/Network/UnitOrders.cs +++ b/OpenRA.Game/Network/UnitOrders.cs @@ -20,6 +20,12 @@ namespace OpenRA.Network { public const int ChatMessageMaxLength = 2500; + [TranslationReference("player")] + const string Joined = "notification-joined"; + + [TranslationReference("player")] + const string Left = "notification-lobby-disconnected"; + static Player FindPlayerByClient(this World world, Session.Client c) { return world.Players.FirstOrDefault(p => p.ClientIndex == c.Index && p.PlayerReference.Playable); @@ -44,7 +50,12 @@ namespace OpenRA.Network foreach (var node in yaml) { var localizedMessage = new LocalizedMessage(node.Value); - TextNotificationsManager.AddSystemLine(localizedMessage.TranslatedText); + if (localizedMessage.Key == Joined) + TextNotificationsManager.AddPlayerJoinedLine(localizedMessage.TranslatedText); + else if (localizedMessage.Key == Left) + TextNotificationsManager.AddPlayerLeftLine(localizedMessage.TranslatedText); + else + TextNotificationsManager.AddSystemLine(localizedMessage.TranslatedText); } break; diff --git a/OpenRA.Game/TextNotification.cs b/OpenRA.Game/TextNotification.cs index 7424e9f01e..666f62e078 100644 --- a/OpenRA.Game/TextNotification.cs +++ b/OpenRA.Game/TextNotification.cs @@ -14,7 +14,7 @@ using OpenRA.Primitives; namespace OpenRA { - public enum TextNotificationPool { System, Chat, Mission, Feedback, Transients } + public enum TextNotificationPool { System, Join, Leave, Chat, Mission, Feedback, Transients } public class TextNotification : IEquatable { diff --git a/OpenRA.Game/TextNotificationsManager.cs b/OpenRA.Game/TextNotificationsManager.cs index bb1582a359..60517b773b 100644 --- a/OpenRA.Game/TextNotificationsManager.cs +++ b/OpenRA.Game/TextNotificationsManager.cs @@ -51,6 +51,16 @@ namespace OpenRA AddTextNotification(TextNotificationPool.Mission, SystemClientId, prefix, text, prefixColor); } + public static void AddPlayerJoinedLine(string text) + { + AddTextNotification(TextNotificationPool.Join, SystemClientId, SystemMessageLabel, text); + } + + public static void AddPlayerLeftLine(string text) + { + AddTextNotification(TextNotificationPool.Leave, SystemClientId, SystemMessageLabel, text); + } + public static void AddSystemLine(string text) { AddSystemLine(SystemMessageLabel, text); @@ -86,11 +96,15 @@ namespace OpenRA { var filters = Game.Settings.Game.TextNotificationPoolFilters; - return pool == TextNotificationPool.Chat || - pool == TextNotificationPool.System || - pool == TextNotificationPool.Mission || - (pool == TextNotificationPool.Transients && filters.HasFlag(TextNotificationPoolFilters.Transients)) || - (pool == TextNotificationPool.Feedback && filters.HasFlag(TextNotificationPoolFilters.Feedback)); + switch (pool) + { + case TextNotificationPool.Transients: + return filters.HasFlag(TextNotificationPoolFilters.Transients); + case TextNotificationPool.Feedback: + return filters.HasFlag(TextNotificationPoolFilters.Feedback); + default: + return true; + } } public static void Clear() diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index 0f7fe2e67e..01ff400d68 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -106,6 +106,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic Dictionary spawnOccupants = new(); readonly string chatLineSound = ChromeMetrics.Get("ChatLineSound"); + readonly string playerJoinedSound = ChromeMetrics.Get("PlayerJoinedSound"); + readonly string playerLeftSound = ChromeMetrics.Get("PlayerLeftSound"); + readonly string lobbyOptionChangedSound = ChromeMetrics.Get("LobbyOptionChangedSound"); bool MapIsPlayable => (mapStatus & Session.MapStatus.Playable) == Session.MapStatus.Playable; @@ -440,7 +443,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic forceStartBin.Get("CANCEL_BUTTON").OnClick = () => panel = PanelType.Players; var disconnectButton = lobby.Get("DISCONNECT_BUTTON"); - disconnectButton.OnClick = () => { Ui.CloseWindow(); onExit(); }; + disconnectButton.OnClick = () => + { + Ui.CloseWindow(); + onExit(); + Game.Sound.PlayNotification(modRules, null, "Sounds", playerLeftSound, null); + }; if (skirmishMode) disconnectButton.Text = TranslationProvider.GetString(Back); @@ -519,6 +527,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (logicArgs.TryGetValue("ChatLineSound", out var yaml)) chatLineSound = yaml.Value; + if (logicArgs.TryGetValue("PlayerJoinedSound", out yaml)) + playerJoinedSound = yaml.Value; + if (logicArgs.TryGetValue("PlayerLeftSound", out yaml)) + playerLeftSound = yaml.Value; + if (logicArgs.TryGetValue("LobbyOptionChangedSound", out yaml)) + lobbyOptionChangedSound = yaml.Value; } bool disposed; @@ -577,7 +591,21 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (scrolledToBottom) lobbyChatPanel.ScrollToBottom(smooth: true); - Game.Sound.PlayNotification(modRules, null, "Sounds", chatLineSound, null); + switch (notification.Pool) + { + case TextNotificationPool.Chat: + Game.Sound.PlayNotification(modRules, null, "Sounds", chatLineSound, null); + break; + case TextNotificationPool.System: + Game.Sound.PlayNotification(modRules, null, "Sounds", lobbyOptionChangedSound, null); + break; + case TextNotificationPool.Join: + Game.Sound.PlayNotification(modRules, null, "Sounds", playerJoinedSound, null); + break; + case TextNotificationPool.Leave: + Game.Sound.PlayNotification(modRules, null, "Sounds", playerLeftSound, null); + break; + } } void UpdateCurrentMap() diff --git a/mods/cnc/chrome/lobby.yaml b/mods/cnc/chrome/lobby.yaml index 3f0d13e77b..925a48336e 100644 --- a/mods/cnc/chrome/lobby.yaml +++ b/mods/cnc/chrome/lobby.yaml @@ -2,6 +2,8 @@ Container@SERVER_LOBBY: Logic: LobbyLogic ChatTemplates: Chat: CHAT_LINE_TEMPLATE + Join: SYSTEM_LINE_TEMPLATE + Leave: SYSTEM_LINE_TEMPLATE System: SYSTEM_LINE_TEMPLATE Mission: CHAT_LINE_TEMPLATE Feedback: TRANSIENT_LINE_TEMPLATE diff --git a/mods/common/chrome/lobby.yaml b/mods/common/chrome/lobby.yaml index a42ce5d357..ea2e10e6d0 100644 --- a/mods/common/chrome/lobby.yaml +++ b/mods/common/chrome/lobby.yaml @@ -2,6 +2,8 @@ Background@SERVER_LOBBY: Logic: LobbyLogic ChatTemplates: Chat: CHAT_LINE_TEMPLATE + Join: SYSTEM_LINE_TEMPLATE + Leave: SYSTEM_LINE_TEMPLATE System: SYSTEM_LINE_TEMPLATE Mission: CHAT_LINE_TEMPLATE Feedback: TRANSIENT_LINE_TEMPLATE diff --git a/mods/common/languages/en.ftl b/mods/common/languages/en.ftl index ce3bca263c..c7640730af 100644 --- a/mods/common/languages/en.ftl +++ b/mods/common/languages/en.ftl @@ -23,7 +23,6 @@ notification-requires-host = Only the host can do that. notification-invalid-bot-slot = Can't add bots to a slot with another client. notification-invalid-bot-type = Invalid bot type. notification-admin-change-map = Only the host can change the map. -notification-lobby-disconnected = { $player } has left. notification-player-disconnected = { $player } has disconnected. notification-team-player-disconnected = { $player } (Team { $team }) has disconnected. notification-observer-disconnected = { $player } (Spectator) has disconnected. @@ -57,7 +56,6 @@ notification-incompatible-protocol = Server is running an incompatible protocol. notification-you-were-banned = You have been banned from the server. notification-you-were-temp-banned = You have been temporarily banned from the server. notification-game-full = The game is full. -notification-joined = { $player } has joined the game. notification-new-admin = { $player } is now the admin. notification-option-locked = { $option } cannot be changed. notification-invalid-configuration-command = Invalid configuration command. @@ -85,6 +83,10 @@ notification-requires-authentication = Server requires players to have an OpenRA notification-no-permission-to-join = You do not have permission to join this server. notification-slot-closed = Your slot was closed by the host. +## ServerOrders, UnitOrders +notification-joined = { $player } has joined the game. +notification-lobby-disconnected = { $player } has left. + ## Server notification-game-started = Game started diff --git a/mods/common/metrics.yaml b/mods/common/metrics.yaml index 9767c8c60c..998822e669 100644 --- a/mods/common/metrics.yaml +++ b/mods/common/metrics.yaml @@ -47,6 +47,9 @@ Metrics: NoticeSuccessColor: 00FF00 NoticeErrorColor: FF0000 ChatLineSound: ChatLine + PlayerJoinedSound: ChatLine + LobbyOptionChangedSound: ChatLine + PlayerLeftSound: ChatLine ClickDisabledSound: ClickDisabledSound ClickSound: ClickSound NormalSelectionColor: FFFFFF