Fix right click not showing the context menu in AHelps, players tab and objects tab (#22798)

* Fix right clicks in AHelp window

* Fix player tab right click

* Fix objects tab right click
This commit is contained in:
DrSmugleaf
2023-12-20 22:32:52 -08:00
committed by GitHub
parent 5ee01ce900
commit 0273bbcbf3
5 changed files with 47 additions and 36 deletions

View File

@@ -1,10 +1,8 @@
using System.Linq; using System.Linq;
using Content.Client.Administration.Systems; using Content.Client.Administration.Systems;
using Content.Client.UserInterface.Controls; using Content.Client.UserInterface.Controls;
using Content.Client.Verbs;
using Content.Client.Verbs.UI; using Content.Client.Verbs.UI;
using Content.Shared.Administration; using Content.Shared.Administration;
using Content.Shared.Input;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
@@ -39,6 +37,7 @@ namespace Content.Client.Administration.UI.CustomControls
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
// Fill the Option data // Fill the Option data
PlayerListContainer.ItemPressed += PlayerListItemPressed; PlayerListContainer.ItemPressed += PlayerListItemPressed;
PlayerListContainer.ItemKeyBindDown += PlayerListItemKeyBindDown;
PlayerListContainer.GenerateItem += GenerateButton; PlayerListContainer.GenerateItem += GenerateButton;
PopulateList(_adminSystem.PlayerList); PopulateList(_adminSystem.PlayerList);
FilterLineEdit.OnTextChanged += _ => FilterList(); FilterLineEdit.OnTextChanged += _ => FilterList();
@@ -50,18 +49,27 @@ namespace Content.Client.Administration.UI.CustomControls
{ {
if (args == null || data is not PlayerListData {Info: var selectedPlayer}) if (args == null || data is not PlayerListData {Info: var selectedPlayer})
return; return;
if (args.Event.Function == EngineKeyFunctions.UIClick)
{ if (args.Event.Function != EngineKeyFunctions.UIClick)
return;
OnSelectionChanged?.Invoke(selectedPlayer); OnSelectionChanged?.Invoke(selectedPlayer);
// update label text. Only required if there is some override (e.g. unread bwoink count). // update label text. Only required if there is some override (e.g. unread bwoink count).
if (OverrideText != null && args.Button.Children.FirstOrDefault()?.Children?.FirstOrDefault() is Label label) if (OverrideText != null && args.Button.Children.FirstOrDefault()?.Children?.FirstOrDefault() is Label label)
label.Text = GetText(selectedPlayer); label.Text = GetText(selectedPlayer);
} }
else if (args.Event.Function == EngineKeyFunctions.UseSecondary && selectedPlayer.NetEntity != null)
private void PlayerListItemKeyBindDown(GUIBoundKeyEventArgs? args, ListData? data)
{ {
if (args == null || data is not PlayerListData { Info: var selectedPlayer })
return;
if (args.Function != EngineKeyFunctions.UIRightClick || selectedPlayer.NetEntity == null)
return;
_uiManager.GetUIController<VerbMenuUIController>().OpenVerbMenu(selectedPlayer.NetEntity.Value, true); _uiManager.GetUIController<VerbMenuUIController>().OpenVerbMenu(selectedPlayer.NetEntity.Value, true);
} args.Handle();
} }
public void StopFiltering() public void StopFiltering()

View File

@@ -1,7 +1,6 @@
using Content.Client.Station; using Content.Client.Station;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
using Robust.Shared.Map.Components; using Robust.Shared.Map.Components;
@@ -15,7 +14,7 @@ public sealed partial class ObjectsTab : Control
private readonly List<ObjectsTabEntry> _objects = new(); private readonly List<ObjectsTabEntry> _objects = new();
private List<ObjectsTabSelection> _selections = new(); private List<ObjectsTabSelection> _selections = new();
public event Action<BaseButton.ButtonEventArgs>? OnEntryPressed; public event Action<ObjectsTabEntry, GUIBoundKeyEventArgs>? OnEntryKeyBindDown;
public ObjectsTab() public ObjectsTab()
{ {
@@ -82,7 +81,7 @@ public sealed partial class ObjectsTab : Control
var ctrl = new ObjectsTabEntry(name, entity); var ctrl = new ObjectsTabEntry(name, entity);
_objects.Add(ctrl); _objects.Add(ctrl);
ObjectList.AddChild(ctrl); ObjectList.AddChild(ctrl);
ctrl.OnPressed += args => OnEntryPressed?.Invoke(args); ctrl.OnKeyBindDown += args => OnEntryKeyBindDown?.Invoke(ctrl, args);
} }
} }

View File

@@ -28,7 +28,7 @@ namespace Content.Client.Administration.UI.Tabs.PlayerTab
private bool _ascending = true; private bool _ascending = true;
private bool _showDisconnected; private bool _showDisconnected;
public event Action<ButtonEventArgs>? OnEntryPressed; public event Action<PlayerTabEntry, GUIBoundKeyEventArgs>? OnEntryKeyBindDown;
public PlayerTab() public PlayerTab()
{ {
@@ -123,7 +123,7 @@ namespace Content.Client.Administration.UI.Tabs.PlayerTab
player.Connected, player.Connected,
player.PlaytimeString); player.PlaytimeString);
entry.PlayerEntity = player.NetEntity; entry.PlayerEntity = player.NetEntity;
entry.OnPressed += args => OnEntryPressed?.Invoke(args); entry.OnKeyBindDown += args => OnEntryKeyBindDown?.Invoke(entry, args);
entry.ToolTip = Loc.GetString("player-tab-entry-tooltip"); entry.ToolTip = Loc.GetString("player-tab-entry-tooltip");
PlayerList.AddChild(entry); PlayerList.AddChild(entry);

