Administration: Ahelp tabs (#5965)
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Client.Administration.Managers;
|
||||
using Content.Client.Administration.UI;
|
||||
using Content.Client.Administration.UI.CustomControls;
|
||||
using Content.Shared.Administration;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Network;
|
||||
@@ -16,18 +22,21 @@ namespace Content.Client.Administration
|
||||
[UsedImplicitly]
|
||||
public class BwoinkSystem : SharedBwoinkSystem
|
||||
{
|
||||
[Dependency] private readonly IClientAdminManager _adminManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IClyde _clyde = default!;
|
||||
|
||||
private readonly Dictionary<NetUserId, BwoinkWindow> _activeWindowMap = new();
|
||||
private BwoinkWindow? _adminWindow;
|
||||
private DefaultWindow? _plainWindow;
|
||||
private readonly Dictionary<NetUserId, BwoinkPanel> _activePanelMap = new();
|
||||
|
||||
protected override void OnBwoinkTextMessage(BwoinkTextMessage message, EntitySessionEventArgs eventArgs)
|
||||
{
|
||||
base.OnBwoinkTextMessage(message, eventArgs);
|
||||
LogBwoink(message);
|
||||
// Actual line
|
||||
var window = EnsureWindow(message.ChannelId);
|
||||
window.ReceiveLine(message.Text);
|
||||
var window = EnsurePanel(message.ChannelId);
|
||||
window.ReceiveLine($"[color=gray]{message.SentAt.ToShortTimeString()}[/color] {message.Text}");
|
||||
// Play a sound if we didn't send it
|
||||
var localPlayer = _playerManager.LocalPlayer;
|
||||
if (localPlayer?.UserId != message.TrueSender)
|
||||
@@ -35,27 +44,67 @@ namespace Content.Client.Administration
|
||||
SoundSystem.Play(Filter.Local(), "/Audio/Effects/adminhelp.ogg");
|
||||
_clyde.RequestWindowAttention();
|
||||
}
|
||||
|
||||
_adminWindow?.OnBwoink(message.ChannelId);
|
||||
}
|
||||
|
||||
public BwoinkWindow EnsureWindow(NetUserId channelId)
|
||||
public bool TryGetChannel(NetUserId ch, [NotNullWhen(true)] out BwoinkPanel? bp) => _activePanelMap.TryGetValue(ch, out bp);
|
||||
|
||||
private BwoinkPanel EnsureAdmin(NetUserId channelId)
|
||||
{
|
||||
if (!_activeWindowMap.TryGetValue(channelId, out var existingWindow))
|
||||
_adminWindow ??= new BwoinkWindow(this);
|
||||
|
||||
if (!_activePanelMap.TryGetValue(channelId, out var existingPanel))
|
||||
{
|
||||
_activeWindowMap[channelId] = existingWindow = new BwoinkWindow(channelId,
|
||||
_playerManager.SessionsDict.TryGetValue(channelId, out var otherSession)
|
||||
? otherSession.Name
|
||||
: channelId.ToString());
|
||||
_activePanelMap[channelId] = existingPanel = new BwoinkPanel(this, channelId);
|
||||
existingPanel.Visible = false;
|
||||
if (!_adminWindow.BwoinkArea.Children.Contains(existingPanel))
|
||||
_adminWindow.BwoinkArea.AddChild(existingPanel);
|
||||
}
|
||||
|
||||
existingWindow.Open();
|
||||
return existingWindow;
|
||||
_adminWindow.Open();
|
||||
|
||||
return existingPanel;
|
||||
}
|
||||
|
||||
public void EnsureWindowForLocalPlayer()
|
||||
private BwoinkPanel EnsurePlain(NetUserId channelId)
|
||||
{
|
||||
BwoinkPanel bp;
|
||||
if (_plainWindow is null)
|
||||
{
|
||||
bp = new BwoinkPanel(this, channelId);
|
||||
_plainWindow = new DefaultWindow()
|
||||
{
|
||||
TitleClass="windowTitleAlert",
|
||||
HeaderClass="windowHeaderAlert",
|
||||
Title=Loc.GetString("bwoink-user-title"),
|
||||
SetSize=(400, 200),
|
||||
};
|
||||
|
||||
_plainWindow.Contents.AddChild(bp);
|
||||
}
|
||||
else
|
||||
{
|
||||
bp = (BwoinkPanel) _plainWindow.Contents.GetChild(0);
|
||||
}
|
||||
|
||||
_plainWindow.Open();
|
||||
return bp;
|
||||
}
|
||||
|
||||
public BwoinkPanel EnsurePanel(NetUserId channelId)
|
||||
{
|
||||
if (_adminManager.HasFlag(AdminFlags.Adminhelp))
|
||||
return EnsureAdmin(channelId);
|
||||
|
||||
return EnsurePlain(channelId);
|
||||
}
|
||||
|
||||
public void EnsurePanelForLocalPlayer()
|
||||
{
|
||||
var localPlayer = _playerManager.LocalPlayer;
|
||||
if (localPlayer != null)
|
||||
EnsureWindow(localPlayer.UserId);
|
||||
EnsurePanel(localPlayer.UserId);
|
||||
}
|
||||
|
||||
public void Send(NetUserId channelId, string text)
|
||||
|
||||
Reference in New Issue
Block a user