Add lobby sounds for leave, join and option change

This commit is contained in:
Matthias Mailänder
2023-06-14 19:10:52 +02:00
committed by Gustas
parent d217ab39c2
commit a1efb28f0b
8 changed files with 73 additions and 11 deletions

View File

@@ -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;

View File

@@ -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<TextNotification>
{

View File

@@ -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()

View File

@@ -106,6 +106,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
Dictionary<int, SpawnOccupant> spawnOccupants = new();
readonly string chatLineSound = ChromeMetrics.Get<string>("ChatLineSound");
readonly string playerJoinedSound = ChromeMetrics.Get<string>("PlayerJoinedSound");
readonly string playerLeftSound = ChromeMetrics.Get<string>("PlayerLeftSound");
readonly string lobbyOptionChangedSound = ChromeMetrics.Get<string>("LobbyOptionChangedSound");
bool MapIsPlayable => (mapStatus & Session.MapStatus.Playable) == Session.MapStatus.Playable;
@@ -440,7 +443,12 @@ namespace OpenRA.Mods.Common.Widgets.Logic
forceStartBin.Get<ButtonWidget>("CANCEL_BUTTON").OnClick = () => panel = PanelType.Players;
var disconnectButton = lobby.Get<ButtonWidget>("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()

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -47,6 +47,9 @@ Metrics:
NoticeSuccessColor: 00FF00
NoticeErrorColor: FF0000
ChatLineSound: ChatLine
PlayerJoinedSound: ChatLine
LobbyOptionChangedSound: ChatLine
PlayerLeftSound: ChatLine
ClickDisabledSound: ClickDisabledSound
ClickSound: ClickSound
NormalSelectionColor: FFFFFF