Ahelp popout button (#13547)

This commit is contained in:
Kara
2023-01-17 12:47:52 -06:00
committed by GitHub
parent cdcfd4ce01
commit 4e6bb1f46e
8 changed files with 233 additions and 84 deletions

View File

@@ -0,0 +1,25 @@
<Control
xmlns="https://spacestation14.io"
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client">
<PanelContainer>
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BackgroundColor="#25252A"/>
</PanelContainer.PanelOverride>
<SplitContainer Orientation="Horizontal" VerticalExpand="True">
<cc:PlayerListControl Access="Public" Name="ChannelSelector" HorizontalExpand="True" SizeFlagsStretchRatio="1" />
<BoxContainer Orientation="Vertical" HorizontalExpand="True" SizeFlagsStretchRatio="2">
<BoxContainer Access="Public" Name="BwoinkArea" VerticalExpand="True" />
<BoxContainer Orientation="Horizontal" HorizontalAlignment="Right">
<Button Margin="0 0 10 0" Visible="True" Name="PopOut" Access="Public" Text="{Loc 'admin-logs-pop-out'}"/>
<Button Visible="False" Name="Bans" Text="{Loc 'admin-player-actions-bans'}" />
<Button Visible="False" Name="Notes" Text="{Loc 'admin-player-actions-notes'}" />
<Button Visible="False" Name="Kick" Text="{Loc 'admin-player-actions-kick'}" />
<Button Visible="False" Name="Ban" Text="{Loc 'admin-player-actions-ban'}" />
<Button Visible="False" Name="Respawn" Text="{Loc 'admin-player-actions-respawn'}" />
<Button Visible="False" Name="Teleport" Text="{Loc 'admin-player-actions-teleport'}" />
</BoxContainer>
</BoxContainer>
</SplitContainer>
</PanelContainer>
</Control>

View File

@@ -1,4 +1,4 @@
using System.Text;
using System.Text;
using System.Threading;
using Content.Client.Administration.Managers;
using Content.Client.Administration.UI.CustomControls;
@@ -16,27 +16,33 @@ using Robust.Shared.Network;
using Robust.Shared.Utility;
using Timer = Robust.Shared.Timing.Timer;
namespace Content.Client.Administration.UI
namespace Content.Client.Administration.UI.Bwoink
{
/// <summary>
/// This window connects to a BwoinkSystem channel. BwoinkSystem manages the rest.
/// </summary>
[GenerateTypedNameReferences]
public sealed partial class BwoinkWindow : DefaultWindow
public sealed partial class BwoinkControl : Control
{
[Dependency] private readonly IClientAdminManager _adminManager = default!;
[Dependency] private readonly IClientConsoleHost _console = default!;
private readonly AdminAHelpUIHandler _adminAHelpHelper;
[Dependency] private readonly IUserInterfaceManager _ui = default!;
public AdminAHelpUIHandler AHelpHelper = default!;
//private readonly BwoinkSystem _bwoinkSystem;
private PlayerInfo? _currentPlayer = default;
public BwoinkWindow(AdminAHelpUIHandler adminAHelpHelper)
public BwoinkControl()
{
_adminAHelpHelper = adminAHelpHelper;
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
var uiController = _ui.GetUIController<AHelpUIController>();
if (uiController.UIHelper is not AdminAHelpUIHandler helper)
return;
AHelpHelper = helper;
_adminManager.AdminStatusUpdated += FixButtons;
FixButtons();
@@ -46,7 +52,6 @@ namespace Content.Client.Administration.UI
if (sel is not null)
{
SwitchToChannel(sel.SessionId);
Title = $"{sel.CharacterName} / {sel.Username}";
}
ChannelSelector.PlayerListContainer.DirtyList();
@@ -62,7 +67,7 @@ namespace Content.Client.Administration.UI
sb.Append(info.ActiveThisRound ? '○' : '·');
sb.Append(' ');
if (_adminAHelpHelper.TryGetChannel(info.SessionId, out var panel) && panel.Unread > 0)
if (AHelpHelper.TryGetChannel(info.SessionId, out var panel) && panel.Unread > 0)
{
if (panel.Unread < 11)
sb.Append(new Rune('➀' + (panel.Unread-1)));
@@ -81,8 +86,8 @@ namespace Content.Client.Administration.UI
ChannelSelector.Comparison = (a, b) =>
{
var ach = _adminAHelpHelper.EnsurePanel(a.SessionId);
var bch = _adminAHelpHelper.EnsurePanel(b.SessionId);
var ach = AHelpHelper.EnsurePanel(a.SessionId);
var bch = AHelpHelper.EnsurePanel(b.SessionId);
// First, sort by unread. Any chat with unread messages appears first. We just sort based on unread
// status, not number of unread messages, so that more recent unread messages take priority.
@@ -153,7 +158,10 @@ namespace Content.Client.Administration.UI
_console.ExecuteCommand($"respawn \"{_currentPlayer.Username}\"");
};
OnOpen += () => ChannelSelector.PopulateList();
PopOut.OnPressed += _ =>
{
uiController.PopOut();
};
}
private Dictionary<Control, (CancellationTokenSource cancellation, string? originalText)> Confirmations { get; } = new();
@@ -199,7 +207,7 @@ namespace Content.Client.Administration.UI
var sb = new StringBuilder();
sb.Append(pl.Connected ? '●' : '○');
sb.Append(' ');
if (_adminAHelpHelper.TryGetChannel(pl.SessionId, out var panel) && panel.Unread > 0)
if (AHelpHelper.TryGetChannel(pl.SessionId, out var panel) && panel.Unread > 0)
{
if (panel.Unread < 11)
sb.Append(new Rune('➀' + (panel.Unread-1)));
@@ -225,7 +233,7 @@ namespace Content.Client.Administration.UI
{
foreach (var bw in BwoinkArea.Children)
bw.Visible = false;
var panel = _adminAHelpHelper.EnsurePanel(ch);
var panel = AHelpHelper.EnsurePanel(ch);
panel.Visible = true;
}

View File

@@ -1,15 +1,11 @@
#nullable enable
using System;
using Content.Client.Administration.Systems;
using Content.Client.UserInterface.Systems.Bwoink;
using Content.Shared.Administration;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Network;
using Robust.Shared.Utility;
using Content.Client.Administration.UI.CustomControls;
namespace Content.Client.Administration.UI.CustomControls
namespace Content.Client.Administration.UI.Bwoink
{
[GenerateTypedNameReferences]
public sealed partial class BwoinkPanel : BoxContainer

View File

@@ -0,0 +1,8 @@
<DefaultWindow xmlns="https://spacestation14.io"
xmlns:cc="clr-namespace:Content.Client.Administration.UI.Bwoink"
SetSize="900 500"
HeaderClass="windowHeaderAlert"
TitleClass="windowTitleAlert"
Title="{Loc 'bwoink-user-title'}" >
<cc:BwoinkControl Name="Bwoink" Access="Public"/>
</DefaultWindow>

View File

@@ -0,0 +1,42 @@
using System.Text;
using System.Threading;
using Content.Client.Administration.Managers;
using Content.Client.Administration.UI.CustomControls;
using Content.Client.Administration.UI.Tabs.AdminTab;
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Systems.Bwoink;
using Content.Shared.Administration;
using Robust.Client.AutoGenerated;
using Robust.Client.Console;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Network;
using Robust.Shared.Utility;
using Timer = Robust.Shared.Timing.Timer;
namespace Content.Client.Administration.UI.Bwoink
{
/// <summary>
/// This window connects to a BwoinkSystem channel. BwoinkSystem manages the rest.
/// </summary>
[GenerateTypedNameReferences]
public sealed partial class BwoinkWindow : DefaultWindow
{
public BwoinkWindow()
{
RobustXamlLoader.Load(this);
Bwoink.ChannelSelector.OnSelectionChanged += sel =>
{
if (sel is not null)
{
Title = $"{sel.CharacterName} / {sel.Username}";
}
};
OnOpen += () => Bwoink.ChannelSelector.PopulateList();
}
}
}

View File

@@ -1,22 +0,0 @@
<DefaultWindow
xmlns="https://spacestation14.io"
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
SetSize="900 500"
HeaderClass="windowHeaderAlert"
TitleClass="windowTitleAlert"
Title="{Loc 'bwoink-user-title'}" >
<SplitContainer Orientation="Horizontal">
<cc:PlayerListControl Access="Public" Name="ChannelSelector" HorizontalExpand="True" SizeFlagsStretchRatio="1" />
<BoxContainer Orientation="Vertical" HorizontalExpand="True" SizeFlagsStretchRatio="2">
<BoxContainer Access="Public" Name="BwoinkArea" VerticalExpand="True" />
<BoxContainer Orientation="Horizontal" HorizontalAlignment="Right">
<Button Visible="False" Name="Bans" Text="{Loc 'admin-player-actions-bans'}" />
<Button Visible="False" Name="Notes" Text="{Loc 'admin-player-actions-notes'}" />
<Button Visible="False" Name="Kick" Text="{Loc 'admin-player-actions-kick'}" />
<Button Visible="False" Name="Ban" Text="{Loc 'admin-player-actions-ban'}" />
<Button Visible="False" Name="Respawn" Text="{Loc 'admin-player-actions-respawn'}" />
<Button Visible="False" Name="Teleport" Text="{Loc 'admin-player-actions-teleport'}" />
</BoxContainer>
</BoxContainer>
</SplitContainer>
</DefaultWindow>

View File

@@ -1,7 +1,9 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Client.Administration.Managers;
using Content.Client.Administration.Systems;
using Content.Client.Administration.UI;
using Content.Client.Administration.UI.Bwoink;
using Content.Client.Administration.UI.CustomControls;
using Content.Client.Gameplay;
using Content.Client.UserInterface.Controls;
@@ -11,6 +13,7 @@ using Content.Shared.Input;
using JetBrains.Annotations;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
@@ -19,6 +22,7 @@ using Robust.Shared.Input.Binding;
using Robust.Shared.Network;
using Robust.Shared.Player;
using Robust.Shared.Utility;
using BwoinkPanel = Content.Client.Administration.UI.Bwoink.BwoinkPanel;
namespace Content.Client.UserInterface.Systems.Bwoink;
@@ -28,13 +32,14 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
[Dependency] private readonly IClientAdminManager _adminManager = default!;
[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;
private IAHelpUIHandler? _uiHelper;
public IAHelpUIHandler? UIHelper;
public void OnStateEntered(GameplayState state)
{
DebugTools.Assert(_uiHelper == null);
DebugTools.Assert(UIHelper == null);
_adminManager.AdminStatusUpdated += OnAdminStatusUpdated;
CommandBinds.Builder
@@ -65,23 +70,24 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
private void OnAdminStatusUpdated()
{
if (_uiHelper is not { IsOpen: true })
if (UIHelper is not { IsOpen: true })
return;
EnsureUIHelper();
}
private void AHelpButtonPressed(BaseButton.ButtonEventArgs obj)
{
EnsureUIHelper();
_uiHelper!.ToggleWindow();
UIHelper!.ToggleWindow();
}
public void OnStateExited(GameplayState state)
{
SetAHelpPressed(false);
_adminManager.AdminStatusUpdated -= OnAdminStatusUpdated;
_uiHelper?.Dispose();
_uiHelper = null;
UIHelper?.Dispose();
UIHelper = null;
CommandBinds.Unregister<AHelpUIController>();
}
public void OnSystemLoaded(BwoinkSystem system)
@@ -120,33 +126,33 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
}
EnsureUIHelper();
if (!_uiHelper!.IsOpen)
if (!UIHelper!.IsOpen)
{
AhelpButton?.StyleClasses.Add(MenuButton.StyleClassRedTopButton);
}
_uiHelper!.Receive(message);
UIHelper!.Receive(message);
}
public void EnsureUIHelper()
{
var isAdmin = _adminManager.HasFlag(AdminFlags.Adminhelp);
if (_uiHelper != null && _uiHelper.IsAdmin == isAdmin)
if (UIHelper != null && UIHelper.IsAdmin == isAdmin)
return;
_uiHelper?.Dispose();
UIHelper?.Dispose();
var ownerUserId = _playerManager!.LocalPlayer!.UserId;
_uiHelper = isAdmin ? new AdminAHelpUIHandler(ownerUserId) : new UserAHelpUIHandler(ownerUserId);
UIHelper = isAdmin ? new AdminAHelpUIHandler(ownerUserId) : new UserAHelpUIHandler(ownerUserId);
_uiHelper.SendMessageAction = (userId, textMessage) => _bwoinkSystem?.Send(userId, textMessage);
_uiHelper.OnClose += () => { SetAHelpPressed(false); };
_uiHelper.OnOpen += () => { SetAHelpPressed(true); };
SetAHelpPressed(_uiHelper.IsOpen);
UIHelper.SendMessageAction = (userId, textMessage) => _bwoinkSystem?.Send(userId, textMessage);
UIHelper.OnClose += () => { SetAHelpPressed(false); };
UIHelper.OnOpen += () => { SetAHelpPressed(true); };
SetAHelpPressed(UIHelper.IsOpen);
}
public void Close()
{
_uiHelper?.Close();
UIHelper?.Close();
}
public void Open()
@@ -157,24 +163,63 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
return;
}
EnsureUIHelper();
if (_uiHelper!.IsOpen)
if (UIHelper!.IsOpen)
return;
_uiHelper!.Open(localPlayer.UserId);
UIHelper!.Open(localPlayer.UserId);
}
public void Open(NetUserId userId)
{
EnsureUIHelper();
if (!_uiHelper!.IsAdmin)
if (!UIHelper!.IsAdmin)
return;
_uiHelper?.Open(userId);
UIHelper?.Open(userId);
}
public void ToggleWindow()
{
EnsureUIHelper();
_uiHelper?.ToggleWindow();
UIHelper?.ToggleWindow();
}
public void PopOut()
{
EnsureUIHelper();
if (UIHelper is not AdminAHelpUIHandler helper)
return;
if (helper.Window == null || helper.Control == null)
{
return;
}
helper.Control.Orphan();
helper.Window.Dispose();
helper.Window = null;
var monitor = _clyde.EnumerateMonitors().First();
helper.ClydeWindow = _clyde.CreateWindow(new WindowCreateParameters
{
Maximized = false,
Title = "Admin Help",
Monitor = monitor,
Width = 900,
Height = 500
});
helper.ClydeWindow.RequestClosed += helper.OnRequestClosed;
helper.ClydeWindow.DisposeOnClose = true;
helper.WindowRoot = _uiManager.CreateWindowRoot(helper.ClydeWindow);
helper.WindowRoot.AddChild(helper.Control);
helper.Control.PopOut.Disabled = true;
helper.Control.PopOut.Visible = false;
}
}
// please kill all this indirection
public interface IAHelpUIHandler: IDisposable
{
public bool IsAdmin { get; }
@@ -196,31 +241,54 @@ public sealed class AdminAHelpUIHandler : IAHelpUIHandler
}
private readonly Dictionary<NetUserId, BwoinkPanel> _activePanelMap = new();
public bool IsAdmin => true;
public bool IsOpen => _window is { Disposed: false, IsOpen: true };
private BwoinkWindow? _window;
public bool IsOpen => Window is { Disposed: false, IsOpen: true } || ClydeWindow is { IsDisposed: false };
public BwoinkWindow? Window;
public WindowRoot? WindowRoot;
public IClydeWindow? ClydeWindow;
public BwoinkControl? Control;
public void Receive(SharedBwoinkSystem.BwoinkTextMessage message)
{
var window = EnsurePanel(message.UserId);
window.ReceiveLine(message);
_window?.OnBwoink(message.UserId);
var panel = EnsurePanel(message.UserId);
panel.ReceiveLine(message);
Control?.OnBwoink(message.UserId);
}
public void Close()
{
_window?.Close();
Window?.Close();
// popped-out window is being closed
if (ClydeWindow != null)
{
ClydeWindow.RequestClosed -= OnRequestClosed;
ClydeWindow.Dispose();
// need to dispose control cause we cant reattach it directly back to the window
// but orphan panels first so -they- can get readded when the window is opened again
if (Control != null)
{
foreach (var (_, panel) in _activePanelMap)
{
panel.Orphan();
}
Control?.Dispose();
}
// window wont be closed here so we will invoke ourselves
OnClose?.Invoke();
}
}
public void ToggleWindow()
{
EnsurePanel(_ownerId);
if (_window!.IsOpen)
if (IsOpen)
{
_window.Close();
Close();
}
else
{
_window.OpenCentered();
Window!.OpenCentered();
}
}
@@ -231,28 +299,46 @@ public sealed class AdminAHelpUIHandler : IAHelpUIHandler
public void Open(NetUserId channelId)
{
SelectChannel(channelId);
_window?.OpenCentered();
Window?.OpenCentered();
}
private void EnsureWindow()
public void OnRequestClosed(WindowRequestClosedEventArgs args)
{
if (_window is { Disposed: false })
return;
_window = new BwoinkWindow(this);
_window.OnClose += () => { OnClose?.Invoke(); };
_window.OnOpen += () => { OnOpen?.Invoke(); };
Close();
}
private void EnsureControl()
{
if (Control is { Disposed: false })
return;
Window = new BwoinkWindow();
Control = Window.Bwoink;
Window.OnClose += () => { OnClose?.Invoke(); };
Window.OnOpen += () => { OnOpen?.Invoke(); };
// need to readd any unattached panels..
foreach (var (_, panel) in _activePanelMap)
{
if (!Control!.BwoinkArea.Children.Contains(panel))
{
Control!.BwoinkArea.AddChild(panel);
}
panel.Visible = false;
}
}
public BwoinkPanel EnsurePanel(NetUserId channelId)
{
EnsureWindow();
EnsureControl();
if (_activePanelMap.TryGetValue(channelId, out var existingPanel))
return existingPanel;
_activePanelMap[channelId] = existingPanel = new BwoinkPanel(text => SendMessageAction?.Invoke(channelId, text));
existingPanel.Visible = false;
if (!_window!.BwoinkArea.Children.Contains(existingPanel))
_window.BwoinkArea.AddChild(existingPanel);
if (!Control!.BwoinkArea.Children.Contains(existingPanel))
Control.BwoinkArea.AddChild(existingPanel);
return existingPanel;
}
@@ -261,13 +347,14 @@ public sealed class AdminAHelpUIHandler : IAHelpUIHandler
private void SelectChannel(NetUserId uid)
{
EnsurePanel(uid);
_window!.SelectChannel(uid);
Control!.SelectChannel(uid);
}
public void Dispose()
{
_window?.Dispose();
_window = null;
Window?.Dispose();
Window = null;
Control = null;
_activePanelMap.Clear();
}
}
@@ -309,6 +396,11 @@ public sealed class UserAHelpUIHandler : IAHelpUIHandler
}
}
// user can't pop out their window.
public void PopOut()
{
}
public event Action? OnClose;
public event Action? OnOpen;
public Action<NetUserId, string>? SendMessageAction { get; set; }