Add confirmation to AHelp kick and respawn buttons (#7260)
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
#nullable enable
|
||||
using System.Text;
|
||||
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.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.IoC;
|
||||
using Timer = Robust.Shared.Timing.Timer;
|
||||
|
||||
namespace Content.Client.Administration.UI
|
||||
{
|
||||
@@ -33,7 +35,7 @@ namespace Content.Client.Administration.UI
|
||||
IoCManager.InjectDependencies(this);
|
||||
_bwoinkSystem = bs;
|
||||
|
||||
_adminManager.AdminStatusUpdated += () => FixButtons();
|
||||
_adminManager.AdminStatusUpdated += FixButtons;
|
||||
FixButtons();
|
||||
|
||||
ChannelSelector.OnSelectionChanged += sel =>
|
||||
@@ -80,6 +82,11 @@ namespace Content.Client.Administration.UI
|
||||
|
||||
Kick.OnPressed += _ =>
|
||||
{
|
||||
if (!TryConfirm(Kick))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Reason field
|
||||
if (_currentPlayer is not null)
|
||||
_console.ExecuteCommand($"kick \"{_currentPlayer.Username}\"");
|
||||
@@ -93,11 +100,18 @@ namespace Content.Client.Administration.UI
|
||||
|
||||
Respawn.OnPressed += _ =>
|
||||
{
|
||||
if (!TryConfirm(Respawn))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_currentPlayer is not null)
|
||||
_console.ExecuteCommand($"respawn \"{_currentPlayer.Username}\"");
|
||||
};
|
||||
}
|
||||
|
||||
private Dictionary<Control, (CancellationTokenSource cancellation, string? originalText)> Confirmations { get; } = new();
|
||||
|
||||
public void OnBwoink(NetUserId channel)
|
||||
{
|
||||
var open = IsOpen;
|
||||
@@ -169,5 +183,30 @@ namespace Content.Client.Administration.UI
|
||||
var panel = _bwoinkSystem.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