From ed45440256f38c61983284086a4e78a23cdb2c8f Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Tue, 28 Mar 2023 14:27:21 -0700 Subject: [PATCH] Always show ahelp relay message when the relay is enabled (#14931) --- .../Administration/UI/Bwoink/BwoinkPanel.xaml | 4 +- .../UI/Bwoink/BwoinkPanel.xaml.cs | 8 ++- .../Systems/Bwoink/AHelpUIController.cs | 56 +++++++++++++++---- .../Administration/Systems/BwoinkSystem.cs | 8 +-- .../Administration/SharedBwoinkSystem.cs | 17 ++++++ .../Locale/en-US/administration/bwoink.ftl | 3 +- 6 files changed, 76 insertions(+), 20 deletions(-) diff --git a/Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml b/Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml index 433807e7b1..5c3e7f667d 100644 --- a/Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml +++ b/Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml @@ -1,7 +1,9 @@  + HorizontalExpand="True"> + diff --git a/Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml.cs b/Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml.cs index f545aff422..ee345cb51c 100644 --- a/Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml.cs +++ b/Content.Client/Administration/UI/Bwoink/BwoinkPanel.xaml.cs @@ -3,7 +3,6 @@ using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; using Robust.Shared.Utility; -using Content.Client.Administration.UI.CustomControls; namespace Content.Client.Administration.UI.Bwoink { @@ -18,6 +17,13 @@ namespace Content.Client.Administration.UI.Bwoink public BwoinkPanel(Action messageSender) { RobustXamlLoader.Load(this); + + var msg = new FormattedMessage(); + msg.PushColor(Color.LightGray); + msg.AddText(Loc.GetString("bwoink-system-messages-being-relayed-to-discord")); + msg.Pop(); + RelayedToDiscordLabel.SetMessage(msg); + _messageSender = messageSender; OnVisibilityChanged += c => diff --git a/Content.Client/UserInterface/Systems/Bwoink/AHelpUIController.cs b/Content.Client/UserInterface/Systems/Bwoink/AHelpUIController.cs index 21b3c9d0ff..871708a711 100644 --- a/Content.Client/UserInterface/Systems/Bwoink/AHelpUIController.cs +++ b/Content.Client/UserInterface/Systems/Bwoink/AHelpUIController.cs @@ -29,9 +29,18 @@ public sealed class AHelpUIController: UIController, IOnStateChanged UIManager.GetActiveUIWidgetOrNull()?.AHelpButton; public IAHelpUIHandler? UIHelper; + private bool _discordRelayActive; + + public override void Initialize() + { + base.Initialize(); + + SubscribeNetworkEvent(DiscordRelayUpdated); + } public void OnStateEntered(GameplayState state) { @@ -71,7 +80,6 @@ public sealed class AHelpUIController: UIController, IOnStateChanged _bwoinkSystem?.Send(userId, textMessage); UIHelper.OnClose += () => { SetAHelpPressed(false); }; @@ -161,14 +176,15 @@ public sealed class AHelpUIController: UIController, IOnStateChanged? SendMessageAction { get; set; } @@ -298,11 +314,15 @@ public sealed class AdminAHelpUIHandler : IAHelpUIHandler OpenWindow(); } + public void DiscordRelayChanged(bool active) + { + } + public event Action? OnClose; public event Action? OnOpen; public Action? SendMessageAction { get; set; } - public void Open(NetUserId channelId) + public void Open(NetUserId channelId, bool relayActive) { SelectChannel(channelId); OpenWindow(); @@ -381,11 +401,12 @@ public sealed class UserAHelpUIHandler : IAHelpUIHandler public bool IsOpen => _window is { Disposed: false, IsOpen: true }; private DefaultWindow? _window; private BwoinkPanel? _chatPanel; + private bool _discordRelayActive; public void Receive(SharedBwoinkSystem.BwoinkTextMessage message) { DebugTools.Assert(message.UserId == _ownerId); - EnsureInit(); + EnsureInit(_discordRelayActive); _chatPanel!.ReceiveLine(message); _window!.OpenCentered(); } @@ -397,7 +418,7 @@ public sealed class UserAHelpUIHandler : IAHelpUIHandler public void ToggleWindow() { - EnsureInit(); + EnsureInit(_discordRelayActive); if (_window!.IsOpen) { _window.Close(); @@ -413,27 +434,38 @@ public sealed class UserAHelpUIHandler : IAHelpUIHandler { } + public void DiscordRelayChanged(bool active) + { + _discordRelayActive = active; + + if (_chatPanel != null) + { + _chatPanel.RelayedToDiscordLabel.Visible = active; + } + } + public event Action? OnClose; public event Action? OnOpen; public Action? SendMessageAction { get; set; } - public void Open(NetUserId channelId) + public void Open(NetUserId channelId, bool relayActive) { - EnsureInit(); + EnsureInit(relayActive); _window!.OpenCentered(); } - private void EnsureInit() + private void EnsureInit(bool relayActive) { if (_window is { Disposed: false }) return; _chatPanel = new BwoinkPanel(text => SendMessageAction?.Invoke(_ownerId, text)); + _chatPanel.RelayedToDiscordLabel.Visible = relayActive; _window = new DefaultWindow() { TitleClass="windowTitleAlert", HeaderClass="windowHeaderAlert", Title=Loc.GetString("bwoink-user-title"), - SetSize=(400, 200), + MinSize=(500, 200), }; _window.OnClose += () => { OnClose?.Invoke(); }; _window.OnOpen += () => { OnOpen?.Invoke(); }; diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index 0d42407b15..2cc3d2d3c7 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -109,6 +109,8 @@ namespace Content.Server.Administration.Systems { _webhookUrl = url; + RaiseNetworkEvent(new BwoinkDiscordRelayUpdated(!string.IsNullOrWhiteSpace(url))); + if (url == string.Empty) return; @@ -395,13 +397,11 @@ namespace Content.Server.Administration.Systems _messageQueues[msg.UserId].Enqueue(GenerateAHelpMessage(senderSession.Name, str, !personalChannel, admins.Count == 0)); } - if (admins.Count != 0) + if (admins.Count != 0 || sendsWebhook) return; // No admin online, let the player know - var systemText = sendsWebhook ? - Loc.GetString("bwoink-system-starmute-message-no-other-users-webhook") : - Loc.GetString("bwoink-system-starmute-message-no-other-users"); + var systemText = Loc.GetString("bwoink-system-starmute-message-no-other-users"); var starMuteMsg = new BwoinkTextMessage(message.UserId, SystemUserId, systemText); RaiseNetworkEvent(starMuteMsg, senderSession.ConnectedClient); } diff --git a/Content.Shared/Administration/SharedBwoinkSystem.cs b/Content.Shared/Administration/SharedBwoinkSystem.cs index 2df0e3a7d7..597d2c0a6c 100644 --- a/Content.Shared/Administration/SharedBwoinkSystem.cs +++ b/Content.Shared/Administration/SharedBwoinkSystem.cs @@ -29,7 +29,9 @@ namespace Content.Shared.Administration public sealed class BwoinkTextMessage : EntityEventArgs { public DateTime SentAt { get; } + public NetUserId UserId { get; } + // This is ignored from the client. // It's checked by the client when receiving a message from the server for bwoink noises. // This could be a boolean "Incoming", but that would require making a second instance. @@ -44,5 +46,20 @@ namespace Content.Shared.Administration Text = text; } } + + /// + /// Sent by the server to notify all clients when the webhook url is sent. + /// The webhook url itself is not and should not be sent. + /// + [Serializable, NetSerializable] + public sealed class BwoinkDiscordRelayUpdated : EntityEventArgs + { + public bool DiscordRelayEnabled { get; } + + public BwoinkDiscordRelayUpdated(bool enabled) + { + DiscordRelayEnabled = enabled; + } + } } } diff --git a/Resources/Locale/en-US/administration/bwoink.ftl b/Resources/Locale/en-US/administration/bwoink.ftl index cb9230e2da..dd96f8a3b7 100644 --- a/Resources/Locale/en-US/administration/bwoink.ftl +++ b/Resources/Locale/en-US/administration/bwoink.ftl @@ -2,5 +2,4 @@ bwoink-user-title = Admin Message bwoink-system-starmute-message-no-other-users = *System: Nobody is available to receive your message. Try pinging Game Admins on Discord. -bwoink-system-starmute-message-no-other-users-webhook = *System: Your message has been relayed to the admins via discord. - +bwoink-system-messages-being-relayed-to-discord = Your messages are being relayed to the admins via Discord.