Add confirmation to kick and respawn in the admin player actions panel (#20542)
This commit is contained in:
@@ -1,22 +1,16 @@
|
||||
using System.Linq;
|
||||
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.Client.UserInterface.Systems.Chat.Controls;
|
||||
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
|
||||
{
|
||||
@@ -31,8 +25,8 @@ namespace Content.Client.Administration.UI.Bwoink
|
||||
[Dependency] private readonly IUserInterfaceManager _ui = default!;
|
||||
public AdminAHelpUIHandler AHelpHelper = default!;
|
||||
|
||||
//private readonly BwoinkSystem _bwoinkSystem;
|
||||
private PlayerInfo? _currentPlayer = default;
|
||||
private PlayerInfo? _currentPlayer;
|
||||
private readonly Dictionary<Button, ConfirmationData> _confirmations = new();
|
||||
|
||||
public BwoinkControl()
|
||||
{
|
||||
@@ -131,7 +125,7 @@ namespace Content.Client.Administration.UI.Bwoink
|
||||
|
||||
Kick.OnPressed += _ =>
|
||||
{
|
||||
if (!TryConfirm(Kick))
|
||||
if (!AdminUIHelpers.TryConfirm(Kick, _confirmations))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -149,7 +143,7 @@ namespace Content.Client.Administration.UI.Bwoink
|
||||
|
||||
Respawn.OnPressed += _ =>
|
||||
{
|
||||
if (!TryConfirm(Respawn))
|
||||
if (!AdminUIHelpers.TryConfirm(Respawn, _confirmations))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -164,8 +158,6 @@ namespace Content.Client.Administration.UI.Bwoink
|
||||
};
|
||||
}
|
||||
|
||||
private Dictionary<Control, (CancellationTokenSource cancellation, string? originalText)> Confirmations { get; } = new();
|
||||
|
||||
public void OnBwoink(NetUserId channel)
|
||||
{
|
||||
ChannelSelector.PopulateList();
|
||||
@@ -246,30 +238,5 @@ namespace Content.Client.Administration.UI.Bwoink
|
||||
var panel = AHelpHelper.EnsurePanel(ch);
|
||||
panel.Visible = true;
|
||||
}
|
||||
|
||||
private bool TryConfirm(Button button)
|
||||
{
|
||||
if (Confirmations.Remove(button, out var tuple))
|
||||
{
|
||||
tuple.cancellation.Cancel();
|
||||
button.ModulateSelfOverride = null;
|
||||
button.Text = tuple.originalText;
|
||||
return true;
|
||||
}
|
||||
|
||||
tuple = (new CancellationTokenSource(), button.Text);
|
||||
Confirmations[button] = tuple;
|
||||
|
||||
Timer.Spawn(TimeSpan.FromSeconds(5), () =>
|
||||
{
|
||||
Confirmations.Remove(button);
|
||||
button.ModulateSelfOverride = null;
|
||||
button.Text = tuple.originalText;
|
||||
}, tuple.cancellation.Token);
|
||||
|
||||
button.ModulateSelfOverride = StyleNano.ButtonColorCautionDefault;
|
||||
button.Text = Loc.GetString("admin-player-actions-confirm");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user