+++ /dev/null
-using System.Threading;
-using Content.Client.Stylesheets;
-using Robust.Client.UserInterface.Controls;
-using Timer = Robust.Shared.Timing.Timer;
-
-namespace Content.Client.Administration.UI;
-
-public static class AdminUIHelpers
-{
- private static void ResetButton(Button button, ConfirmationData data)
- {
- data.Cancellation.Cancel();
- button.ModulateSelfOverride = null;
- button.Text = data.OriginalText;
- }
-
- public static bool RemoveConfirm(Button button, Dictionary<Button, ConfirmationData> confirmations)
- {
- if (confirmations.Remove(button, out var data))
- {
- ResetButton(button, data);
- return true;
- }
-
- return false;
- }
-
- public static void RemoveAllConfirms(Dictionary<Button, ConfirmationData> confirmations)
- {
- foreach (var (button, confirmation) in confirmations)
- {
- ResetButton(button, confirmation);
- }
-
- confirmations.Clear();
- }
-
- public static bool TryConfirm(Button button, Dictionary<Button, ConfirmationData> confirmations)
- {
- if (RemoveConfirm(button, confirmations))
- return true;
-
- var data = new ConfirmationData(new CancellationTokenSource(), button.Text);
- confirmations[button] = data;
-
- Timer.Spawn(TimeSpan.FromSeconds(5), () =>
- {
- confirmations.Remove(button);
- button.ModulateSelfOverride = null;
- button.Text = data.OriginalText;
- }, data.Cancellation.Token);
-
- button.ModulateSelfOverride = StyleNano.ButtonColorCautionDefault;
- button.Text = Loc.GetString("admin-player-actions-confirm");
- return false;
- }
-}
-
-public readonly record struct ConfirmationData(CancellationTokenSource Cancellation, string? OriginalText);
<Control
xmlns="https://spacestation14.io"
- xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls">
+ xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
+ xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls">
<PanelContainer StyleClasses="BackgroundDark">
<SplitContainer Orientation="Vertical" ResizeMode="NotResizable">
<SplitContainer Orientation="Horizontal" VerticalExpand="True">
<Control HorizontalExpand="True" />
<Button Visible="False" Name="Bans" Text="{Loc 'admin-player-actions-bans'}" StyleClasses="OpenRight" />
<Button Visible="False" Name="Notes" Text="{Loc 'admin-player-actions-notes'}" StyleClasses="OpenBoth" />
- <Button Visible="False" Name="Kick" Text="{Loc 'admin-player-actions-kick'}" StyleClasses="OpenBoth" />
+ <controls:ConfirmButton Visible="False" Name="Kick" Text="{Loc 'admin-player-actions-kick'}" ConfirmationText="{Loc 'admin-player-actions-confirm'}" StyleClasses="OpenBoth" />
<Button Visible="False" Name="Ban" Text="{Loc 'admin-player-actions-ban'}" StyleClasses="OpenBoth" />
- <Button Visible="False" Name="Respawn" Text="{Loc 'admin-player-actions-respawn'}" StyleClasses="OpenBoth" />
+ <controls:ConfirmButton Visible="False" Name="Respawn" Text="{Loc 'admin-player-actions-respawn'}" ConfirmationText="{Loc 'admin-player-actions-confirm'}" StyleClasses="OpenBoth" />
<Button Visible="False" Name="Follow" Text="{Loc 'admin-player-actions-follow'}" StyleClasses="OpenLeft" />
</BoxContainer>
</SplitContainer>
public AdminAHelpUIHandler AHelpHelper = default!;
private PlayerInfo? _currentPlayer;
- private readonly Dictionary<Button, ConfirmationData> _confirmations = new();
public BwoinkControl()
{
Kick.OnPressed += _ =>
{
- if (!AdminUIHelpers.TryConfirm(Kick, _confirmations))
- {
- return;
- }
-
// TODO: Reason field
if (_currentPlayer is not null)
_console.ExecuteCommand($"kick \"{_currentPlayer.Username}\"");
Respawn.OnPressed += _ =>
{
- if (!AdminUIHelpers.TryConfirm(Respawn, _confirmations))
- {
- return;
- }
-
if (_currentPlayer is not null)
_console.ExecuteCommand($"respawn \"{_currentPlayer.Username}\"");
};
<Popup xmlns="https://spacestation14.io"
- xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client">
+ xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
+ xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls">
<PanelContainer>
<PanelContainer.PanelOverride>
<gfx:StyleBoxFlat BorderThickness="2" BorderColor="#18181B" BackgroundColor="#25252a"/>
<BoxContainer Orientation="Horizontal">
<Button Name="EditButton" Text="{Loc admin-notes-edit}"/>
<Control HorizontalExpand="True"/>
- <Button Name="DeleteButton" Text="{Loc admin-notes-delete}" HorizontalAlignment="Right"/>
+ <controls:ConfirmButton Name="DeleteButton" Text="{Loc admin-notes-delete}" ConfirmationText="{Loc 'admin-player-actions-confirm'}" HorizontalAlignment="Right"/>
</BoxContainer>
</BoxContainer>
</PanelContainer>
<DefaultWindow
xmlns="https://spacestation14.io"
xmlns:cc="clr-namespace:Content.Client.Administration.UI.CustomControls"
+ xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc admin-player-actions-window-title}" MinSize="425 272">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Horizontal">
</BoxContainer>
<cc:PlayerListControl Name="PlayerList" VerticalExpand="True" />
<BoxContainer Orientation="Horizontal">
- <Button Name="SubmitKickButton" Text="{Loc admin-player-actions-kick}" Disabled="True"/>
+ <controls:ConfirmButton Name="SubmitKickButton" Text="{Loc admin-player-actions-kick}" ConfirmationText="{Loc 'admin-player-actions-confirm'}" Disabled="True"/>
<Button Name="SubmitAHelpButton" Text="{Loc admin-player-actions-ahelp}" Disabled="True"/>
- <Button Name="SubmitRespawnButton" Text="{Loc admin-player-actions-respawn}" Disabled="True"/>
+ <controls:ConfirmButton Name="SubmitRespawnButton" Text="{Loc admin-player-actions-respawn}" ConfirmationText="{Loc 'admin-player-actions-confirm'}" Disabled="True"/>
</BoxContainer>
</BoxContainer>
</DefaultWindow>
public sealed partial class PlayerActionsWindow : DefaultWindow
{
private PlayerInfo? _selectedPlayer;
- private readonly Dictionary<Button, ConfirmationData> _confirmations = new();
public PlayerActionsWindow()
{
private void OnListOnOnSelectionChanged(PlayerInfo? obj)
{
- if (_selectedPlayer != obj)
- AdminUIHelpers.RemoveAllConfirms(_confirmations);
-
_selectedPlayer = obj;
var disableButtons = _selectedPlayer == null;
SubmitKickButton.Disabled = disableButtons;
if (_selectedPlayer == null)
return;
- if (!AdminUIHelpers.TryConfirm(SubmitKickButton, _confirmations))
- return;
-
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
$"kick \"{_selectedPlayer.Username}\" \"{CommandParsing.Escape(ReasonLine.Text)}\"");
}
if (_selectedPlayer == null)
return;
- if (!AdminUIHelpers.TryConfirm(SubmitRespawnButton, _confirmations))
- return;
-
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
$"respawn \"{_selectedPlayer.Username}\"");
}
public Action<NetEntity>? OnTeleport;
public Action<NetEntity>? OnDelete;
- private readonly Dictionary<Button, ConfirmationData> _confirmations = new();
public ObjectsTabEntry(IClientAdminManager manager, string name, NetEntity nent, StyleBox styleBox)
{
DeleteButton.Disabled = !manager.CanCommand("delete");
TeleportButton.OnPressed += _ => OnTeleport?.Invoke(nent);
- DeleteButton.OnPressed += _ =>
- {
- if (!AdminUIHelpers.TryConfirm(DeleteButton, _confirmations))
- {
- return;
- }
- OnDelete?.Invoke(nent);
- };
+ DeleteButton.OnPressed += _ => OnDelete?.Invoke(nent);
}
}