Skip to content

Commit

Permalink
Add lobby sounds for leave, join and option change
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender committed Jun 3, 2022
1 parent c1cb9ea commit de90265
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 10 deletions.
13 changes: 12 additions & 1 deletion OpenRA.Game/Network/UnitOrders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public static class UnitOrders
{
public const int ChatMessageMaxLength = 2500;

[TranslationReference("player")]
static readonly string Joined = "lobby-joined";

[TranslationReference("player")]
static readonly string Left = "lobby-disconnected";

static Player FindPlayerByClient(this World world, Session.Client c)
{
return world.Players.FirstOrDefault(p => p.ClientIndex == c.Index && p.PlayerReference.Playable);
Expand All @@ -44,7 +50,12 @@ internal static void ProcessOrder(OrderManager orderManager, World world, int cl
foreach (var node in yaml)
{
var localizedMessage = new LocalizedMessage(node.Value);
TextNotificationsManager.AddSystemLine(localizedMessage.Translate(Game.ModData));
if (localizedMessage.Key == Joined)
TextNotificationsManager.AddPlayerJoinedLine(localizedMessage.Translate(Game.ModData));
else if (localizedMessage.Key == Left)
TextNotificationsManager.AddPlayerLeftLine(localizedMessage.Translate(Game.ModData));
else
TextNotificationsManager.AddSystemLine(localizedMessage.Translate(Game.ModData));
}

break;
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/Server/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public sealed class Server
static readonly string Full = "full";

[TranslationReference("player")]
static readonly string Joined = "joined";
static readonly string Joined = "lobby-joined";

[TranslationReference]
static readonly string RequiresForumAccount = "requires-forum-account";
Expand Down
2 changes: 1 addition & 1 deletion OpenRA.Game/TextNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

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>
{
Expand Down
24 changes: 19 additions & 5 deletions OpenRA.Game/TextNotificationsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public static void AddMissionLine(string prefix, string text, Color? prefixColor
AddTextNotification(TextNotificationPool.Mission, prefix, text, prefixColor);
}

public static void AddPlayerJoinedLine(string text)
{
AddTextNotification(TextNotificationPool.Join, SystemMessageLabel, text);
}

public static void AddPlayerLeftLine(string text)
{
AddTextNotification(TextNotificationPool.Leave, SystemMessageLabel, text);
}

public static void AddSystemLine(string text)
{
AddSystemLine(SystemMessageLabel, text);
Expand Down Expand Up @@ -75,11 +85,15 @@ static bool IsPoolEnabled(TextNotificationPool pool)
{
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;
}
}
}
}
25 changes: 24 additions & 1 deletion OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ enum PanelType { Players, Options, Music, Servers, Kick, ForceStart }
Dictionary<int, SpawnOccupant> spawnOccupants = new Dictionary<int, SpawnOccupant>();

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;

Expand Down Expand Up @@ -485,6 +488,12 @@ void ConnectionStateChanged(OrderManager om, string password, NetworkConnection

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;
Expand Down Expand Up @@ -545,7 +554,21 @@ void AddChatLine(TextNotification notification)
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()
Expand Down
6 changes: 6 additions & 0 deletions mods/cnc/audio/notifications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ Sounds:
VolumeModifier: 0.33
ChatLine: scold1
AllowInterrupt: true
PlayerJoined: country4
AllowInterrupt: true
PlayerLeft: bleep2
AllowInterrupt: true
LobbyOptionChanged: country1
AllowInterrupt: true
ClickDisabledSound: scold2
AllowInterrupt: true
ClickSound: button
Expand Down
2 changes: 2 additions & 0 deletions mods/cnc/chrome/lobby.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions mods/common/chrome/lobby.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mods/common/languages/en.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ incompatible-protocol = Server is running an incompatible protocol.
banned = You have been banned from the server.
temp-banned = You have been temporarily banned from the server.
full = The game is full.
joined = { $player } has joined the game.
lobby-joined = { $player } has joined the game.
new-admin = { $player } is now the admin.
option-locked = { $option } cannot be changed.
invalid-configuration-command = Invalid configuration command.
Expand Down
3 changes: 3 additions & 0 deletions mods/common/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ Metrics:
NoticeWarningColor: FFA500
NoticeSuccessColor: 00FF00
NoticeErrorColor: FF0000
PlayerJoinedSound: PlayerJoined
ChatLineSound: ChatLine
LobbyOptionChangedSound: LobbyOptionChanged
PlayerLeftSound: PlayerLeft
ClickDisabledSound: ClickDisabledSound
ClickSound: ClickSound
NormalSelectionColor: FFFFFF
Expand Down
6 changes: 6 additions & 0 deletions mods/d2k/audio/notifications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ Sounds:
LevelUp: SCORTIK1
ChatLine: CHAT1
AllowInterrupt: true
PlayerJoined: STEALTH2
AllowInterrupt: true
PlayerLeft: STEALTH1
AllowInterrupt: true
LobbyOptionChanged: ENDLIST1
AllowInterrupt: true
BuildPaletteOpen: BUTTON1
BuildPaletteClose: BUTTON1
TabClick: SIDEBAR1
Expand Down
6 changes: 6 additions & 0 deletions mods/ra/audio/notifications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ Sounds:
EnablePower: bleep12
ChatLine: rabeep1
AllowInterrupt: true
PlayerJoined: bleep11
AllowInterrupt: true
PlayerLeft: bleep12
AllowInterrupt: true
LobbyOptionChanged: bleep17
AllowInterrupt: true
ClickSound: ramenu1
AllowInterrupt: true
ClickDisabledSound:
Expand Down
6 changes: 6 additions & 0 deletions mods/ts/audio/sounds-generic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ Sounds:
VolumeModifier: 0.33
ChatLine: message1
AllowInterrupt: true
PlayerJoined: orcaup1
AllowInterrupt: true
PlayerLeft: orcadwn1
AllowInterrupt: true
LobbyOptionChanged: notify
AllowInterrupt: true
ClickDisabledSound: wrong1
AllowInterrupt: true
ClickSound: clicky1
Expand Down

0 comments on commit de90265

Please sign in to comment.