Add confirmation to kick and respawn in the admin player actions panel (#20542)
This commit is contained in:
59
Content.Client/Administration/UI/AdminUIHelpers.cs
Normal file
59
Content.Client/Administration/UI/AdminUIHelpers.cs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
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);
|
||||||
@@ -1,22 +1,16 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
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.CustomControls;
|
||||||
using Content.Client.Administration.UI.Tabs.AdminTab;
|
|
||||||
using Content.Client.Stylesheets;
|
|
||||||
using Content.Client.UserInterface.Systems.Bwoink;
|
using Content.Client.UserInterface.Systems.Bwoink;
|
||||||
using Content.Client.UserInterface.Systems.Chat.Controls;
|
|
||||||
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;
|
||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
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.Utility;
|
using Robust.Shared.Utility;
|
||||||
using Timer = Robust.Shared.Timing.Timer;
|
|
||||||
|
|
||||||
namespace Content.Client.Administration.UI.Bwoink
|
namespace Content.Client.Administration.UI.Bwoink
|
||||||
{
|
{
|
||||||
@@ -31,8 +25,8 @@ namespace Content.Client.Administration.UI.Bwoink
|
|||||||
[Dependency] private readonly IUserInterfaceManager _ui = default!;
|
[Dependency] private readonly IUserInterfaceManager _ui = default!;
|
||||||
public AdminAHelpUIHandler AHelpHelper = default!;
|
public AdminAHelpUIHandler AHelpHelper = default!;
|
||||||
|
|
||||||
//private readonly BwoinkSystem _bwoinkSystem;
|
private PlayerInfo? _currentPlayer;
|
||||||
private PlayerInfo? _currentPlayer = default;
|
private readonly Dictionary<Button, ConfirmationData> _confirmations = new();
|
||||||
|
|
||||||
public BwoinkControl()
|
public BwoinkControl()
|
||||||
{
|
{
|
||||||
@@ -131,7 +125,7 @@ namespace Content.Client.Administration.UI.Bwoink
|
|||||||
|
|
||||||
Kick.OnPressed += _ =>
|
Kick.OnPressed += _ =>
|
||||||
{
|
{
|
||||||
if (!TryConfirm(Kick))
|
if (!AdminUIHelpers.TryConfirm(Kick, _confirmations))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -149,7 +143,7 @@ namespace Content.Client.Administration.UI.Bwoink
|
|||||||
|
|
||||||
Respawn.OnPressed += _ =>
|
Respawn.OnPressed += _ =>
|
||||||
{
|
{
|
||||||
if (!TryConfirm(Respawn))
|
if (!AdminUIHelpers.TryConfirm(Respawn, _confirmations))
|
||||||
{
|
{
|
||||||
return;
|
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)
|
public void OnBwoink(NetUserId channel)
|
||||||
{
|
{
|
||||||
ChannelSelector.PopulateList();
|
ChannelSelector.PopulateList();
|
||||||
@@ -246,30 +238,5 @@ namespace Content.Client.Administration.UI.Bwoink
|
|||||||
var panel = AHelpHelper.EnsurePanel(ch);
|
var panel = AHelpHelper.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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ using Robust.Client.AutoGenerated;
|
|||||||
using Robust.Client.Console;
|
using Robust.Client.Console;
|
||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Client.UserInterface.CustomControls;
|
using Robust.Client.UserInterface.CustomControls;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Client.UserInterface.XAML;
|
||||||
using Robust.Shared.Players;
|
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
|
|
||||||
namespace Content.Client.Administration.UI.Tabs.AdminTab
|
namespace Content.Client.Administration.UI.Tabs.AdminTab
|
||||||
@@ -15,9 +14,12 @@ namespace Content.Client.Administration.UI.Tabs.AdminTab
|
|||||||
public sealed partial class PlayerActionsWindow : DefaultWindow
|
public sealed partial class PlayerActionsWindow : DefaultWindow
|
||||||
{
|
{
|
||||||
private PlayerInfo? _selectedPlayer;
|
private PlayerInfo? _selectedPlayer;
|
||||||
|
private readonly Dictionary<Button, ConfirmationData> _confirmations = new();
|
||||||
|
|
||||||
protected override void EnteredTree()
|
public PlayerActionsWindow()
|
||||||
{
|
{
|
||||||
|
RobustXamlLoader.Load(this);
|
||||||
|
|
||||||
SubmitKickButton.OnPressed += SubmitKickButtonOnPressed;
|
SubmitKickButton.OnPressed += SubmitKickButtonOnPressed;
|
||||||
SubmitAHelpButton.OnPressed += SubmitAhelpButtonOnPressed;
|
SubmitAHelpButton.OnPressed += SubmitAhelpButtonOnPressed;
|
||||||
SubmitRespawnButton.OnPressed += SubmitRespawnButtonOnPressed;
|
SubmitRespawnButton.OnPressed += SubmitRespawnButtonOnPressed;
|
||||||
@@ -26,6 +28,9 @@ namespace Content.Client.Administration.UI.Tabs.AdminTab
|
|||||||
|
|
||||||
private void OnListOnOnSelectionChanged(PlayerInfo? obj)
|
private void OnListOnOnSelectionChanged(PlayerInfo? obj)
|
||||||
{
|
{
|
||||||
|
if (_selectedPlayer != obj)
|
||||||
|
AdminUIHelpers.RemoveAllConfirms(_confirmations);
|
||||||
|
|
||||||
_selectedPlayer = obj;
|
_selectedPlayer = obj;
|
||||||
var disableButtons = _selectedPlayer == null;
|
var disableButtons = _selectedPlayer == null;
|
||||||
SubmitKickButton.Disabled = disableButtons;
|
SubmitKickButton.Disabled = disableButtons;
|
||||||
@@ -37,6 +42,10 @@ namespace Content.Client.Administration.UI.Tabs.AdminTab
|
|||||||
{
|
{
|
||||||
if (_selectedPlayer == null)
|
if (_selectedPlayer == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!AdminUIHelpers.TryConfirm(SubmitKickButton, _confirmations))
|
||||||
|
return;
|
||||||
|
|
||||||
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
|
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
|
||||||
$"kick \"{_selectedPlayer.Username}\" \"{CommandParsing.Escape(ReasonLine.Text)}\"");
|
$"kick \"{_selectedPlayer.Username}\" \"{CommandParsing.Escape(ReasonLine.Text)}\"");
|
||||||
}
|
}
|
||||||
@@ -54,6 +63,10 @@ namespace Content.Client.Administration.UI.Tabs.AdminTab
|
|||||||
{
|
{
|
||||||
if (_selectedPlayer == null)
|
if (_selectedPlayer == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!AdminUIHelpers.TryConfirm(SubmitRespawnButton, _confirmations))
|
||||||
|
return;
|
||||||
|
|
||||||
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
|
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
|
||||||
$"respawn \"{_selectedPlayer.Username}\"");
|
$"respawn \"{_selectedPlayer.Username}\"");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user