Add confirmation to AHelp kick and respawn buttons (#7260)
This commit is contained in:
@@ -1,17 +1,19 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
using System.Text;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using Content.Client.Administration.Managers;
|
using Content.Client.Administration.Managers;
|
||||||
using Content.Client.Administration.UI.CustomControls;
|
|
||||||
using Content.Client.Administration.UI.Tabs.AdminTab;
|
using Content.Client.Administration.UI.Tabs.AdminTab;
|
||||||
|
using Content.Client.Stylesheets;
|
||||||
using Content.Shared.Administration;
|
using Content.Shared.Administration;
|
||||||
using Robust.Client.AutoGenerated;
|
using Robust.Client.AutoGenerated;
|
||||||
using Robust.Client.Console;
|
using Robust.Client.Console;
|
||||||
|
using Robust.Client.UserInterface;
|
||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Client.UserInterface.CustomControls;
|
using Robust.Client.UserInterface.CustomControls;
|
||||||
using Robust.Client.UserInterface.XAML;
|
using Robust.Client.UserInterface.XAML;
|
||||||
using Robust.Shared.Network;
|
using Robust.Shared.Network;
|
||||||
using Robust.Shared.IoC;
|
using Timer = Robust.Shared.Timing.Timer;
|
||||||
|
|
||||||
namespace Content.Client.Administration.UI
|
namespace Content.Client.Administration.UI
|
||||||
{
|
{
|
||||||
@@ -33,7 +35,7 @@ namespace Content.Client.Administration.UI
|
|||||||
IoCManager.InjectDependencies(this);
|
IoCManager.InjectDependencies(this);
|
||||||
_bwoinkSystem = bs;
|
_bwoinkSystem = bs;
|
||||||
|
|
||||||
_adminManager.AdminStatusUpdated += () => FixButtons();
|
_adminManager.AdminStatusUpdated += FixButtons;
|
||||||
FixButtons();
|
FixButtons();
|
||||||
|
|
||||||
ChannelSelector.OnSelectionChanged += sel =>
|
ChannelSelector.OnSelectionChanged += sel =>
|
||||||
@@ -80,6 +82,11 @@ namespace Content.Client.Administration.UI
|
|||||||
|
|
||||||
Kick.OnPressed += _ =>
|
Kick.OnPressed += _ =>
|
||||||
{
|
{
|
||||||
|
if (!TryConfirm(Kick))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Reason field
|
// TODO: Reason field
|
||||||
if (_currentPlayer is not null)
|
if (_currentPlayer is not null)
|
||||||
_console.ExecuteCommand($"kick \"{_currentPlayer.Username}\"");
|
_console.ExecuteCommand($"kick \"{_currentPlayer.Username}\"");
|
||||||
@@ -93,11 +100,18 @@ namespace Content.Client.Administration.UI
|
|||||||
|
|
||||||
Respawn.OnPressed += _ =>
|
Respawn.OnPressed += _ =>
|
||||||
{
|
{
|
||||||
|
if (!TryConfirm(Respawn))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (_currentPlayer is not null)
|
if (_currentPlayer is not null)
|
||||||
_console.ExecuteCommand($"respawn \"{_currentPlayer.Username}\"");
|
_console.ExecuteCommand($"respawn \"{_currentPlayer.Username}\"");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Dictionary<Control, (CancellationTokenSource cancellation, string? originalText)> Confirmations { get; } = new();
|
||||||
|
|
||||||
public void OnBwoink(NetUserId channel)
|
public void OnBwoink(NetUserId channel)
|
||||||
{
|
{
|
||||||
var open = IsOpen;
|
var open = IsOpen;
|
||||||
@@ -169,5 +183,30 @@ namespace Content.Client.Administration.UI
|
|||||||
var panel = _bwoinkSystem.EnsurePanel(ch);
|
var panel = _bwoinkSystem.EnsurePanel(ch);
|
||||||
panel.Visible = true;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,3 +3,4 @@ admin-player-actions-ban = Ban
|
|||||||
admin-player-actions-ahelp = AHelp
|
admin-player-actions-ahelp = AHelp
|
||||||
admin-player-actions-respawn = Respawn
|
admin-player-actions-respawn = Respawn
|
||||||
admin-player-actions-teleport = Teleport To
|
admin-player-actions-teleport = Teleport To
|
||||||
|
admin-player-actions-confirm = Are you sure?
|
||||||
|
|||||||
Reference in New Issue
Block a user