Modify admin chat (#13050)

* split admin chat into new channel

* add ability to play audio when a chat message is received and add audio to admin chat

* give client control of AdminChat sound and volume + suppress sound for senders
This commit is contained in:
Chief-Engineer
2022-12-19 21:39:01 -06:00
committed by GitHub
parent 8b347dd70f
commit 5ece9bd9e8
12 changed files with 55 additions and 21 deletions

View File

@@ -420,6 +420,7 @@ public sealed class ChatUIController : UIController
if (_admin.HasFlag(AdminFlags.Admin))
{
FilterableChannels |= ChatChannel.Admin;
FilterableChannels |= ChatChannel.AdminChat;
CanSendChannels |= ChatSelectChannel.Admin;
}

View File

@@ -20,6 +20,7 @@ public sealed partial class ChannelFilterPopup : Popup
ChatChannel.OOC,
ChatChannel.Dead,
ChatChannel.Admin,
ChatChannel.AdminChat,
ChatChannel.Server
};

View File

@@ -82,7 +82,7 @@ public sealed class ChannelSelectorButton : Button
ChatSelectChannel.LOOC => Color.MediumTurquoise,
ChatSelectChannel.OOC => Color.LightSkyBlue,
ChatSelectChannel.Dead => Color.MediumPurple,
ChatSelectChannel.Admin => Color.Red,
ChatSelectChannel.Admin => Color.HotPink,
_ => Color.DarkGray
};
}

View File

@@ -7,7 +7,9 @@ using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Audio;
using Robust.Shared.Input;
using Robust.Shared.Player;
using Robust.Shared.Utility;
using static Robust.Client.UserInterface.Controls.LineEdit;
@@ -52,6 +54,9 @@ public partial class ChatBox : UIWidget
return;
}
if (msg is { Read: false, AudioPath: { } })
SoundSystem.Play(msg.AudioPath, Filter.Local(), new AudioParams().WithVolume(msg.AudioVolume));
msg.Read = true;
var color = msg.MessageColorOverride != null

View File

@@ -38,6 +38,7 @@ namespace Content.Server.Chat.Managers
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly IServerPreferencesManager _preferencesManager = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly INetConfigurationManager _netConfigManager = default!;
/// <summary>
/// The maximum length a player-sent message can be sent
@@ -191,7 +192,18 @@ namespace Content.Server.Chat.Managers
var wrappedMessage = Loc.GetString("chat-manager-send-admin-chat-wrap-message",
("adminChannelName", Loc.GetString("chat-manager-admin-channel-name")),
("playerName", player.Name), ("message", FormattedMessage.EscapeText(message)));
ChatMessageToMany(ChatChannel.Admin, message, wrappedMessage, default, false, true, clients.ToList());
foreach (var client in clients)
{
var isSource = client != player.ConnectedClient;
ChatMessageToOne(ChatChannel.AdminChat,
message,
wrappedMessage,
default,
false,
client,
audioPath: isSource ? _netConfigManager.GetClientCVar(client, CCVars.AdminChatSoundPath) : default,
audioVolume: isSource ? _netConfigManager.GetClientCVar(client, CCVars.AdminChatSoundVolume) : default);
}
_adminLogger.Add(LogType.Chat, $"Admin chat from {player:Player}: {message}");
}
@@ -200,21 +212,21 @@ namespace Content.Server.Chat.Managers
#region Utility
public void ChatMessageToOne(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, INetChannel client, Color? colorOverride = null, bool recordReplay = false)
public void ChatMessageToOne(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, INetChannel client, Color? colorOverride = null, bool recordReplay = false, string? audioPath = null, float audioVolume = 0)
{
var msg = new ChatMessage(channel, message, wrappedMessage, source, hideChat, colorOverride);
var msg = new ChatMessage(channel, message, wrappedMessage, source, hideChat, colorOverride, audioPath, audioVolume);
_netManager.ServerSendMessage(new MsgChatMessage() { Message = msg }, client);
if (recordReplay)
_replay.QueueReplayMessage(msg);
}
public void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, IEnumerable<INetChannel> clients, Color? colorOverride = null)
=> ChatMessageToMany(channel, message, wrappedMessage, source, hideChat, recordReplay, clients.ToList(), colorOverride);
public void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, IEnumerable<INetChannel> clients, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0)
=> ChatMessageToMany(channel, message, wrappedMessage, source, hideChat, recordReplay, clients.ToList(), colorOverride, audioPath, audioVolume);
public void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, List<INetChannel> clients, Color? colorOverride = null)
public void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, List<INetChannel> clients, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0)
{
var msg = new ChatMessage(channel, message, wrappedMessage, source, hideChat, colorOverride);
var msg = new ChatMessage(channel, message, wrappedMessage, source, hideChat, colorOverride, audioPath, audioVolume);
_netManager.ServerSendToMany(new MsgChatMessage() { Message = msg }, clients);
if (recordReplay)
@@ -222,7 +234,7 @@ namespace Content.Server.Chat.Managers
}
public void ChatMessageToManyFiltered(Filter filter, ChatChannel channel, string message, string wrappedMessage, EntityUid source,
bool hideChat, bool recordReplay, Color? colorOverride = null)
bool hideChat, bool recordReplay, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0)
{
if (!recordReplay && !filter.Recipients.Any())
return;
@@ -233,12 +245,12 @@ namespace Content.Server.Chat.Managers
clients.Add(recipient.ConnectedClient);
}
ChatMessageToMany(channel, message, wrappedMessage, source, hideChat, recordReplay, clients, colorOverride);
ChatMessageToMany(channel, message, wrappedMessage, source, hideChat, recordReplay, clients, colorOverride, audioPath, audioVolume);
}
public void ChatMessageToAll(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride = null)
public void ChatMessageToAll(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0)
{
var msg = new ChatMessage(channel, message, wrappedMessage, source, hideChat, colorOverride);
var msg = new ChatMessage(channel, message, wrappedMessage, source, hideChat, colorOverride, audioPath, audioVolume);
_netManager.ServerSendToAll(new MsgChatMessage() { Message = msg });
if (recordReplay)

View File

@@ -24,14 +24,14 @@ namespace Content.Server.Chat.Managers
void SendAdminAnnouncement(string message);
void ChatMessageToOne(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat,
INetChannel client, Color? colorOverride = null, bool recordReplay = false);
INetChannel client, Color? colorOverride = null, bool recordReplay = false, string? audioPath = null, float audioVolume = 0);
void ChatMessageToMany(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay,
IEnumerable<INetChannel> clients, Color? colorOverride = null);
IEnumerable<INetChannel> clients, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0);
void ChatMessageToManyFiltered(Filter filter, ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride);
void ChatMessageToManyFiltered(Filter filter, ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride, string? audioPath = null, float audioVolume = 0);
void ChatMessageToAll(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride = null);
void ChatMessageToAll(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat, bool recordReplay, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0);
bool MessageCharacterLimit(IPlayerSession player, string message);
}

