Always show ahelp relay message when the relay is enabled (#14931)
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
<BoxContainer
|
<BoxContainer
|
||||||
xmlns="https://spacestation14.io"
|
xmlns="https://spacestation14.io"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
Orientation="Vertical"
|
Orientation="Vertical"
|
||||||
HorizontalExpand="true">
|
HorizontalExpand="True">
|
||||||
<OutputPanel Name="TextOutput" VerticalExpand="true" />
|
<OutputPanel Name="TextOutput" VerticalExpand="true" />
|
||||||
<HistoryLineEdit Name="SenderLineEdit" />
|
<HistoryLineEdit Name="SenderLineEdit" />
|
||||||
|
<RichTextLabel Name="RelayedToDiscordLabel" Access="Public" Visible="False" />
|
||||||
</BoxContainer>
|
</BoxContainer>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using Robust.Client.AutoGenerated;
|
|||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Client.UserInterface.XAML;
|
using Robust.Client.UserInterface.XAML;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
using Content.Client.Administration.UI.CustomControls;
|
|
||||||
|
|
||||||
namespace Content.Client.Administration.UI.Bwoink
|
namespace Content.Client.Administration.UI.Bwoink
|
||||||
{
|
{
|
||||||
@@ -18,6 +17,13 @@ namespace Content.Client.Administration.UI.Bwoink
|
|||||||
public BwoinkPanel(Action<string> messageSender)
|
public BwoinkPanel(Action<string> messageSender)
|
||||||
{
|
{
|
||||||
RobustXamlLoader.Load(this);
|
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;
|
_messageSender = messageSender;
|
||||||
|
|
||||||
OnVisibilityChanged += c =>
|
OnVisibilityChanged += c =>
|
||||||
|
|||||||
@@ -29,9 +29,18 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
|
|||||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||||
[Dependency] private readonly IClyde _clyde = default!;
|
[Dependency] private readonly IClyde _clyde = default!;
|
||||||
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
|
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
|
||||||
|
|
||||||
private BwoinkSystem? _bwoinkSystem;
|
private BwoinkSystem? _bwoinkSystem;
|
||||||
private MenuButton? AhelpButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.AHelpButton;
|
private MenuButton? AhelpButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.AHelpButton;
|
||||||
public IAHelpUIHandler? UIHelper;
|
public IAHelpUIHandler? UIHelper;
|
||||||
|
private bool _discordRelayActive;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeNetworkEvent<SharedBwoinkSystem.BwoinkDiscordRelayUpdated>(DiscordRelayUpdated);
|
||||||
|
}
|
||||||
|
|
||||||
public void OnStateEntered(GameplayState state)
|
public void OnStateEntered(GameplayState state)
|
||||||
{
|
{
|
||||||
@@ -71,7 +80,6 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
|
|||||||
EnsureUIHelper();
|
EnsureUIHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void AHelpButtonPressed(BaseButton.ButtonEventArgs obj)
|
private void AHelpButtonPressed(BaseButton.ButtonEventArgs obj)
|
||||||
{
|
{
|
||||||
EnsureUIHelper();
|
EnsureUIHelper();
|
||||||
@@ -129,6 +137,12 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
|
|||||||
UIHelper!.Receive(message);
|
UIHelper!.Receive(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void DiscordRelayUpdated(SharedBwoinkSystem.BwoinkDiscordRelayUpdated args, EntitySessionEventArgs session)
|
||||||
|
{
|
||||||
|
_discordRelayActive = args.DiscordRelayEnabled;
|
||||||
|
UIHelper?.DiscordRelayChanged(_discordRelayActive);
|
||||||
|
}
|
||||||
|
|
||||||
public void EnsureUIHelper()
|
public void EnsureUIHelper()
|
||||||
{
|
{
|
||||||
var isAdmin = _adminManager.HasFlag(AdminFlags.Adminhelp);
|
var isAdmin = _adminManager.HasFlag(AdminFlags.Adminhelp);
|
||||||
@@ -139,6 +153,7 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
|
|||||||
UIHelper?.Dispose();
|
UIHelper?.Dispose();
|
||||||
var ownerUserId = _playerManager.LocalPlayer!.UserId;
|
var ownerUserId = _playerManager.LocalPlayer!.UserId;
|
||||||
UIHelper = isAdmin ? new AdminAHelpUIHandler(ownerUserId) : new UserAHelpUIHandler(ownerUserId);
|
UIHelper = isAdmin ? new AdminAHelpUIHandler(ownerUserId) : new UserAHelpUIHandler(ownerUserId);
|
||||||
|
UIHelper.DiscordRelayChanged(_discordRelayActive);
|
||||||
|
|
||||||
UIHelper.SendMessageAction = (userId, textMessage) => _bwoinkSystem?.Send(userId, textMessage);
|
UIHelper.SendMessageAction = (userId, textMessage) => _bwoinkSystem?.Send(userId, textMessage);
|
||||||
UIHelper.OnClose += () => { SetAHelpPressed(false); };
|
UIHelper.OnClose += () => { SetAHelpPressed(false); };
|
||||||
@@ -161,14 +176,15 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
|
|||||||
EnsureUIHelper();
|
EnsureUIHelper();
|
||||||
if (UIHelper!.IsOpen)
|
if (UIHelper!.IsOpen)
|
||||||
return;
|
return;
|
||||||
UIHelper!.Open(localPlayer.UserId);
|
UIHelper!.Open(localPlayer.UserId, _discordRelayActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Open(NetUserId userId)
|
public void Open(NetUserId userId)
|
||||||
{
|
{
|
||||||
EnsureUIHelper();
|
EnsureUIHelper();
|
||||||
if (!UIHelper!.IsAdmin)
|
if (!UIHelper!.IsAdmin)
|
||||||
return;
|
return;
|
||||||
UIHelper?.Open(userId);
|
UIHelper?.Open(userId, _discordRelayActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ToggleWindow()
|
public void ToggleWindow()
|
||||||
@@ -177,7 +193,6 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
|
|||||||
UIHelper?.ToggleWindow();
|
UIHelper?.ToggleWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void PopOut()
|
public void PopOut()
|
||||||
{
|
{
|
||||||
EnsureUIHelper();
|
EnsureUIHelper();
|
||||||
@@ -223,8 +238,9 @@ public interface IAHelpUIHandler : IDisposable
|
|||||||
public bool IsOpen { get; }
|
public bool IsOpen { get; }
|
||||||
public void Receive(SharedBwoinkSystem.BwoinkTextMessage message);
|
public void Receive(SharedBwoinkSystem.BwoinkTextMessage message);
|
||||||
public void Close();
|
public void Close();
|
||||||
public void Open(NetUserId netUserId);
|
public void Open(NetUserId netUserId, bool relayActive);
|
||||||
public void ToggleWindow();
|
public void ToggleWindow();
|
||||||
|
public void DiscordRelayChanged(bool active);
|
||||||
public event Action OnClose;
|
public event Action OnClose;
|
||||||
public event Action OnOpen;
|
public event Action OnOpen;
|
||||||
public Action<NetUserId, string>? SendMessageAction { get; set; }
|
public Action<NetUserId, string>? SendMessageAction { get; set; }
|
||||||
@@ -298,11 +314,15 @@ public sealed class AdminAHelpUIHandler : IAHelpUIHandler
|
|||||||
OpenWindow();
|
OpenWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void DiscordRelayChanged(bool active)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
public event Action? OnClose;
|
public event Action? OnClose;
|
||||||
public event Action? OnOpen;
|
public event Action? OnOpen;
|
||||||
public Action<NetUserId, string>? SendMessageAction { get; set; }
|
public Action<NetUserId, string>? SendMessageAction { get; set; }
|
||||||
|
|
||||||
public void Open(NetUserId channelId)
|
public void Open(NetUserId channelId, bool relayActive)
|
||||||
{
|
{
|
||||||
SelectChannel(channelId);
|
SelectChannel(channelId);
|
||||||
OpenWindow();
|
OpenWindow();
|
||||||
@@ -381,11 +401,12 @@ public sealed class UserAHelpUIHandler : IAHelpUIHandler
|
|||||||
public bool IsOpen => _window is { Disposed: false, IsOpen: true };
|
public bool IsOpen => _window is { Disposed: false, IsOpen: true };
|
||||||
private DefaultWindow? _window;
|
private DefaultWindow? _window;
|
||||||
private BwoinkPanel? _chatPanel;
|
private BwoinkPanel? _chatPanel;
|
||||||
|
private bool _discordRelayActive;
|
||||||
|
|
||||||
public void Receive(SharedBwoinkSystem.BwoinkTextMessage message)
|
public void Receive(SharedBwoinkSystem.BwoinkTextMessage message)
|
||||||
{
|
{
|
||||||
DebugTools.Assert(message.UserId == _ownerId);
|
DebugTools.Assert(message.UserId == _ownerId);
|
||||||
EnsureInit();
|
EnsureInit(_discordRelayActive);
|
||||||
_chatPanel!.ReceiveLine(message);
|
_chatPanel!.ReceiveLine(message);
|
||||||
_window!.OpenCentered();
|
_window!.OpenCentered();
|
||||||
}
|
}
|
||||||
@@ -397,7 +418,7 @@ public sealed class UserAHelpUIHandler : IAHelpUIHandler
|
|||||||
|
|
||||||
public void ToggleWindow()
|
public void ToggleWindow()
|
||||||
{
|
{
|
||||||
EnsureInit();
|
EnsureInit(_discordRelayActive);
|
||||||
if (_window!.IsOpen)
|
if (_window!.IsOpen)
|
||||||
{
|
{
|
||||||
_window.Close();
|
_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? OnClose;
|
||||||
public event Action? OnOpen;
|
public event Action? OnOpen;
|
||||||
public Action<NetUserId, string>? SendMessageAction { get; set; }
|
public Action<NetUserId, string>? SendMessageAction { get; set; }
|
||||||
|
|
||||||
public void Open(NetUserId channelId)
|
public void Open(NetUserId channelId, bool relayActive)
|
||||||
{
|
{
|
||||||
EnsureInit();
|
EnsureInit(relayActive);
|
||||||
_window!.OpenCentered();
|
_window!.OpenCentered();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EnsureInit()
|
private void EnsureInit(bool relayActive)
|
||||||
{
|
{
|
||||||
if (_window is { Disposed: false })
|
if (_window is { Disposed: false })
|
||||||
return;
|
return;
|
||||||
_chatPanel = new BwoinkPanel(text => SendMessageAction?.Invoke(_ownerId, text));
|
_chatPanel = new BwoinkPanel(text => SendMessageAction?.Invoke(_ownerId, text));
|
||||||
|
_chatPanel.RelayedToDiscordLabel.Visible = relayActive;
|
||||||
_window = new DefaultWindow()
|
_window = new DefaultWindow()
|
||||||
{
|
{
|
||||||
TitleClass="windowTitleAlert",
|
TitleClass="windowTitleAlert",
|
||||||
HeaderClass="windowHeaderAlert",
|
HeaderClass="windowHeaderAlert",
|
||||||
Title=Loc.GetString("bwoink-user-title"),
|
Title=Loc.GetString("bwoink-user-title"),
|
||||||
SetSize=(400, 200),
|
MinSize=(500, 200),
|
||||||
};
|
};
|
||||||
_window.OnClose += () => { OnClose?.Invoke(); };
|
_window.OnClose += () => { OnClose?.Invoke(); };
|
||||||
_window.OnOpen += () => { OnOpen?.Invoke(); };
|
_window.OnOpen += () => { OnOpen?.Invoke(); };
|
||||||
|
|||||||
@@ -109,6 +109,8 @@ namespace Content.Server.Administration.Systems
|
|||||||
{
|
{
|
||||||
_webhookUrl = url;
|
_webhookUrl = url;
|
||||||
|
|
||||||
|
RaiseNetworkEvent(new BwoinkDiscordRelayUpdated(!string.IsNullOrWhiteSpace(url)));
|
||||||
|
|
||||||
if (url == string.Empty)
|
if (url == string.Empty)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -395,13 +397,11 @@ namespace Content.Server.Administration.Systems
|
|||||||
_messageQueues[msg.UserId].Enqueue(GenerateAHelpMessage(senderSession.Name, str, !personalChannel, admins.Count == 0));
|
_messageQueues[msg.UserId].Enqueue(GenerateAHelpMessage(senderSession.Name, str, !personalChannel, admins.Count == 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (admins.Count != 0)
|
if (admins.Count != 0 || sendsWebhook)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// No admin online, let the player know
|
// No admin online, let the player know
|
||||||
var systemText = sendsWebhook ?
|
var systemText = Loc.GetString("bwoink-system-starmute-message-no-other-users");
|
||||||
Loc.GetString("bwoink-system-starmute-message-no-other-users-webhook") :
|
|
||||||
Loc.GetString("bwoink-system-starmute-message-no-other-users");
|
|
||||||
var starMuteMsg = new BwoinkTextMessage(message.UserId, SystemUserId, systemText);
|
var starMuteMsg = new BwoinkTextMessage(message.UserId, SystemUserId, systemText);
|
||||||
RaiseNetworkEvent(starMuteMsg, senderSession.ConnectedClient);
|
RaiseNetworkEvent(starMuteMsg, senderSession.ConnectedClient);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ namespace Content.Shared.Administration
|
|||||||
public sealed class BwoinkTextMessage : EntityEventArgs
|
public sealed class BwoinkTextMessage : EntityEventArgs
|
||||||
{
|
{
|
||||||
public DateTime SentAt { get; }
|
public DateTime SentAt { get; }
|
||||||
|
|
||||||
public NetUserId UserId { get; }
|
public NetUserId UserId { get; }
|
||||||
|
|
||||||
// This is ignored from the client.
|
// This is ignored from the client.
|
||||||
// It's checked by the client when receiving a message from the server for bwoink noises.
|
// 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.
|
// This could be a boolean "Incoming", but that would require making a second instance.
|
||||||
@@ -44,5 +46,20 @@ namespace Content.Shared.Administration
|
|||||||
Text = text;
|
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 = *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