Make the admin player panel overlay button a toggle (#7153)

This commit is contained in:
DrSmugleaf
2022-03-24 17:08:08 +01:00
committed by GitHub
parent 3be7621656
commit 3c15de5f55
4 changed files with 52 additions and 17 deletions

View File

@@ -1,7 +1,5 @@
using Content.Client.Administration.Managers;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.IoC;
namespace Content.Client.Administration
{
@@ -9,8 +7,12 @@ namespace Content.Client.Administration
{
[Dependency] private readonly IClientAdminManager _adminManager = default!;
[Dependency] private readonly IEyeManager _eyeManager = default!;
private AdminNameOverlay _adminNameOverlay = default!;
public event Action? OverlayEnabled;
public event Action? OverlayDisabled;
private void InitializeOverlay()
{
_adminNameOverlay = new AdminNameOverlay(this, _entityManager, _eyeManager, _resourceCache, _entityLookup);
@@ -27,15 +29,17 @@ namespace Content.Client.Administration
AdminOverlayOff();
}
public void AdminOverlayOn(BaseButton.ButtonEventArgs? _ = null)
public void AdminOverlayOn()
{
if (!_overlayManager.HasOverlay<AdminNameOverlay>())
_overlayManager.AddOverlay(_adminNameOverlay);
if (_overlayManager.HasOverlay<AdminNameOverlay>()) return;
_overlayManager.AddOverlay(_adminNameOverlay);
OverlayEnabled?.Invoke();
}
public void AdminOverlayOff(BaseButton.ButtonEventArgs? _ = null)
public void AdminOverlayOff()
{
_overlayManager.RemoveOverlay<AdminNameOverlay>();
OverlayDisabled?.Invoke();
}
}
}

View File

@@ -5,10 +5,8 @@
<BoxContainer Orientation="Horizontal">
<Label Name="PlayerCount" HorizontalExpand="True" SizeFlagsStretchRatio="0.50"
Text="{Loc Player Count}" />
<Button Name="OverlayButtonOn" HorizontalExpand="True" SizeFlagsStretchRatio="0.25"
Text="{Loc Overlay On}"/>
<Button Name="OverlayButtonOff" HorizontalExpand="True" SizeFlagsStretchRatio="0.25"
Text="{Loc Overlay Off}"/>
<Button Name="OverlayButton" HorizontalExpand="True" SizeFlagsStretchRatio="0.25"
Text="{Loc player-tab-overlay}" ToggleMode="True"/>
</BoxContainer>
<Control MinSize="0 5" />
<ScrollContainer HorizontalExpand="True" VerticalExpand="True">

View File

@@ -3,9 +3,9 @@ using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using static Content.Client.Administration.UI.Tabs.PlayerTab.PlayerTabHeader;
using static Robust.Client.UserInterface.Controls.BaseButton;
namespace Content.Client.Administration.UI.Tabs.PlayerTab
{
@@ -22,28 +22,60 @@ namespace Content.Client.Administration.UI.Tabs.PlayerTab
private Header _headerClicked = Header.Username;
private bool _ascending = true;
public event Action<BaseButton.ButtonEventArgs>? OnEntryPressed;
public event Action<ButtonEventArgs>? OnEntryPressed;
public PlayerTab()
{
_adminSystem = EntitySystem.Get<AdminSystem>();
RobustXamlLoader.Load(this);
RefreshPlayerList(_adminSystem.PlayerList);
_adminSystem.PlayerListChanged += RefreshPlayerList;
OverlayButtonOn.OnPressed += _adminSystem.AdminOverlayOn;
OverlayButtonOff.OnPressed += _adminSystem.AdminOverlayOff;
_adminSystem.OverlayEnabled += OverlayEnabled;
_adminSystem.OverlayDisabled += OverlayDisabled;
OverlayButton.OnPressed += OverlayButtonPressed;
ListHeader.BackgroundColorPanel.PanelOverride = new StyleBoxFlat(_altColor);
ListHeader.OnHeaderClicked += HeaderClicked;
}
private void OverlayEnabled()
{
OverlayButton.Pressed = true;
}
private void OverlayDisabled()
{
OverlayButton.Pressed = false;
}
private void OverlayButtonPressed(ButtonEventArgs args)
{
if (args.Button.Pressed)
{
_adminSystem.AdminOverlayOn();
}
else
{
_adminSystem.AdminOverlayOff();
}
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_adminSystem.PlayerListChanged -= RefreshPlayerList;
OverlayButtonOn.OnPressed -= _adminSystem.AdminOverlayOn;
OverlayButtonOff.OnPressed -= _adminSystem.AdminOverlayOff;
if (disposing)
{
_adminSystem.PlayerListChanged -= RefreshPlayerList;
_adminSystem.OverlayEnabled -= OverlayEnabled;
_adminSystem.OverlayDisabled -= OverlayDisabled;
OverlayButton.OnPressed -= OverlayButtonPressed;
ListHeader.OnHeaderClicked -= HeaderClicked;
}
}
private void RefreshPlayerList(IReadOnlyList<PlayerInfo> players)

View File

@@ -2,3 +2,4 @@
player-tab-character = Character
player-tab-job = Job
player-tab-antagonist = Antagonist
player-tab-overlay = Overlay