View File

@@ -23,6 +23,7 @@ public sealed class ListContainer : Control
public bool Toggle { get; set; } public bool Toggle { get; set; }
public Action<ListData, ListContainerButton>? GenerateItem; public Action<ListData, ListContainerButton>? GenerateItem;
public Action<BaseButton.ButtonEventArgs?, ListData?>? ItemPressed; public Action<BaseButton.ButtonEventArgs?, ListData?>? ItemPressed;
public Action<GUIBoundKeyEventArgs, ListData?>? ItemKeyBindDown;
public IReadOnlyList<ListData> Data => _data; public IReadOnlyList<ListData> Data => _data;
private const int DefaultSeparation = 3; private const int DefaultSeparation = 3;
@@ -135,6 +136,11 @@ public sealed class ListContainer : Control
ItemPressed?.Invoke(args, button.Data); ItemPressed?.Invoke(args, button.Data);
} }
private void OnItemKeyBindDown(ListContainerButton button, GUIBoundKeyEventArgs args)
{
ItemKeyBindDown?.Invoke(args, button.Data);
}
[Pure] [Pure]
private Vector2 GetScrollValue() private Vector2 GetScrollValue()
{ {
@@ -256,6 +262,7 @@ public sealed class ListContainer : Control
{ {
button = new ListContainerButton(data); button = new ListContainerButton(data);
button.OnPressed += OnItemPressed; button.OnPressed += OnItemPressed;
button.OnKeyBindDown += args => OnItemKeyBindDown(button, args);
button.ToggleMode = Toggle; button.ToggleMode = Toggle;
button.Group = _buttonGroup; button.Group = _buttonGroup;

View File

@@ -13,6 +13,7 @@ using Content.Shared.Input;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.Console; using Robust.Client.Console;
using Robust.Client.Input; using Robust.Client.Input;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers; using Robust.Client.UserInterface.Controllers;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Shared.Input; using Robust.Shared.Input;
@@ -97,8 +98,8 @@ public sealed class AdminUIController : UIController, IOnStateEntered<GameplaySt
if (_panicBunker != null) if (_panicBunker != null)
_window.PanicBunkerControl.UpdateStatus(_panicBunker); _window.PanicBunkerControl.UpdateStatus(_panicBunker);
_window.PlayerTabControl.OnEntryPressed += PlayerTabEntryPressed; _window.PlayerTabControl.OnEntryKeyBindDown += PlayerTabEntryKeyBindDown;
_window.ObjectsTabControl.OnEntryPressed += ObjectsTabEntryPressed; _window.ObjectsTabControl.OnEntryKeyBindDown += ObjectsTabEntryKeyBindDown;
_window.OnOpen += OnWindowOpen; _window.OnOpen += OnWindowOpen;
_window.OnClose += OnWindowClosed; _window.OnClose += OnWindowClosed;
_window.OnDisposed += OnWindowDisposed; _window.OnDisposed += OnWindowDisposed;
@@ -144,8 +145,8 @@ public sealed class AdminUIController : UIController, IOnStateEntered<GameplaySt
if (_window == null) if (_window == null)
return; return;
_window.PlayerTabControl.OnEntryPressed -= PlayerTabEntryPressed; _window.PlayerTabControl.OnEntryKeyBindDown -= PlayerTabEntryKeyBindDown;
_window.ObjectsTabControl.OnEntryPressed -= ObjectsTabEntryPressed; _window.ObjectsTabControl.OnEntryKeyBindDown -= ObjectsTabEntryKeyBindDown;
_window.OnOpen -= OnWindowOpen; _window.OnOpen -= OnWindowOpen;
_window.OnClose -= OnWindowClosed; _window.OnClose -= OnWindowClosed;
_window.OnDisposed -= OnWindowDisposed; _window.OnDisposed -= OnWindowDisposed;
@@ -175,32 +176,28 @@ public sealed class AdminUIController : UIController, IOnStateEntered<GameplaySt
} }
} }
private void PlayerTabEntryPressed(ButtonEventArgs args) private void PlayerTabEntryKeyBindDown(PlayerTabEntry entry, GUIBoundKeyEventArgs args)
{ {
if (args.Button is not PlayerTabEntry button if (entry.PlayerEntity == null)
|| button.PlayerEntity == null)
return; return;
var entity = button.PlayerEntity.Value; var entity = entry.PlayerEntity.Value;
var function = args.Event.Function; var function = args.Function;
if (function == EngineKeyFunctions.UIClick) if (function == EngineKeyFunctions.UIClick)
_conHost.ExecuteCommand($"vv {entity}"); _conHost.ExecuteCommand($"vv {entity}");
else if (function == EngineKeyFunctions.UseSecondary) else if (function == EngineKeyFunctions.UIRightClick)
_verb.OpenVerbMenu(entity, true); _verb.OpenVerbMenu(entity, true);
else else
return; return;
args.Event.Handle(); args.Handle();
} }
private void ObjectsTabEntryPressed(ButtonEventArgs args) private void ObjectsTabEntryKeyBindDown(ObjectsTabEntry entry, GUIBoundKeyEventArgs args)
{ {
if (args.Button is not ObjectsTabEntry button) var uid = entry.AssocEntity;
return; var function = args.Function;
var uid = button.AssocEntity;
var function = args.Event.Function;
if (function == EngineKeyFunctions.UIClick) if (function == EngineKeyFunctions.UIClick)
_conHost.ExecuteCommand($"vv {uid}"); _conHost.ExecuteCommand($"vv {uid}");
@@ -209,6 +206,6 @@ public sealed class AdminUIController : UIController, IOnStateEntered<GameplaySt
else else
return; return;
args.Event.Handle(); args.Handle();
} }
} }