Skip to content

Commit

Permalink
[Feature] Bringing back old ahelp sound (#48)
Browse files Browse the repository at this point in the history
feat: bring back the old ahelp sound
  • Loading branch information
Remuchi authored Sep 9, 2024
1 parent a5508cb commit 0e86495
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 27 deletions.
12 changes: 1 addition & 11 deletions Content.Client/Administration/Systems/BwoinkSystem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
#nullable enable
using Content.Client.UserInterface.Systems.Bwoink;
using Content.Shared.Administration;
using Content.Shared.Administration;
using JetBrains.Annotations;
using Robust.Client.Audio;
using Robust.Shared.Network;
using Robust.Shared.Player;
using Robust.Shared.Timing;

namespace Content.Client.Administration.Systems
Expand All @@ -13,8 +9,6 @@ namespace Content.Client.Administration.Systems
public sealed class BwoinkSystem : SharedBwoinkSystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly AudioSystem _audio = default!;
[Dependency] private readonly AdminSystem _adminSystem = default!;

public event EventHandler<BwoinkTextMessage>? OnBwoinkTextMessageRecieved;
private (TimeSpan Timestamp, bool Typing) _lastTypingUpdateSent;
Expand All @@ -26,10 +20,6 @@ protected override void OnBwoinkTextMessage(BwoinkTextMessage message, EntitySes

public void Send(NetUserId channelId, string text, bool playSound)
{
var info = _adminSystem.PlayerInfos.GetValueOrDefault(channelId)?.Connected ?? true;
_audio.PlayGlobal(info ? AHelpUIController.AHelpSendSound : AHelpUIController.AHelpErrorSound,
Filter.Local(), false);

// Reuse the channel ID as the 'true sender'.
// Server will ignore this and if someone makes it not ignore this (which is bad, allows impersonation!!!), that will help.
RaiseNetworkEvent(new BwoinkTextMessage(channelId, channelId, text, playSound: playSound));
Expand Down
40 changes: 24 additions & 16 deletions Content.Client/UserInterface/Systems/Bwoink/AHelpUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Content.Client.UserInterface.Controls;
using Content.Client.UserInterface.Systems.MenuBar.Widgets;
using Content.Shared.Administration;
using Content.Shared.CCVar;
using Content.Shared.Input;
using JetBrains.Annotations;
using Robust.Client.Audio;
Expand All @@ -21,7 +20,6 @@
using Robust.Client.UserInterface.Controllers;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Configuration;
using Robust.Shared.Input.Binding;
using Robust.Shared.Network;
using Robust.Shared.Player;
Expand All @@ -30,7 +28,8 @@
namespace Content.Client.UserInterface.Systems.Bwoink;

[UsedImplicitly]
public sealed class AHelpUIController: UIController, IOnSystemChanged<BwoinkSystem>, IOnStateChanged<GameplayState>, IOnStateChanged<LobbyState>
public sealed class AHelpUIController : UIController, IOnSystemChanged<BwoinkSystem>, IOnStateChanged<GameplayState>,
IOnStateChanged<LobbyState>
{
[Dependency] private readonly IClientAdminManager _adminManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
Expand All @@ -46,10 +45,7 @@ public sealed class AHelpUIController: UIController, IOnSystemChanged<BwoinkSyst
private bool _discordRelayActive;
private bool _hasUnreadAHelp;

public const string AHelpErrorSound = "/Audio/Admin/ahelp_error.ogg";
public const string AHelpReceiveSound = "/Audio/Admin/ahelp_receive.ogg";
public const string AHelpSendSound = "/Audio/Admin/ahelp_send.ogg";

private const string AHelpReceiveSound = "/Audio/Admin/bwoink.ogg";

public override void Initialize()
{
Expand All @@ -61,7 +57,6 @@ public override void Initialize()
_adminManager.AdminStatusUpdated += OnAdminStatusUpdated;
}


public void UnloadButton()
{
if (GameAHelpButton != null)
Expand Down Expand Up @@ -134,7 +129,7 @@ private void ReceivedBwoink(object? sender, SharedBwoinkSystem.BwoinkTextMessage

EnsureUIHelper();

if (message.PlaySound && localPlayer.UserId != message.TrueSender && !UIHelper!.IsOpen)
if (message.PlaySound && !UIHelper!.IsOpen)
{
_audio.PlayGlobal(AHelpReceiveSound, Filter.Local(), false);
_clyde.RequestWindowAttention();
Expand Down Expand Up @@ -169,10 +164,11 @@ public void EnsureUIHelper()
UIHelper = isAdmin ? new AdminAHelpUIHandler(ownerUserId) : new UserAHelpUIHandler(ownerUserId);
UIHelper.DiscordRelayChanged(_discordRelayActive);

UIHelper.SendMessageAction = (userId, textMessage, playSound) => _bwoinkSystem?.Send(userId, textMessage, playSound);
UIHelper.SendMessageAction =
(userId, textMessage, playSound) => _bwoinkSystem?.Send(userId, textMessage, playSound);
UIHelper.InputTextChanged += (channel, text) => _bwoinkSystem?.SendInputTextUpdated(channel, text.Length > 0);
UIHelper.OnClose += () => { SetAHelpPressed(false); };
UIHelper.OnOpen += () => { SetAHelpPressed(true); };
UIHelper.OnOpen += () => { SetAHelpPressed(true); };
SetAHelpPressed(UIHelper.IsOpen);
}

Expand All @@ -183,6 +179,7 @@ public void Open()
{
return;
}

EnsureUIHelper();
if (UIHelper!.IsOpen)
return;
Expand Down Expand Up @@ -321,13 +318,16 @@ public interface IAHelpUIHandler : IDisposable
public Action<NetUserId, string, bool>? SendMessageAction { get; set; }
public event Action<NetUserId, string>? InputTextChanged;
}

public sealed class AdminAHelpUIHandler : IAHelpUIHandler
{
private readonly NetUserId _ownerId;

public AdminAHelpUIHandler(NetUserId owner)
{
_ownerId = owner;
}

private readonly Dictionary<NetUserId, BwoinkPanel> _activePanelMap = new();
public bool IsAdmin => true;
public bool IsOpen => Window is { Disposed: false, IsOpen: true } || ClydeWindow is { IsDisposed: false };
Expand Down Expand Up @@ -373,8 +373,10 @@ public void Close()
{
panel.Orphan();
}

Control?.Dispose();
}

// window wont be closed here so we will invoke ourselves
OnClose?.Invoke();
}
Expand Down Expand Up @@ -437,6 +439,7 @@ private void EnsureControl()
{
Control!.BwoinkArea.AddChild(panel);
}

panel.Visible = false;
}
}
Expand All @@ -456,15 +459,18 @@ public BwoinkPanel EnsurePanel(NetUserId channelId)
if (_activePanelMap.TryGetValue(channelId, out var existingPanel))
return existingPanel;

_activePanelMap[channelId] = existingPanel = new BwoinkPanel(text => SendMessageAction?.Invoke(channelId, text, Window?.Bwoink.PlaySound.Pressed ?? true));
_activePanelMap[channelId] = existingPanel = new BwoinkPanel(text =>
SendMessageAction?.Invoke(channelId, text, Window?.Bwoink.PlaySound.Pressed ?? true));
existingPanel.InputTextChanged += text => InputTextChanged?.Invoke(channelId, text);
existingPanel.Visible = false;
if (!Control!.BwoinkArea.Children.Contains(existingPanel))
Control.BwoinkArea.AddChild(existingPanel);

return existingPanel;
}
public bool TryGetChannel(NetUserId ch, [NotNullWhen(true)] out BwoinkPanel? bp) => _activePanelMap.TryGetValue(ch, out bp);

public bool TryGetChannel(NetUserId ch, [NotNullWhen(true)] out BwoinkPanel? bp) =>
_activePanelMap.TryGetValue(ch, out bp);

private void SelectChannel(NetUserId uid)
{
Expand All @@ -485,10 +491,12 @@ public void Dispose()
public sealed class UserAHelpUIHandler : IAHelpUIHandler
{
private readonly NetUserId _ownerId;

public UserAHelpUIHandler(NetUserId owner)
{
_ownerId = owner;
}

public bool IsAdmin => false;
public bool IsOpen => _window is { Disposed: false, IsOpen: true };
private DefaultWindow? _window;
Expand Down Expand Up @@ -560,9 +568,9 @@ private void EnsureInit(bool relayActive)
_chatPanel.RelayedToDiscordLabel.Visible = relayActive;
_window = new DefaultWindow()
{
TitleClass="windowTitleAlert",
HeaderClass="windowHeaderAlert",
Title=Loc.GetString("bwoink-user-title"),
TitleClass = "windowTitleAlert",
HeaderClass = "windowHeaderAlert",
Title = Loc.GetString("bwoink-user-title"),
MinSize = new Vector2(500, 300),
};
_window.OnClose += () => { OnClose?.Invoke(); };
Expand Down
Binary file added Resources/Audio/Admin/bwoink.ogg
Binary file not shown.

0 comments on commit 0e86495

Please sign in to comment.