Always show ahelp relay message when the relay is enabled (#14931)
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
<BoxContainer
|
||||
xmlns="https://spacestation14.io"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
Orientation="Vertical"
|
||||
HorizontalExpand="true">
|
||||
HorizontalExpand="True">
|
||||
<OutputPanel Name="TextOutput" VerticalExpand="true" />
|
||||
<HistoryLineEdit Name="SenderLineEdit" />
|
||||
<RichTextLabel Name="RelayedToDiscordLabel" Access="Public" Visible="False" />
|
||||
</BoxContainer>
|
||||
|
||||
@@ -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<string> 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 =>
|
||||
|
||||
@@ -29,9 +29,18 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IClyde _clyde = default!;
|
||||
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
|
||||
|
||||
private BwoinkSystem? _bwoinkSystem;
|
||||
private MenuButton? AhelpButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.AHelpButton;
|
||||
public IAHelpUIHandler? UIHelper;
|
||||
private bool _discordRelayActive;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeNetworkEvent<SharedBwoinkSystem.BwoinkDiscordRelayUpdated>(DiscordRelayUpdated);
|
||||
}
|
||||
|
||||
public void OnStateEntered(GameplayState state)
|
||||
{
|
||||
@@ -71,7 +80,6 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
|
||||
EnsureUIHelper();
|
||||
}
|
||||
|
||||
|
||||
private void AHelpButtonPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
EnsureUIHelper();
|
||||
@@ -129,6 +137,12 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
|
||||
UIHelper!.Receive(message);
|
||||
}
|
||||
|
||||
private void DiscordRelayUpdated(SharedBwoinkSystem.BwoinkDiscordRelayUpdated args, EntitySessionEventArgs session)
|
||||
{
|
||||
_discordRelayActive = args.DiscordRelayEnabled;
|
||||
UIHelper?.DiscordRelayChanged(_discordRelayActive);
|
||||
}
|
||||
|
||||
public void EnsureUIHelper()
|
||||
{
|
||||
var isAdmin = _adminManager.HasFlag(AdminFlags.Adminhelp);
|
||||
@@ -139,6 +153,7 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
|
||||
UIHelper?.Dispose();
|
||||
var ownerUserId = _playerManager.LocalPlayer!.UserId;
|
||||
UIHelper = isAdmin ? new AdminAHelpUIHandler(ownerUserId) : new UserAHelpUIHandler(ownerUserId);
|
||||
UIHelper.DiscordRelayChanged(_discordRelayActive);
|
||||
|
||||
UIHelper.SendMessageAction = (userId, textMessage) => _bwoinkSystem?.Send(userId, textMessage);
|
||||
UIHelper.OnClose += () => { SetAHelpPressed(false); };
|
||||
@@ -161,14 +176,15 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
|
||||
EnsureUIHelper();
|
||||
if (UIHelper!.IsOpen)
|
||||
return;
|
||||
UIHelper!.Open(localPlayer.UserId);
|
||||
UIHelper!.Open(localPlayer.UserId, _discordRelayActive);
|
||||
}
|
||||
|
||||
public void Open(NetUserId userId)
|
||||
{
|
||||
EnsureUIHelper();
|
||||
if (!UIHelper!.IsAdmin)
|
||||
return;
|
||||
UIHelper?.Open(userId);
|
||||
UIHelper?.Open(userId, _discordRelayActive);
|
||||
}
|
||||
|
||||
public void ToggleWindow()
|
||||
@@ -177,7 +193,6 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
|
||||
UIHelper?.ToggleWindow();
|
||||
}
|
||||
|
||||
|
||||
public void PopOut()
|
||||
{
|
||||
EnsureUIHelper();
|
||||
@@ -223,8 +238,9 @@ public interface IAHelpUIHandler : IDisposable
|
||||
public bool IsOpen { get; }
|
||||
public void Receive(SharedBwoinkSystem.BwoinkTextMessage message);
|
||||
public void Close();
|
||||
public void Open(NetUserId netUserId);
|
||||
public void Open(NetUserId netUserId, bool relayActive);
|
||||
public void ToggleWindow();
|
||||
public void DiscordRelayChanged(bool active);
|
||||
public event Action OnClose;
|
||||
public event Action OnOpen;
|
||||
public Action<NetUserId, string>? 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<NetUserId, string>? 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<NetUserId, string>? 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(); };
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class BwoinkDiscordRelayUpdated : EntityEventArgs
|
||||
{
|
||||
public bool DiscordRelayEnabled { get; }
|
||||
|
||||
public BwoinkDiscordRelayUpdated(bool enabled)
|
||||
{
|
||||
DiscordRelayEnabled = enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user