Ahelp popout button (#13547)
This commit is contained in:
25
Content.Client/Administration/UI/Bwoink/BwoinkControl.xaml
Normal file
25
Content.Client/Administration/UI/Bwoink/BwoinkControl.xaml
Normal 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>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Content.Client.Administration.Managers;
|
using Content.Client.Administration.Managers;
|
||||||
using Content.Client.Administration.UI.CustomControls;
|
using Content.Client.Administration.UI.CustomControls;
|
||||||
@@ -16,27 +16,33 @@ using Robust.Shared.Network;
|
|||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
using Timer = Robust.Shared.Timing.Timer;
|
using Timer = Robust.Shared.Timing.Timer;
|
||||||
|
|
||||||
namespace Content.Client.Administration.UI
|
namespace Content.Client.Administration.UI.Bwoink
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This window connects to a BwoinkSystem channel. BwoinkSystem manages the rest.
|
/// This window connects to a BwoinkSystem channel. BwoinkSystem manages the rest.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[GenerateTypedNameReferences]
|
[GenerateTypedNameReferences]
|
||||||
public sealed partial class BwoinkWindow : DefaultWindow
|
public sealed partial class BwoinkControl : Control
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IClientAdminManager _adminManager = default!;
|
[Dependency] private readonly IClientAdminManager _adminManager = default!;
|
||||||
[Dependency] private readonly IClientConsoleHost _console = 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 readonly BwoinkSystem _bwoinkSystem;
|
||||||
private PlayerInfo? _currentPlayer = default;
|
private PlayerInfo? _currentPlayer = default;
|
||||||
|
|
||||||
public BwoinkWindow(AdminAHelpUIHandler adminAHelpHelper)
|
public BwoinkControl()
|
||||||
{
|
{
|
||||||
_adminAHelpHelper = adminAHelpHelper;
|
|
||||||
RobustXamlLoader.Load(this);
|
RobustXamlLoader.Load(this);
|
||||||
IoCManager.InjectDependencies(this);
|
IoCManager.InjectDependencies(this);
|
||||||
|
|
||||||
|
var uiController = _ui.GetUIController<AHelpUIController>();
|
||||||
|
if (uiController.UIHelper is not AdminAHelpUIHandler helper)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AHelpHelper = helper;
|
||||||
|
|
||||||
_adminManager.AdminStatusUpdated += FixButtons;
|
_adminManager.AdminStatusUpdated += FixButtons;
|
||||||
FixButtons();
|
FixButtons();
|
||||||
|
|
||||||
@@ -46,7 +52,6 @@ namespace Content.Client.Administration.UI
|
|||||||
if (sel is not null)
|
if (sel is not null)
|
||||||
{
|
{
|
||||||
SwitchToChannel(sel.SessionId);
|
SwitchToChannel(sel.SessionId);
|
||||||
Title = $"{sel.CharacterName} / {sel.Username}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ChannelSelector.PlayerListContainer.DirtyList();
|
ChannelSelector.PlayerListContainer.DirtyList();
|
||||||
@@ -62,7 +67,7 @@ namespace Content.Client.Administration.UI
|
|||||||
sb.Append(info.ActiveThisRound ? '○' : '·');
|
sb.Append(info.ActiveThisRound ? '○' : '·');
|
||||||
|
|
||||||
sb.Append(' ');
|
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)
|
if (panel.Unread < 11)
|
||||||
sb.Append(new Rune('➀' + (panel.Unread-1)));
|
sb.Append(new Rune('➀' + (panel.Unread-1)));
|
||||||
@@ -81,8 +86,8 @@ namespace Content.Client.Administration.UI
|
|||||||
|
|
||||||
ChannelSelector.Comparison = (a, b) =>
|
ChannelSelector.Comparison = (a, b) =>
|
||||||
{
|
{
|
||||||
var ach = _adminAHelpHelper.EnsurePanel(a.SessionId);
|
var ach = AHelpHelper.EnsurePanel(a.SessionId);
|
||||||
var bch = _adminAHelpHelper.EnsurePanel(b.SessionId);
|
var bch = AHelpHelper.EnsurePanel(b.SessionId);
|
||||||
|
|
||||||
// First, sort by unread. Any chat with unread messages appears first. We just sort based on unread
|
// 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.
|
// 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}\"");
|
_console.ExecuteCommand($"respawn \"{_currentPlayer.Username}\"");
|
||||||
};
|
};
|
||||||
|
|
||||||
OnOpen += () => ChannelSelector.PopulateList();
|
PopOut.OnPressed += _ =>
|
||||||
|
{
|
||||||
|
uiController.PopOut();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<Control, (CancellationTokenSource cancellation, string? originalText)> Confirmations { get; } = new();
|
private Dictionary<Control, (CancellationTokenSource cancellation, string? originalText)> Confirmations { get; } = new();
|
||||||
@@ -199,7 +207,7 @@ namespace Content.Client.Administration.UI
|
|||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
sb.Append(pl.Connected ? '●' : '○');
|
sb.Append(pl.Connected ? '●' : '○');
|
||||||
sb.Append(' ');
|
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)
|
if (panel.Unread < 11)
|
||||||
sb.Append(new Rune('➀' + (panel.Unread-1)));
|
sb.Append(new Rune('➀' + (panel.Unread-1)));
|
||||||
@@ -225,7 +233,7 @@ namespace Content.Client.Administration.UI
|
|||||||
{
|
{
|
||||||
foreach (var bw in BwoinkArea.Children)
|
foreach (var bw in BwoinkArea.Children)
|
||||||
bw.Visible = false;
|
bw.Visible = false;
|
||||||
var panel = _adminAHelpHelper.EnsurePanel(ch);
|
var panel = AHelpHelper.EnsurePanel(ch);
|
||||||
panel.Visible = true;
|
panel.Visible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,15 +1,11 @@
|
|||||||
#nullable enable
|
|
||||||
using System;
|
|
||||||
using Content.Client.Administration.Systems;
|
|
||||||
using Content.Client.UserInterface.Systems.Bwoink;
|
|
||||||
using Content.Shared.Administration;
|
using Content.Shared.Administration;
|
||||||
using Robust.Client.AutoGenerated;
|
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.Network;
|
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
using Content.Client.Administration.UI.CustomControls;
|
||||||
|
|
||||||
namespace Content.Client.Administration.UI.CustomControls
|
namespace Content.Client.Administration.UI.Bwoink
|
||||||
{
|
{
|
||||||
[GenerateTypedNameReferences]
|
[GenerateTypedNameReferences]
|
||||||
public sealed partial class BwoinkPanel : BoxContainer
|
public sealed partial class BwoinkPanel : BoxContainer
|
||||||
@@ -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>
|
||||||
42
Content.Client/Administration/UI/Bwoink/BwoinkWindow.xaml.cs
Normal file
42
Content.Client/Administration/UI/Bwoink/BwoinkWindow.xaml.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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>
|
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
using Content.Client.Administration.Managers;
|
using Content.Client.Administration.Managers;
|
||||||
using Content.Client.Administration.Systems;
|
using Content.Client.Administration.Systems;
|
||||||
using Content.Client.Administration.UI;
|
using Content.Client.Administration.UI;
|
||||||
|
using Content.Client.Administration.UI.Bwoink;
|
||||||
using Content.Client.Administration.UI.CustomControls;
|
using Content.Client.Administration.UI.CustomControls;
|
||||||
using Content.Client.Gameplay;
|
using Content.Client.Gameplay;
|
||||||
using Content.Client.UserInterface.Controls;
|
using Content.Client.UserInterface.Controls;
|
||||||
@@ -11,6 +13,7 @@ using Content.Shared.Input;
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Client.Graphics;
|
using Robust.Client.Graphics;
|
||||||
using Robust.Client.Player;
|
using Robust.Client.Player;
|
||||||
|
using Robust.Client.UserInterface;
|
||||||
using Robust.Client.UserInterface.Controllers;
|
using Robust.Client.UserInterface.Controllers;
|
||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Client.UserInterface.CustomControls;
|
using Robust.Client.UserInterface.CustomControls;
|
||||||
@@ -19,6 +22,7 @@ using Robust.Shared.Input.Binding;
|
|||||||
using Robust.Shared.Network;
|
using Robust.Shared.Network;
|
||||||
using Robust.Shared.Player;
|
using Robust.Shared.Player;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
using BwoinkPanel = Content.Client.Administration.UI.Bwoink.BwoinkPanel;
|
||||||
|
|
||||||
namespace Content.Client.UserInterface.Systems.Bwoink;
|
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 IClientAdminManager _adminManager = default!;
|
||||||
[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!;
|
||||||
private BwoinkSystem? _bwoinkSystem;
|
private BwoinkSystem? _bwoinkSystem;
|
||||||
private MenuButton? AhelpButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.AHelpButton;
|
private MenuButton? AhelpButton => UIManager.GetActiveUIWidgetOrNull<MenuBar.Widgets.GameTopMenuBar>()?.AHelpButton;
|
||||||
private IAHelpUIHandler? _uiHelper;
|
public IAHelpUIHandler? UIHelper;
|
||||||
|
|
||||||
public void OnStateEntered(GameplayState state)
|
public void OnStateEntered(GameplayState state)
|
||||||
{
|
{
|
||||||
DebugTools.Assert(_uiHelper == null);
|
DebugTools.Assert(UIHelper == null);
|
||||||
_adminManager.AdminStatusUpdated += OnAdminStatusUpdated;
|
_adminManager.AdminStatusUpdated += OnAdminStatusUpdated;
|
||||||
|
|
||||||
CommandBinds.Builder
|
CommandBinds.Builder
|
||||||
@@ -65,23 +70,24 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
|
|||||||
|
|
||||||
private void OnAdminStatusUpdated()
|
private void OnAdminStatusUpdated()
|
||||||
{
|
{
|
||||||
if (_uiHelper is not { IsOpen: true })
|
if (UIHelper is not { IsOpen: true })
|
||||||
return;
|
return;
|
||||||
EnsureUIHelper();
|
EnsureUIHelper();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void AHelpButtonPressed(BaseButton.ButtonEventArgs obj)
|
private void AHelpButtonPressed(BaseButton.ButtonEventArgs obj)
|
||||||
{
|
{
|
||||||
EnsureUIHelper();
|
EnsureUIHelper();
|
||||||
_uiHelper!.ToggleWindow();
|
UIHelper!.ToggleWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnStateExited(GameplayState state)
|
public void OnStateExited(GameplayState state)
|
||||||
{
|
{
|
||||||
SetAHelpPressed(false);
|
SetAHelpPressed(false);
|
||||||
_adminManager.AdminStatusUpdated -= OnAdminStatusUpdated;
|
_adminManager.AdminStatusUpdated -= OnAdminStatusUpdated;
|
||||||
_uiHelper?.Dispose();
|
UIHelper?.Dispose();
|
||||||
_uiHelper = null;
|
UIHelper = null;
|
||||||
CommandBinds.Unregister<AHelpUIController>();
|
CommandBinds.Unregister<AHelpUIController>();
|
||||||
}
|
}
|
||||||
public void OnSystemLoaded(BwoinkSystem system)
|
public void OnSystemLoaded(BwoinkSystem system)
|
||||||
@@ -120,33 +126,33 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
|
|||||||
}
|
}
|
||||||
|
|
||||||
EnsureUIHelper();
|
EnsureUIHelper();
|
||||||
if (!_uiHelper!.IsOpen)
|
if (!UIHelper!.IsOpen)
|
||||||
{
|
{
|
||||||
AhelpButton?.StyleClasses.Add(MenuButton.StyleClassRedTopButton);
|
AhelpButton?.StyleClasses.Add(MenuButton.StyleClassRedTopButton);
|
||||||
}
|
}
|
||||||
_uiHelper!.Receive(message);
|
UIHelper!.Receive(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EnsureUIHelper()
|
public void EnsureUIHelper()
|
||||||
{
|
{
|
||||||
var isAdmin = _adminManager.HasFlag(AdminFlags.Adminhelp);
|
var isAdmin = _adminManager.HasFlag(AdminFlags.Adminhelp);
|
||||||
|
|
||||||
if (_uiHelper != null && _uiHelper.IsAdmin == isAdmin)
|
if (UIHelper != null && UIHelper.IsAdmin == isAdmin)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_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.SendMessageAction = (userId, textMessage) => _bwoinkSystem?.Send(userId, textMessage);
|
UIHelper.SendMessageAction = (userId, textMessage) => _bwoinkSystem?.Send(userId, textMessage);
|
||||||
_uiHelper.OnClose += () => { SetAHelpPressed(false); };
|
UIHelper.OnClose += () => { SetAHelpPressed(false); };
|
||||||
_uiHelper.OnOpen += () => { SetAHelpPressed(true); };
|
UIHelper.OnOpen += () => { SetAHelpPressed(true); };
|
||||||
SetAHelpPressed(_uiHelper.IsOpen);
|
SetAHelpPressed(UIHelper.IsOpen);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
public void Close()
|
||||||
{
|
{
|
||||||
_uiHelper?.Close();
|
UIHelper?.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Open()
|
public void Open()
|
||||||
@@ -157,24 +163,63 @@ public sealed class AHelpUIController: UIController, IOnStateChanged<GameplaySta
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EnsureUIHelper();
|
EnsureUIHelper();
|
||||||
if (_uiHelper!.IsOpen)
|
if (UIHelper!.IsOpen)
|
||||||
return;
|
return;
|
||||||
_uiHelper!.Open(localPlayer.UserId);
|
UIHelper!.Open(localPlayer.UserId);
|
||||||
}
|
}
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ToggleWindow()
|
public void ToggleWindow()
|
||||||
{
|
{
|
||||||
EnsureUIHelper();
|
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 interface IAHelpUIHandler: IDisposable
|
||||||
{
|
{
|
||||||
public bool IsAdmin { get; }
|
public bool IsAdmin { get; }
|
||||||
@@ -196,31 +241,54 @@ public sealed class AdminAHelpUIHandler : IAHelpUIHandler
|
|||||||
}
|
}
|
||||||
private readonly Dictionary<NetUserId, BwoinkPanel> _activePanelMap = new();
|
private readonly Dictionary<NetUserId, BwoinkPanel> _activePanelMap = new();
|
||||||
public bool IsAdmin => true;
|
public bool IsAdmin => true;
|
||||||
public bool IsOpen => _window is { Disposed: false, IsOpen: true };
|
public bool IsOpen => Window is { Disposed: false, IsOpen: true } || ClydeWindow is { IsDisposed: false };
|
||||||
private BwoinkWindow? _window;
|
|
||||||
|
public BwoinkWindow? Window;
|
||||||
|
public WindowRoot? WindowRoot;
|
||||||
|
public IClydeWindow? ClydeWindow;
|
||||||
|
public BwoinkControl? Control;
|
||||||
|
|
||||||
public void Receive(SharedBwoinkSystem.BwoinkTextMessage message)
|
public void Receive(SharedBwoinkSystem.BwoinkTextMessage message)
|
||||||
{
|
{
|
||||||
var window = EnsurePanel(message.UserId);
|
var panel = EnsurePanel(message.UserId);
|
||||||
window.ReceiveLine(message);
|
panel.ReceiveLine(message);
|
||||||
_window?.OnBwoink(message.UserId);
|
Control?.OnBwoink(message.UserId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Close()
|
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()
|
public void ToggleWindow()
|
||||||
{
|
{
|
||||||
EnsurePanel(_ownerId);
|
EnsurePanel(_ownerId);
|
||||||
if (_window!.IsOpen)
|
if (IsOpen)
|
||||||
{
|
{
|
||||||
_window.Close();
|
Close();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_window.OpenCentered();
|
Window!.OpenCentered();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,28 +299,46 @@ public sealed class AdminAHelpUIHandler : IAHelpUIHandler
|
|||||||
public void Open(NetUserId channelId)
|
public void Open(NetUserId channelId)
|
||||||
{
|
{
|
||||||
SelectChannel(channelId);
|
SelectChannel(channelId);
|
||||||
_window?.OpenCentered();
|
Window?.OpenCentered();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EnsureWindow()
|
public void OnRequestClosed(WindowRequestClosedEventArgs args)
|
||||||
{
|
{
|
||||||
if (_window is { Disposed: false })
|
Close();
|
||||||
return;
|
|
||||||
_window = new BwoinkWindow(this);
|
|
||||||
_window.OnClose += () => { OnClose?.Invoke(); };
|
|
||||||
_window.OnOpen += () => { OnOpen?.Invoke(); };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
public BwoinkPanel EnsurePanel(NetUserId channelId)
|
||||||
{
|
{
|
||||||
EnsureWindow();
|
EnsureControl();
|
||||||
|
|
||||||
if (_activePanelMap.TryGetValue(channelId, out var existingPanel))
|
if (_activePanelMap.TryGetValue(channelId, out var existingPanel))
|
||||||
return existingPanel;
|
return existingPanel;
|
||||||
|
|
||||||
_activePanelMap[channelId] = existingPanel = new BwoinkPanel(text => SendMessageAction?.Invoke(channelId, text));
|
_activePanelMap[channelId] = existingPanel = new BwoinkPanel(text => SendMessageAction?.Invoke(channelId, text));
|
||||||
existingPanel.Visible = false;
|
existingPanel.Visible = false;
|
||||||
if (!_window!.BwoinkArea.Children.Contains(existingPanel))
|
if (!Control!.BwoinkArea.Children.Contains(existingPanel))
|
||||||
_window.BwoinkArea.AddChild(existingPanel);
|
Control.BwoinkArea.AddChild(existingPanel);
|
||||||
|
|
||||||
return existingPanel;
|
return existingPanel;
|
||||||
}
|
}
|
||||||
@@ -261,13 +347,14 @@ public sealed class AdminAHelpUIHandler : IAHelpUIHandler
|
|||||||
private void SelectChannel(NetUserId uid)
|
private void SelectChannel(NetUserId uid)
|
||||||
{
|
{
|
||||||
EnsurePanel(uid);
|
EnsurePanel(uid);
|
||||||
_window!.SelectChannel(uid);
|
Control!.SelectChannel(uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_window?.Dispose();
|
Window?.Dispose();
|
||||||
_window = null;
|
Window = null;
|
||||||
|
Control = null;
|
||||||
_activePanelMap.Clear();
|
_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? OnClose;
|
||||||
public event Action? OnOpen;
|
public event Action? OnOpen;
|
||||||
public Action<NetUserId, string>? SendMessageAction { get; set; }
|
public Action<NetUserId, string>? SendMessageAction { get; set; }
|
||||||
|
|||||||
Reference in New Issue
Block a user