View File

@@ -511,6 +511,10 @@ namespace Content.Shared.CCVar
public static readonly CVarDef<bool> AdminSoundsEnabled =
CVarDef.Create("audio.admin_sounds_enabled", true, CVar.ARCHIVE | CVar.CLIENTONLY);
public static readonly CVarDef<string> AdminChatSoundPath =
CVarDef.Create("audio.admin_chat_sound_path", "/Audio/Items/pop.ogg", CVar.ARCHIVE | CVar.CLIENT | CVar.REPLICATED);
public static readonly CVarDef<float> AdminChatSoundVolume =
CVarDef.Create("audio.admin_chat_sound_volume", -5f, CVar.ARCHIVE | CVar.CLIENT | CVar.REPLICATED);
/*
* HUD

View File

@@ -60,14 +60,19 @@ namespace Content.Shared.Chat
Dead = 1 << 9,
/// <summary>
/// Admin chat
/// Misc admin messages
/// </summary>
Admin = 1 << 10,
/// <summary>
/// Admin chat
/// </summary>
AdminChat = 1 << 11,
/// <summary>
/// Unspecified.
/// </summary>
Unspecified = 1 << 11,
Unspecified = 1 << 12,
/// <summary>
/// Channels considered to be IC.

View File

@@ -12,6 +12,7 @@ public static class ChatChannelExtensions
ChatChannel.OOC => Color.LightSkyBlue,
ChatChannel.Dead => Color.MediumPurple,
ChatChannel.Admin => Color.Red,
ChatChannel.AdminChat => Color.HotPink,
ChatChannel.Whisper => Color.DarkGray,
_ => Color.LightGray
};

View File

@@ -49,7 +49,7 @@
/// <summary>
/// Admin chat
/// </summary>
Admin = ChatChannel.Admin,
Admin = ChatChannel.AdminChat,
Console = ChatChannel.Unspecified
}

View File

@@ -16,11 +16,13 @@ namespace Content.Shared.Chat
public EntityUid SenderEntity;
public bool HideChat;
public Color? MessageColorOverride;
public string? AudioPath;
public float AudioVolume;
[NonSerialized]
public bool Read;
public ChatMessage(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat = false, Color? colorOverride = null)
public ChatMessage(ChatChannel channel, string message, string wrappedMessage, EntityUid source, bool hideChat = false, Color? colorOverride = null, string? audioPath = null, float audioVolume = 0)
{
Channel = channel;
Message = message;
@@ -28,6 +30,8 @@ namespace Content.Shared.Chat
SenderEntity = source;
HideChat = hideChat;
MessageColorOverride = colorOverride;
AudioPath = audioPath;
AudioVolume = audioVolume;
}
}

View File

@@ -13,7 +13,8 @@ hud-chatbox-select-channel-Damage = Damage
hud-chatbox-select-channel-Visual = Actions
hud-chatbox-select-channel-Radio = Radio
hud-chatbox-channel-Admin = Admin
hud-chatbox-channel-Admin = Admin Misc
hud-chatbox-channel-AdminChat = Admin Chat
hud-chatbox-channel-Dead = Dead
hud-chatbox-channel-Emotes = Emotes
hud-chatbox-channel-Local = Local