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 Content.Client.Administration.Systems;
using Content.Client.UserInterface.Controls;
using Content.Client.Verbs;
using Content.Client.Verbs.UI;
using Content.Shared.Administration;
using Content.Shared.Input;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
@@ -39,6 +37,7 @@ namespace Content.Client.Administration.UI.CustomControls
RobustXamlLoader.Load(this);
// Fill the Option data
PlayerListContainer.ItemPressed += PlayerListItemPressed;
PlayerListContainer.ItemKeyBindDown += PlayerListItemKeyBindDown;
PlayerListContainer.GenerateItem += GenerateButton;
PopulateList(_adminSystem.PlayerList);
FilterLineEdit.OnTextChanged += _ => FilterList();
@@ -50,18 +49,27 @@ namespace Content.Client.Administration.UI.CustomControls
{
if (args == null || data is not PlayerListData {Info: var selectedPlayer})
return;
if (args.Event.Function == EngineKeyFunctions.UIClick)
{
OnSelectionChanged?.Invoke(selectedPlayer);
// 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)
label.Text = GetText(selectedPlayer);
}
else if (args.Event.Function == EngineKeyFunctions.UseSecondary && selectedPlayer.NetEntity != null)
{
_uiManager.GetUIController<VerbMenuUIController>().OpenVerbMenu(selectedPlayer.NetEntity.Value, true);
}
if (args.Event.Function != EngineKeyFunctions.UIClick)
return;
OnSelectionChanged?.Invoke(selectedPlayer);
// 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)
label.Text = GetText(selectedPlayer);
}
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);
args.Handle();
}
public void StopFiltering()

View File

@@ -1,7 +1,6 @@
using Content.Client.Station;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Map.Components;
@@ -15,7 +14,7 @@ public sealed partial class ObjectsTab : Control
private readonly List<ObjectsTabEntry> _objects = new();
private List<ObjectsTabSelection> _selections = new();
public event Action<BaseButton.ButtonEventArgs>? OnEntryPressed;
public event Action<ObjectsTabEntry, GUIBoundKeyEventArgs>? OnEntryKeyBindDown;
public ObjectsTab()
{
@@ -82,7 +81,7 @@ public sealed partial class ObjectsTab : Control
var ctrl = new ObjectsTabEntry(name, entity);
_objects.Add(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 _showDisconnected;
public event Action<ButtonEventArgs>? OnEntryPressed;
public event Action<PlayerTabEntry, GUIBoundKeyEventArgs>? OnEntryKeyBindDown;
public PlayerTab()
{
@@ -123,7 +123,7 @@ namespace Content.Client.Administration.UI.Tabs.PlayerTab
player.Connected,
player.PlaytimeString);
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");
PlayerList.AddChild(entry);

View File

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

View File

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