ECS verbs and update context menu (#4594)

* Functioning ECS verbs

Currently only ID card console works.

* Changed verb types and allow ID card insertions

* Verb GUI sorting and verb networking

* More networking, and shared components

* Clientside verbs work now.

* Verb enums changed to bitmask flags

* Verb Categories redo

* Fix range check

* GasTank Verb

* Remove unnecessary bodypart verb

* Buckle Verb

* buckle & unbuckle verbs

* Updated range checks

* Item cabinet verbs

* Add range user override

* construction verb

* Chemistry machine verbs

* Climb Verb

* Generalise pulled entity verbs

* ViewVariables Verb

* rejuvenate, delete, sentient, control verbs

* Outfit verb

* inrangeunoccluded and tubedirection verbs

* attach-to verbs

* remove unused verbs and move VV

* Rename DebugVerbSystem

* Ghost role and pointing verbs

* Remove global verbs

* Allow verbs to raise events

* Changing categories and simplifying debug verbs

* Add rotate and flip verbs

* fix rejuvenate test

* redo context menu

* new Add Gas debug verb

* Add Set Temperature debug verb

* Uncuff verb

* Disposal unit verbs

* Add pickup verb

* lock/unlock verb

* Remove verb type, add specific verb events

* rename verb messages -> events

* Context menu displays verbs by interaction type

* Updated context menu HandleMove

previously, checked if entities moved 1 tile from click location.

Now checks if entities moved out of view.

Now you can actually right-click interact with yourself while walking!

* Misc Verb menu GUI changes

* Fix non-human/ghost verbs

* Update types and categories

* Allow non-ghost/human to open context menu

* configuration verb

* tagger verb

* Morgue Verbs

* Medical Scanner Verbs

* Fix solution refactor merge issues

* Fix context menu in-view check

* Remove prepare GUI

* Redo verb restrictions

* Fix context menu UI

* Disposal Verbs

* Spill verb

* Light verb

* Hand Held light verb

* power cell verbs

* storage verbs

and adding names to insert/eject

* Pulling verb

* Close context menu on verb execution

* Strip verb

* AmmoBox verb

* fix pull verb

* gun barrel verbs

revolver verb
energy weapon verbs
Bolt action verb

* Magazine gun barrel  verbs

* Add charger verbs

* PDA verbs

* Transfer amount verb

* Add reagent verb

* make alt-click use ECS verbs

* Delete old verb files

* Magboot verb

* finalising tweaks

* context menu visibility changes

* code cleanup

* Update AdminAddReagentUI.cs

* Remove HasFlag

* Consistent verb keys

* Remove Linq, add comment

* Fix in-inventory check

* Update GUI text alignment and padding

* Added close-menu option

* Changed some "interaction" verbs to "activation"

* Remove verb keys, use sorted sets

* fix master merge

* update some verb text

* Undo Changes

Remove some new verbs that can be added later

undid some .ftl bugfixes, can and should be done separately

* fix merge

* Undo file rename

* fix merge

* Misc Cleanup

* remove contraction

* Fix keybinding issue

* fix comment

* merge fix

* fix merge

* fix merge

* fix merge

* fix merge

* fix open-close verbs

* adjust uncuff verb

* fix merge

and undo the renaming of SharedPullableComponent to PullableComponent. I'm tired of all of those merge conflicts
This commit is contained in:
Leon Friedrich
2021-10-05 14:29:03 +11:00
committed by GitHub
parent 1095c8fc08
commit 6cb58e608b
175 changed files with 3391 additions and 4305 deletions

View File

@@ -0,0 +1,40 @@
using Content.Client.Administration.UI.Tabs.AtmosTab;
using Content.Shared.Verbs;
using Robust.Client.Console;
using Robust.Client.ViewVariables;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
namespace Content.Client.Verbs
{
/// <summary>
/// Client-side admin verb system. These usually open some sort of UIs.
/// </summary>
class AdminVerbSystem : EntitySystem
{
[Dependency] private readonly IClientConGroupController _clientConGroupController = default!;
[Dependency] private readonly IViewVariablesManager _viewVariablesManager = default!;
public override void Initialize()
{
SubscribeLocalEvent<GetOtherVerbsEvent>(AddAdminVerbs);
}
private void AddAdminVerbs(GetOtherVerbsEvent args)
{
// Currently this is only the ViewVariables verb, but more admin-UI related verbs can be added here.
// View variables verbs
if (_clientConGroupController.CanViewVar())
{
Verb verb = new();
verb.Category = VerbCategory.Debug;
verb.Text = "View Variables";
verb.IconTexture = "/Textures/Interface/VerbIcons/vv.svg.192dpi.png";
verb.Act = () => _viewVariablesManager.OpenVV(args.Target);
args.Verbs.Add(verb);
}
}
}
}

View File

@@ -101,7 +101,6 @@ namespace Content.Client.ContextMenu.UI
public sealed class StackContextElement : ContextMenuElement
{
public event Action? OnExitedTree;
public readonly TimeSpan HoverDelay = TimeSpan.FromSeconds(0.2);
public HashSet<IEntity> ContextEntities { get; }
public readonly StackContextElement? Pre;
@@ -176,40 +175,44 @@ namespace Content.Client.ContextMenu.UI
}
}
public sealed class ContextMenuPopup : Robust.Client.UserInterface.Controls.Popup
public class ContextMenuPopup : Popup
{
private static readonly Color DefaultColor = Color.FromHex("#1116");
private static readonly Color MarginColor = Color.FromHex("#222E");
private const int MaxItemsBeforeScroll = 10;
private const int MarginSizeBetweenElements = 2;
public static readonly Color ButtonColor = Color.FromHex("#1119");
public static readonly Color BackgroundColor = Color.FromHex("#333E");
public const int MaxItemsBeforeScroll = 10;
public const int MarginSize = 2;
public const int ButtonHeight = 32;
public BoxContainer List { get; }
public ScrollContainer Scroll { get; }
public int Depth { get; }
public ContextMenuPopup(int depth = 0)
{
MaxHeight = MaxItemsBeforeScroll * (ButtonHeight + 2*MarginSize);
Depth = depth;
AddChild(new ScrollContainer
List = new() { Orientation = LayoutOrientation.Vertical };
Scroll = new()
{
HScrollEnabled = false,
Children = { new PanelContainer
{
Children = { (List = new BoxContainer
{
Orientation = LayoutOrientation.Vertical
}) },
PanelOverride = new StyleBoxFlat { BackgroundColor = MarginColor }
}}
Children = { List }
};
AddChild(new PanelContainer
{
Children = { Scroll },
PanelOverride = new StyleBoxFlat { BackgroundColor = BackgroundColor }
});
}
public void AddToMenu(ContextMenuElement element)
public void AddToMenu(Control element)
{
List.AddChild(new PanelContainer
{
Children = { element },
Margin = new Thickness(0,0,0, MarginSizeBetweenElements),
PanelOverride = new StyleBoxFlat {BackgroundColor = DefaultColor}
Margin = new Thickness(MarginSize, MarginSize, MarginSize, MarginSize),
PanelOverride = new StyleBoxFlat { BackgroundColor = ButtonColor }
});
}
@@ -229,15 +232,18 @@ namespace Content.Client.ContextMenu.UI
return Vector2.Zero;
}
List.Measure(availableSize);
var listSize = List.DesiredSize;
Scroll.Measure(availableSize);
var size = List.DesiredSize;
if (List.ChildCount < MaxItemsBeforeScroll)
// account for scroll bar width
if (size.Y > MaxHeight)
{
return listSize;
// Scroll._vScrollBar is private and ScrollContainer gives no size information :/
// 10 = Scroll._vScrollBar.DesiredSize
size.X += 10;
}
listSize.Y = MaxItemsBeforeScroll * 32 + MaxItemsBeforeScroll * MarginSizeBetweenElements;
return listSize;
return size;
}
}
}

View File

@@ -6,10 +6,9 @@ using Content.Client.Interactable;
using Content.Client.Items.Managers;
using Content.Client.Verbs;
using Content.Client.Viewport;
using Content.Shared;
using Content.Shared.CCVar;
using Content.Shared.Input;
using Content.Shared.Verbs;
using Content.Shared.Interaction.Helpers;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Input;
@@ -40,21 +39,19 @@ namespace Content.Client.ContextMenu.UI
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IEyeManager _eyeManager = default!;
public static readonly TimeSpan HoverDelay = TimeSpan.FromSeconds(0.2);
private CancellationTokenSource? _cancelHover;
private readonly IContextMenuView _contextMenuView;
private readonly VerbSystem _verbSystem;
private bool _playerCanSeeThroughContainers;
private MapCoordinates _mapCoordinates;
private CancellationTokenSource? _cancellationTokenSource;
public ContextMenuPresenter(VerbSystem verbSystem)
{
IoCManager.InjectDependencies(this);
_verbSystem = verbSystem;
_verbSystem.ToggleContextMenu += SystemOnToggleContextMenu;
_verbSystem.ToggleContainerVisibility += SystemOnToggleContainerVisibility;
_contextMenuView = new ContextMenuView();
_contextMenuView.OnKeyBindDownSingle += OnKeyBindDownSingle;
@@ -70,6 +67,10 @@ namespace Content.Client.ContextMenu.UI
_contextMenuView.OnCloseChildMenu += OnCloseChildMenu;
_cfg.OnValueChanged(CCVars.ContextMenuGroupingType, _contextMenuView.OnGroupingContextMenuChanged, true);
CommandBinds.Builder
.Bind(ContentKeyFunctions.OpenContextMenu, new PointerInputCmdHandler(HandleOpenContextMenu))
.Register<ContextMenuPresenter>();
}
#region View Events
@@ -92,13 +93,11 @@ namespace Content.Client.ContextMenu.UI
{
var realGlobalPosition = e.GlobalPosition;
_cancellationTokenSource?.Cancel();
_cancellationTokenSource = new();
_cancelHover?.Cancel();
_cancelHover = new();
Timer.Spawn(e.HoverDelay, () =>
Timer.Spawn(HoverDelay, () =>
{
_verbSystem.CloseGroupMenu();
if (_contextMenuView.Menus.Count == 0)
{
return;
@@ -111,7 +110,7 @@ namespace Content.Client.ContextMenu.UI
{
_contextMenuView.AddChildMenu(filteredEntities, realGlobalPosition, e);
}
}, _cancellationTokenSource.Token);
}, _cancelHover.Token);
}
private void OnKeyBindDownStack(object? sender, (GUIBoundKeyEventArgs, StackContextElement) e)
@@ -169,10 +168,23 @@ namespace Content.Client.ContextMenu.UI
private void OnMouseEnteredSingle(object? sender, SingleContextElement e)
{
_cancellationTokenSource?.Cancel();
// close other pop-ups after a short delay
_cancelHover?.Cancel();
_cancelHover = new();
Timer.Spawn(HoverDelay, () =>
{
if (_contextMenuView.Menus.Count == 0)
{
return;
}
OnCloseChildMenu(sender, e.ParentMenu?.Depth ?? 0);
}, _cancelHover.Token);
var entity = e.ContextEntity;
_verbSystem.CloseGroupMenu();
OnCloseChildMenu(sender, e.ParentMenu?.Depth ?? 0);
@@ -251,91 +263,114 @@ namespace Content.Client.ContextMenu.UI
#endregion
#region Model Updates
private void SystemOnToggleContainerVisibility(object? sender, bool args)
private bool HandleOpenContextMenu(in PointerInputCmdHandler.PointerInputCmdArgs args)
{
_playerCanSeeThroughContainers = args;
}
private void SystemOnToggleContextMenu(object? sender, PointerInputCmdHandler.PointerInputCmdArgs args)
{
if (_stateManager.CurrentState is not GameScreenBase)
if (args.State != BoundKeyState.Down)
{
return;
return false;
}
var playerEntity = _playerManager.LocalPlayer?.ControlledEntity;
if (playerEntity == null)
if (_stateManager.CurrentState is not GameScreenBase)
{
return;
return false;
}
var player = _playerManager.LocalPlayer?.ControlledEntity;
if (player == null)
{
return false;
}
_mapCoordinates = args.Coordinates.ToMap(_entityManager);
if (!_verbSystem.TryGetContextEntities(playerEntity, _mapCoordinates, out var entities))
{
return;
}
entities = entities.Where(CanSeeOnContextMenu).ToList();
if (entities.Count > 0)
if (!_verbSystem.TryGetContextEntities(player, _mapCoordinates, out var entities, ignoreVisibility: _verbSystem.CanSeeAllContext))
return false;
// do we need to do visiblity checks?
if (_verbSystem.CanSeeAllContext)
{
_contextMenuView.AddRootMenu(entities);
return true;
}
}
public void HandleMoveEvent(ref MoveEvent ev)
{
if (_contextMenuView.Elements.Count == 0) return;
var entity = ev.Sender;
if (_contextMenuView.Elements.ContainsKey(entity))
//visibility checks
player.TryGetContainer(out var playerContainer);
foreach (var entity in entities.ToList())
{
if (!entity.Transform.MapPosition.InRange(_mapCoordinates, 1.0f))
if (!entity.TryGetComponent(out ISpriteComponent? spriteComponent) ||
!spriteComponent.Visible ||
!CanSeeContainerCheck(entity, playerContainer))
{
_contextMenuView.RemoveEntity(entity);
entities.Remove(entity);
}
}
if (entities.Count == 0)
return false;
_contextMenuView.AddRootMenu(entities);
return true;
}
/// <summary>
/// Can the player see the entity through any entity containers?
/// </summary>
/// <remarks>
/// This is similar to <see cref="ContainerHelpers.IsInSameOrParentContainer()"/>, except that we do not
/// allow the player to be the "parent" container and we allow for see-through containers (display cases).
/// </remarks>
private bool CanSeeContainerCheck(IEntity entity, IContainer? playerContainer)
{
// is the player inside this entity?
if (playerContainer?.Owner == entity)
return true;
entity.TryGetContainer(out var entityContainer);
// are they in the same container (or none?)
if (playerContainer == entityContainer)
return true;
// Is the entity in a display case?
if (playerContainer == null && entityContainer!.ShowContents)
return true;
return false;
}
/// <summary>
/// Check that entities in the context menu are still visible. If not, remove them from the context menu.
/// </summary>
public void Update()
{
if (_contextMenuView.Elements.Count == 0) return;
if (_contextMenuView.Elements.Count == 0)
return;
var player = _playerManager.LocalPlayer?.ControlledEntity;
if (player == null)
return;
foreach (var entity in _contextMenuView.Elements.Keys.ToList())
{
if (entity.Deleted || !_playerCanSeeThroughContainers && entity.IsInContainer())
if (entity.Deleted || !_verbSystem.CanSeeAllContext && !player.InRangeUnOccluded(entity))
{
_contextMenuView.RemoveEntity(entity);
if (_verbSystem.CurrentTarget == entity.Uid)
_verbSystem.CloseVerbMenu();
}
}
}
#endregion
private bool CanSeeOnContextMenu(IEntity entity)
{
if (!entity.TryGetComponent(out ISpriteComponent? spriteComponent) || !spriteComponent.Visible)
{
return false;
}
if (entity.GetAllComponents<IShowContextMenu>().Any(s => !s.ShowContextMenu(entity)))
{
return false;
}
return _playerCanSeeThroughContainers || !entity.TryGetContainer(out var container) || container.ShowContents;
}
private void CloseAllMenus()
public void CloseAllMenus()
{
_contextMenuView.CloseContextPopups();
_verbSystem.CloseGroupMenu();
_verbSystem.CloseVerbMenu();
}
public void Dispose()
{
_verbSystem.ToggleContextMenu -= SystemOnToggleContextMenu;
_verbSystem.ToggleContainerVisibility -= SystemOnToggleContainerVisibility;
_contextMenuView.OnKeyBindDownSingle -= OnKeyBindDownSingle;
_contextMenuView.OnMouseEnteredSingle -= OnMouseEnteredSingle;
_contextMenuView.OnMouseExitedSingle -= OnMouseExitedSingle;
@@ -347,6 +382,8 @@ namespace Content.Client.ContextMenu.UI
_contextMenuView.OnExitedTree -= OnExitedTree;
_contextMenuView.OnCloseRootMenu -= OnCloseRootMenu;
_contextMenuView.OnCloseChildMenu -= OnCloseChildMenu;
CommandBinds.Unregister<ContextMenuPresenter>();
}
}
}

View File

@@ -1,4 +1,3 @@

using System;
using System.Collections.Generic;
using System.Linq;
@@ -73,7 +72,7 @@ namespace Content.Client.ContextMenu.UI
var entitySpriteStates = GroupEntities(entities);
var orderedStates = entitySpriteStates.ToList();
orderedStates.Sort((x, y) => string.CompareOrdinal(x.First().Prototype!.Name, y.First().Prototype!.Name));
orderedStates.Sort((x, y) => string.CompareOrdinal(x.First().Prototype?.Name, y.First().Prototype?.Name));
AddToUI(orderedStates);
_userInterfaceManager.ModalRoot.AddChild(rootContextMenu);

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using Robust.Client.GameObjects;
@@ -105,9 +105,13 @@ namespace Content.Client.ContextMenu.UI
public int GetHashCode(IEntity e)
{
var hash = EqualityComparer<string>.Default.GetHashCode(e.Prototype?.ID!);
foreach (var element in e.GetComponent<ISpriteComponent>().AllLayers.Where(obj => obj.Visible).Select(s => s.RsiState.Name))
if (e.TryGetComponent<ISpriteComponent>(out var sprite))
{
hash ^= EqualityComparer<string>.Default.GetHashCode(element!);
foreach (var element in sprite.AllLayers.Where(obj => obj.Visible).Select(s => s.RsiState.Name))
{
hash ^= EqualityComparer<string>.Default.GetHashCode(element!);
}
}
return hash;

View File

@@ -1,8 +1,9 @@
using System.Linq;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Content.Shared.Examine;
using Content.Shared.Input;
using Content.Shared.Verbs;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Client.Player;
@@ -12,6 +13,7 @@ using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Input.Binding;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Players;
@@ -38,6 +40,8 @@ namespace Content.Client.Examine
{
IoCManager.InjectDependencies(this);
SubscribeLocalEvent<GetOtherVerbsEvent>(AddExamineVerb);
CommandBinds.Builder
.Bind(ContentKeyFunctions.ExamineEntity, new PointerInputCmdHandler(HandleExamine))
.Register<ExamineSystem>();
@@ -85,6 +89,18 @@ namespace Content.Client.Examine
return true;
}
private void AddExamineVerb(GetOtherVerbsEvent args)
{
if (!CanExamine(args.User, args.Target))
return;
Verb verb = new();
verb.Act = () => DoExamine(args.Target) ;
verb.Text = Loc.GetString("examine-verb-name");
verb.IconTexture = "/Textures/Interface/VerbIcons/examine.svg.192dpi.png";
args.Verbs.Add(verb);
}
public async void DoExamine(IEntity entity)
{
// Close any examine tooltip that might already be opened

View File

@@ -1,26 +0,0 @@
using Content.Shared.Verbs;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
namespace Content.Client.Examine
{
[GlobalVerb]
public class ExamineVerb : GlobalVerb
{
public override bool RequireInteractionRange => false;
public override bool BlockedByContainers => false;
public override void GetData(IEntity user, IEntity target, VerbData data)
{
data.Visibility = VerbVisibility.Visible;
data.Text = Loc.GetString("examine-verb-name");
data.IconTexture = "/Textures/Interface/VerbIcons/examine.svg.192dpi.png";
}
public override void Activate(IEntity user, IEntity target)
{
EntitySystem.Get<ExamineSystem>().DoExamine(target);
}
}
}

View File

@@ -26,6 +26,7 @@ namespace Content.Client.Input
common.AddFunction(ContentKeyFunctions.TakeScreenshot);
common.AddFunction(ContentKeyFunctions.TakeScreenshotNoUI);
common.AddFunction(ContentKeyFunctions.Point);
common.AddFunction(ContentKeyFunctions.OpenContextMenu);
var human = contexts.GetContext("human");
human.AddFunction(ContentKeyFunctions.SwapHands);
@@ -39,7 +40,6 @@ namespace Content.Client.Input
human.AddFunction(ContentKeyFunctions.TryPullObject);
human.AddFunction(ContentKeyFunctions.MovePulledObject);
human.AddFunction(ContentKeyFunctions.ReleasePulledObject);
human.AddFunction(ContentKeyFunctions.OpenContextMenu);
human.AddFunction(ContentKeyFunctions.OpenCraftingMenu);
human.AddFunction(ContentKeyFunctions.OpenInventoryMenu);
human.AddFunction(ContentKeyFunctions.SmartEquipBackpack);
@@ -82,7 +82,6 @@ namespace Content.Client.Input
aghost.AddFunction(EngineKeyFunctions.MoveLeft);
aghost.AddFunction(EngineKeyFunctions.MoveRight);
aghost.AddFunction(EngineKeyFunctions.Walk);
aghost.AddFunction(ContentKeyFunctions.OpenContextMenu);
aghost.AddFunction(ContentKeyFunctions.SwapHands);
aghost.AddFunction(ContentKeyFunctions.Drop);
aghost.AddFunction(ContentKeyFunctions.ThrowItemInHand);
@@ -93,7 +92,6 @@ namespace Content.Client.Input
ghost.AddFunction(EngineKeyFunctions.MoveLeft);
ghost.AddFunction(EngineKeyFunctions.MoveRight);
ghost.AddFunction(EngineKeyFunctions.Walk);
ghost.AddFunction(ContentKeyFunctions.OpenContextMenu);
common.AddFunction(ContentKeyFunctions.OpenEntitySpawnWindow);
common.AddFunction(ContentKeyFunctions.OpenSandboxWindow);

View File

@@ -78,7 +78,7 @@ namespace Content.Client.Items.Managers
else if (args.Function == ContentKeyFunctions.OpenContextMenu)
{
_entitySystemManager.GetEntitySystem<VerbSystem>()
.OpenContextMenu(item, _uiMgr.ScreenToUIPosition(args.PointerLocation));
.OpenVerbMenu(item, _uiMgr.ScreenToUIPosition(args.PointerLocation));
}
else if (args.Function == ContentKeyFunctions.ActivateItemInWorld)
{

View File

@@ -1,11 +0,0 @@
using Content.Shared.Pulling.Components;
using Robust.Shared.GameObjects;
namespace Content.Client.Pulling
{
[RegisterComponent]
[ComponentReference(typeof(SharedPullableComponent))]
public class PullableComponent : SharedPullableComponent
{
}
}

View File

@@ -1,4 +1,5 @@
using Content.Shared.Pulling;
using Content.Shared.Pulling;
using Content.Shared.Pulling.Components;
using JetBrains.Annotations;
using Robust.Client.Physics;
@@ -13,8 +14,8 @@ namespace Content.Client.Pulling
UpdatesAfter.Add(typeof(PhysicsSystem));
SubscribeLocalEvent<PullableComponent, PullableMoveMessage>(OnPullableMove);
SubscribeLocalEvent<PullableComponent, PullableStopMovingMessage>(OnPullableStopMove);
SubscribeLocalEvent<SharedPullableComponent, PullableMoveMessage>(OnPullableMove);
SubscribeLocalEvent<SharedPullableComponent, PullableStopMovingMessage>(OnPullableStopMove);
}
}
}

View File

@@ -1,11 +0,0 @@
using Content.Shared.Rotatable;
using Robust.Shared.GameObjects;
namespace Content.Client.Rotatable
{
[RegisterComponent]
[ComponentReference(typeof(SharedRotatableComponent))]
public class RotatableComponent : SharedRotatableComponent
{
}
}

View File

@@ -0,0 +1,246 @@
using System.Collections.Generic;
using System.Threading;
using Content.Client.ContextMenu.UI;
using Content.Client.Resources;
using Content.Shared.Verbs;
using Robust.Client.Graphics;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.Utility;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
using static Robust.Client.UserInterface.Controls.BoxContainer;
using Timer = Robust.Shared.Timing.Timer;
namespace Content.Client.Verbs
{
/// <summary>
/// This pop-up appears when hovering over a verb category in the context menu.
/// </summary>
public sealed class VerbCategoryPopup : ContextMenuPopup
{
public VerbCategoryPopup(VerbSystem system, IEnumerable<Verb> verbs, VerbType type, EntityUid target, bool drawOnlyIcons)
: base()
{
// Do any verbs have icons? If not, don't bother leaving space for icons in the pop-up.
var drawVerbIcons = false;
foreach (var verb in verbs)
{
if (verb.Icon != null)
{
drawVerbIcons = true;
break;
}
}
// If no verbs have icons. we cannot draw only icons
if (drawVerbIcons == false)
drawOnlyIcons = false;
// If we are drawing only icons, show them side by side
if (drawOnlyIcons)
List.Orientation = LayoutOrientation.Horizontal;
foreach (var verb in verbs)
{
AddToMenu(new VerbButton(system, verb, type, target, drawVerbIcons));
}
}
}
public sealed class VerbButton : BaseButton
{
public VerbButton(VerbSystem system, Verb verb, VerbType type, EntityUid target, bool drawIcons = true, bool categoryPrefix = false) : base()
{
Disabled = verb.Disabled;
ToolTip = verb.Tooltip;
TooltipDelay = 0.5f;
var buttonContents = new BoxContainer { Orientation = LayoutOrientation.Horizontal };
// maybe draw verb icons
if (drawIcons)
{
TextureRect icon = new()
{
MinSize = (ContextMenuPopup.ButtonHeight, ContextMenuPopup.ButtonHeight),
Stretch = TextureRect.StretchMode.KeepCentered,
TextureScale = (0.5f, 0.5f)
};
// Even though we are drawing icons, the icon for this specific verb may be null.
if (verb.Icon != null)
{
icon.Texture = verb.Icon.Frame0();
} else if (categoryPrefix && verb.Category?.Icon != null)
{
// we will use the category icon instead
icon.Texture = verb.Category.Icon.Frame0();
}
buttonContents.AddChild(icon);
}
// maybe add a label
if (verb.Text != string.Empty || categoryPrefix)
{
// First add a small bit of padding
buttonContents.AddChild(new Control { MinSize = (4, ContextMenuPopup.ButtonHeight) });
var label = new RichTextLabel();
var text = categoryPrefix ? verb.Category!.Text + " " + verb.Text : verb.Text;
label.SetMessage(FormattedMessage.FromMarkupPermissive(text.Trim()));
label.VerticalAlignment = VAlignment.Center;
buttonContents.AddChild(label);
// Then also add some padding after the text.
buttonContents.AddChild(new Control { MinSize = (4, ContextMenuPopup.ButtonHeight) });
}
AddChild(buttonContents);
if (Disabled)
return;
// give the button functionality!
OnPressed += _ =>
{
if (verb.CloseMenu)
system.ContextMenuPresenter.CloseAllMenus();
system.TryExecuteVerb(verb, target, type);
};
}
protected override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
if (Disabled)
{
// use transparent-black rectangle to create a darker background.
handle.DrawRect(PixelSizeBox, new Color(0,0,0,155));
}
else if (DrawMode == DrawModeEnum.Hover)
{
// Draw a lighter shade of gray when hovered over
handle.DrawRect(PixelSizeBox, Color.DarkSlateGray);
}
}
}
public sealed class VerbCategoryButton : Control
{
private readonly VerbSystem _system;
private CancellationTokenSource? _openCancel;
/// <summary>
/// Whether or not to hide member verb text and just show icons.
/// </summary>
/// <remarks>
/// If no members have icons, this option is ignored and text is shown anyways. Defaults to using <see cref="VerbCategory.IconsOnly"/>.
/// </remarks>
private readonly bool _drawOnlyIcons;
/// <summary>
/// The pop-up that appears when hovering over this verb group.
/// </summary>
private readonly VerbCategoryPopup _popup;
public VerbCategoryButton(VerbSystem system, VerbCategory category, IEnumerable<Verb> verbs, VerbType type, EntityUid target, bool? drawOnlyIcons = null) : base()
{
_system = system;
_drawOnlyIcons = drawOnlyIcons ?? category.IconsOnly;
MouseFilter = MouseFilterMode.Stop;
// Contents of the button stored in this box container
var box = new BoxContainer() { Orientation = LayoutOrientation.Horizontal };
// First we add the icon for the verb group
var icon = new TextureRect
{
MinSize = (ContextMenuPopup.ButtonHeight, ContextMenuPopup.ButtonHeight),
TextureScale = (0.5f, 0.5f),
Stretch = TextureRect.StretchMode.KeepCentered,
};
if (category.Icon != null)
{
icon.Texture = category.Icon.Frame0();
}
box.AddChild(icon);
// Some padding before the text
box.AddChild(new Control { MinSize = (4, ContextMenuPopup.ButtonHeight) });
// Then we add the label
var label = new RichTextLabel();
label.SetMessage(FormattedMessage.FromMarkupPermissive(category.Text));
label.HorizontalExpand = true;
label.VerticalAlignment = VAlignment.Center;
box.AddChild(label);
// Then also add some padding after the text.
box.AddChild(new Control { MinSize = (4, ContextMenuPopup.ButtonHeight) });
// Then add the little ">" icon that tells you it's a group of verbs
box.AddChild(new TextureRect
{
Texture = IoCManager.Resolve<IResourceCache>()
.GetTexture("/Textures/Interface/VerbIcons/group.svg.192dpi.png"),
TextureScale = (0.5f, 0.5f),
Stretch = TextureRect.StretchMode.KeepCentered,
});
// The pop-up that appears when hovering over the button
_popup = new VerbCategoryPopup(_system, verbs, type, target, _drawOnlyIcons);
UserInterfaceManager.ModalRoot.AddChild(_popup);
AddChild(box);
}
protected override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
if (this == UserInterfaceManager.CurrentlyHovered ||
_system.CurrentCategoryPopup == _popup)
{
handle.DrawRect(PixelSizeBox, Color.DarkSlateGray);
}
}
/// <summary>
/// Open a verb category pop-up after a short delay.
/// </summary>
protected override void MouseEntered()
{
base.MouseEntered();
_openCancel = new CancellationTokenSource();
Timer.Spawn(ContextMenuPresenter.HoverDelay, () =>
{
_system.CurrentCategoryPopup?.Close();
_system.CurrentCategoryPopup = _popup;
var upperRight = GlobalPosition + (Width + ContextMenuPopup.MarginSize, -ContextMenuPopup.MarginSize);
_popup.Open(UIBox2.FromDimensions(upperRight, (1, 1)), GlobalPosition);
}, _openCancel.Token);
}
/// <summary>
/// Cancel the delayed pop-up
/// </summary>
protected override void MouseExited()
{
base.MouseExited();
_openCancel?.Cancel();
_openCancel = null;
}
}
}

View File

@@ -1,535 +1,228 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
using System.Linq;
using Content.Client.ContextMenu.UI;
using Content.Client.Resources;
using Content.Shared.GameTicking;
using Content.Shared.Input;
using Content.Shared.Verbs;
using JetBrains.Annotations;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.Utility;
using Robust.Shared.GameObjects;
using Robust.Shared.Input;
using Robust.Shared.Input.Binding;
using Robust.Shared.IoC;
using Robust.Shared.Localization;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
using static Robust.Client.UserInterface.Controls.BoxContainer;
using Timer = Robust.Shared.Timing.Timer;
namespace Content.Client.Verbs
{
[UsedImplicitly]
public sealed class VerbSystem : SharedVerbSystem
{
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
public event EventHandler<PointerInputCmdHandler.PointerInputCmdArgs>? ToggleContextMenu;
public event EventHandler<bool>? ToggleContainerVisibility;
public ContextMenuPresenter ContextMenuPresenter = default!;
private ContextMenuPresenter _contextMenuPresenter = default!;
private VerbPopup? _currentVerbListRoot;
private VerbPopup? _currentGroupList;
private EntityUid _currentEntity;
public EntityUid CurrentTarget;
public ContextMenuPopup? CurrentVerbPopup;
public ContextMenuPopup? CurrentCategoryPopup;
public Dictionary<VerbType, SortedSet<Verb>> CurrentVerbs = new();
// TODO: Move presenter out of the system
// TODO: Separate the rest of the UI from the logic
/// <summary>
/// Whether to show all entities on the context menu.
/// </summary>
/// <remarks>
/// Verb execution will only be affected if the server also agrees that this player can see the target
/// entity.
/// </remarks>
public bool CanSeeAllContext = false;
// TODO VERBS Move presenter out of the system
// TODO VERBS Separate the rest of the UI from the logic
public override void Initialize()
{
base.Initialize();
SubscribeNetworkEvent<RoundRestartCleanupEvent>(Reset);
SubscribeNetworkEvent<VerbSystemMessages.VerbsResponseMessage>(FillEntityPopup);
SubscribeNetworkEvent<PlayerContainerVisibilityMessage>(HandleContainerVisibilityMessage);
SubscribeNetworkEvent<VerbsResponseEvent>(HandleVerbResponse);
SubscribeNetworkEvent<SetSeeAllContextEvent>(SetSeeAllContext);
_contextMenuPresenter = new ContextMenuPresenter(this);
SubscribeLocalEvent<MoveEvent>(_contextMenuPresenter.HandleMoveEvent);
ContextMenuPresenter = new ContextMenuPresenter(this);
}
CommandBinds.Builder
.Bind(ContentKeyFunctions.OpenContextMenu,
new PointerInputCmdHandler(HandleOpenContextMenu))
.Register<VerbSystem>();
private void Reset(RoundRestartCleanupEvent ev)
{
ContextMenuPresenter.CloseAllMenus();
}
public override void Shutdown()
{
base.Shutdown();
_contextMenuPresenter?.Dispose();
CommandBinds.Unregister<VerbSystem>();
}
public void Reset(RoundRestartCleanupEvent ev)
{
ToggleContainerVisibility?.Invoke(this, false);
}
private bool HandleOpenContextMenu(in PointerInputCmdHandler.PointerInputCmdArgs args)
{
if (args.State == BoundKeyState.Down)
{
ToggleContextMenu?.Invoke(this, args);
}
return true;
}
private void HandleContainerVisibilityMessage(PlayerContainerVisibilityMessage ev)
{
ToggleContainerVisibility?.Invoke(this, ev.CanSeeThrough);
ContextMenuPresenter?.Dispose();
}
public override void Update(float frameTime)
{
base.Update(frameTime);
_contextMenuPresenter?.Update();
ContextMenuPresenter?.Update();
}
public void OpenContextMenu(IEntity entity, ScreenCoordinates screenCoordinates)
private void SetSeeAllContext(SetSeeAllContextEvent args)
{
if (_currentVerbListRoot != null)
CanSeeAllContext = args.CanSeeAllContext;
}
/// <summary>
/// Execute actions associated with the given verb. If there are no defined actions, this will instead ask
/// the server to run the given verb.
/// </summary>
public void TryExecuteVerb(Verb verb, EntityUid target, VerbType verbType)
{
if (!TryExecuteVerb(verb))
RaiseNetworkEvent(new TryExecuteVerbEvent(target, verb, verbType));
}
public void OpenVerbMenu(IEntity target, ScreenCoordinates screenCoordinates)
{
if (CurrentVerbPopup != null)
{
CloseVerbMenu();
}
_currentEntity = entity.Uid;
_currentVerbListRoot = new VerbPopup();
_userInterfaceManager.ModalRoot.AddChild(_currentVerbListRoot);
_currentVerbListRoot.OnPopupHide += CloseVerbMenu;
var user = _playerManager.LocalPlayer?.ControlledEntity;
if (user == null)
return;
if (!entity.Uid.IsClientSide())
CurrentTarget = target.Uid;
CurrentVerbPopup = new ContextMenuPopup();
_userInterfaceManager.ModalRoot.AddChild(CurrentVerbPopup);
CurrentVerbPopup.OnPopupHide += CloseVerbMenu;
CurrentVerbs = GetVerbs(target, user, VerbType.All);
if (!target.Uid.IsClientSide())
{
_currentVerbListRoot.List.AddChild(new Label { Text = Loc.GetString("verb-system-waiting-on-server-text") });
RaiseNetworkEvent(new VerbSystemMessages.RequestVerbsMessage(_currentEntity));
CurrentVerbPopup.AddToMenu(new Label { Text = Loc.GetString("verb-system-waiting-on-server-text") });
RaiseNetworkEvent(new RequestServerVerbsEvent(CurrentTarget, VerbType.All));
}
// Show the menu
FillVerbPopup(CurrentVerbPopup);
var box = UIBox2.FromDimensions(screenCoordinates.Position, (1, 1));
_currentVerbListRoot.Open(box);
CurrentVerbPopup.Open(box);
}
public void OnContextButtonPressed(IEntity entity)
{
OpenContextMenu(entity, _userInterfaceManager.MousePositionScaled);
OpenVerbMenu(entity, _userInterfaceManager.MousePositionScaled);
}
private void FillEntityPopup(VerbSystemMessages.VerbsResponseMessage msg)
private void HandleVerbResponse(VerbsResponseEvent msg)
{
if (_currentEntity != msg.Entity || !EntityManager.TryGetEntity(_currentEntity, out var entity))
if (CurrentTarget != msg.Entity || CurrentVerbPopup == null)
{
return;
}
DebugTools.AssertNotNull(_currentVerbListRoot);
var buttons = new Dictionary<string, List<ListedVerbData>>();
var groupIcons = new Dictionary<string, SpriteSpecifier>();
var vBox = _currentVerbListRoot!.List;
vBox.DisposeAllChildren();
// Local variable so that scope capture ensures this is the correct value.
var curEntity = _currentEntity;
foreach (var data in msg.Verbs)
// This **should** not happen.
if (msg.Verbs == null)
{
var list = buttons.GetOrNew(data.Category);
if (data.CategoryIcon != null && !groupIcons.ContainsKey(data.Category))
{
groupIcons.Add(data.Category, data.CategoryIcon);
}
list.Add(new ListedVerbData(data.Text, !data.Available, data.Key, entity.ToString()!, () =>
{
RaiseNetworkEvent(new VerbSystemMessages.UseVerbMessage(curEntity, data.Key));
CloseAllMenus();
}, data.Icon));
// update "waiting for server...".
CurrentVerbPopup.List.DisposeAllChildren();
CurrentVerbPopup.AddToMenu(new Label { Text = Loc.GetString("verb-system-null-server-response") });
FillVerbPopup(CurrentVerbPopup);
return;
}
var user = GetUserEntity();
//Get verbs, component dependent.
foreach (var (component, verb) in VerbUtility.GetVerbs(entity))
// Add the new server-side verbs.
foreach (var (verbType, verbSet) in msg.Verbs)
{
if (!VerbUtility.VerbAccessChecks(user, entity, verb))
SortedSet<Verb> sortedVerbs = new (verbSet);
if (!CurrentVerbs.TryAdd(verbType, sortedVerbs))
{
continue;
CurrentVerbs[verbType].UnionWith(sortedVerbs);
}
var verbData = verb.GetData(user, component);
if (verbData.IsInvisible)
continue;
var list = buttons.GetOrNew(verbData.Category);
if (verbData.CategoryIcon != null && !groupIcons.ContainsKey(verbData.Category))
{
groupIcons.Add(verbData.Category, verbData.CategoryIcon);
}
list.Add(new ListedVerbData(verbData.Text, verbData.IsDisabled, verb.ToString()!, entity.ToString()!,
() => verb.Activate(user, component), verbData.Icon));
}
//Get global verbs. Visible for all entities regardless of their components.
foreach (var globalVerb in VerbUtility.GetGlobalVerbs(Assembly.GetExecutingAssembly()))
// Clear currently shown verbs and show new ones
CurrentVerbPopup.List.DisposeAllChildren();
FillVerbPopup(CurrentVerbPopup);
}
private void FillVerbPopup(ContextMenuPopup popup)
{
if (CurrentTarget == EntityUid.Invalid)
return;
// Add verbs to pop-up, grouped by type. Order determined by how types are defined VerbTypes
var types = CurrentVerbs.Keys.ToList();
types.Sort();
foreach (var type in types)
{
if (!VerbUtility.VerbAccessChecks(user, entity, globalVerb))
{
continue;
}
var verbData = globalVerb.GetData(user, entity);
if (verbData.IsInvisible)
continue;
var list = buttons.GetOrNew(verbData.Category);
if (verbData.CategoryIcon != null && !groupIcons.ContainsKey(verbData.Category))
{
groupIcons.Add(verbData.Category, verbData.CategoryIcon);
}
list.Add(new ListedVerbData(verbData.Text, verbData.IsDisabled, globalVerb.ToString()!,
entity.ToString()!,
() => globalVerb.Activate(user, entity), verbData.Icon));
AddVerbSet(popup, type);
}
if (buttons.Count > 0)
{
var first = true;
foreach (var (category, verbs) in buttons)
{
if (string.IsNullOrEmpty(category))
continue;
if (!first)
{
vBox.AddChild(new PanelContainer
{
MinSize = (0, 2),
PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex("#333") }
});
}
first = false;
groupIcons.TryGetValue(category, out var icon);
vBox.AddChild(CreateCategoryButton(category, verbs, icon));
}
if (buttons.ContainsKey(""))
{
buttons[""].Sort((a, b) => string.Compare(a.Text, b.Text, StringComparison.CurrentCulture));
foreach (var verb in buttons[""])
{
if (!first)
{
vBox.AddChild(new PanelContainer
{
MinSize = (0, 2),
PanelOverride = new StyleBoxFlat { BackgroundColor = Color.FromHex("#333") }
});
}
first = false;
vBox.AddChild(CreateVerbButton(verb));
}
}
}
else
// Were the verb lists empty?
if (popup.List.ChildCount == 0)
{
var panel = new PanelContainer();
panel.AddChild(new Label { Text = Loc.GetString("verb-system-no-verbs-text") });
vBox.AddChild(panel);
popup.AddChild(panel);
}
popup.InvalidateMeasure();
}
private VerbButton CreateVerbButton(ListedVerbData data)
/// <summary>
/// Add a list of verbs to a BoxContainer. Iterates over the given verbs list and creates GUI buttons.
/// </summary>
private void AddVerbSet(ContextMenuPopup popup, VerbType type)
{
var button = new VerbButton
{
Text = Loc.GetString(data.Text),
Disabled = data.Disabled
};
if (!CurrentVerbs.TryGetValue(type, out var verbSet) || verbSet.Count == 0)
return;
if (data.Icon != null)
{
button.Icon = data.Icon.Frame0();
}
HashSet<string> listedCategories = new();
if (!data.Disabled)
foreach (var verb in verbSet)
{
button.OnPressed += _ =>
if (verb.Category == null)
{
CloseAllMenus();
try
{
data.Action.Invoke();
}
catch (Exception e)
{
Logger.ErrorS("verb", "Exception in verb {0} on {1}:\n{2}", data.VerbName, data.OwnerName, e);
}
};
// Lone verb without a category. just create a button for it
popup.AddToMenu(new VerbButton(this, verb, type, CurrentTarget));
continue;
}
if (listedCategories.Contains(verb.Category.Text))
{
// This verb was already included in a verb-category button added by a previous verb
continue;
}
// Get the verbs in the category
var verbsInCategory = verbSet.Where(v => v.Category?.Text == verb.Category.Text);
popup.AddToMenu(
new VerbCategoryButton(this, verb.Category, verbsInCategory, type, CurrentTarget));
listedCategories.Add(verb.Category.Text);
continue;
}
return button;
}
private Control CreateCategoryButton(string text, List<ListedVerbData> verbButtons, SpriteSpecifier? icon)
{
verbButtons.Sort((a, b) => string.Compare(a.Text, b.Text, StringComparison.CurrentCulture));
return new VerbGroupButton(this, verbButtons, icon)
{
Text = Loc.GetString(text),
};
}
public void CloseVerbMenu()
{
_currentVerbListRoot?.Dispose();
_currentVerbListRoot = null;
_currentEntity = EntityUid.Invalid;
}
private void CloseAllMenus()
{
CloseVerbMenu();
// CloseContextPopups();
CloseGroupMenu();
}
public void CloseGroupMenu()
{
_currentGroupList?.Dispose();
_currentGroupList = null;
}
private IEntity GetUserEntity()
{
return _playerManager.LocalPlayer!.ControlledEntity!;
}
private sealed class VerbPopup : Popup
{
public BoxContainer List { get; }
public VerbPopup()
if (CurrentVerbPopup != null)
{
AddChild(new PanelContainer
{
Children = {(List = new BoxContainer
{
Orientation = LayoutOrientation.Vertical
})},
PanelOverride = new StyleBoxFlat {BackgroundColor = Color.FromHex("#111E")}
});
}
}
private sealed class VerbButton : BaseButton
{
private readonly Label _label;
private readonly TextureRect _icon;
public Texture? Icon
{
get => _icon.Texture;
set => _icon.Texture = value;
CurrentVerbPopup.OnPopupHide -= CloseVerbMenu;
CurrentVerbPopup.Dispose();
CurrentVerbPopup = null;
}
public string? Text
{
get => _label.Text;
set => _label.Text = value;
}
public VerbButton()
{
AddChild(new BoxContainer
{
Orientation = LayoutOrientation.Horizontal,
Children =
{
(_icon = new TextureRect
{
MinSize = (32, 32),
Stretch = TextureRect.StretchMode.KeepCentered,
TextureScale = (0.5f, 0.5f)
}),
(_label = new Label()),
// Padding
new Control {MinSize = (8, 0)}
}
});
}
protected override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
if (DrawMode == DrawModeEnum.Hover)
{
handle.DrawRect(PixelSizeBox, Color.DarkSlateGray);
}
}
}
private sealed class VerbGroupButton : Control
{
private static readonly TimeSpan HoverDelay = TimeSpan.FromSeconds(0.2);
private readonly VerbSystem _system;
private readonly Label _label;
private readonly TextureRect _icon;
private CancellationTokenSource? _openCancel;
public List<ListedVerbData> VerbButtons { get; }
public string? Text
{
get => _label.Text;
set => _label.Text = value;
}
public Texture? Icon
{
get => _icon.Texture;
set => _icon.Texture = value;
}
public VerbGroupButton(VerbSystem system, List<ListedVerbData> verbButtons, SpriteSpecifier? icon)
{
_system = system;
VerbButtons = verbButtons;
MouseFilter = MouseFilterMode.Stop;
AddChild(new BoxContainer
{
Orientation = LayoutOrientation.Horizontal,
Children =
{
(_icon = new TextureRect
{
MinSize = (32, 32),
TextureScale = (0.5f, 0.5f),
Stretch = TextureRect.StretchMode.KeepCentered
}),
(_label = new Label { HorizontalExpand = true }),
// Padding
new Control {MinSize = (8, 0)},
new TextureRect
{
Texture = IoCManager.Resolve<IResourceCache>()
.GetTexture("/Textures/Interface/VerbIcons/group.svg.192dpi.png"),
TextureScale = (0.5f, 0.5f),
Stretch = TextureRect.StretchMode.KeepCentered,
}
}
});
if (icon != null)
{
_icon.Texture = icon.Frame0();
}
}
protected override void Draw(DrawingHandleScreen handle)
{
base.Draw(handle);
if (this == UserInterfaceManager.CurrentlyHovered)
{
handle.DrawRect(PixelSizeBox, Color.DarkSlateGray);
}
}
protected override void MouseEntered()
{
base.MouseEntered();
_openCancel = new CancellationTokenSource();
Timer.Spawn(HoverDelay, () =>
{
if (_system._currentGroupList != null)
{
_system.CloseGroupMenu();
}
var popup = _system._currentGroupList = new VerbPopup();
var first = true;
foreach (var verb in VerbButtons)
{
if (!first)
{
popup.List.AddChild(new PanelContainer
{
MinSize = (0, 2),
PanelOverride = new StyleBoxFlat {BackgroundColor = Color.FromHex("#333")}
});
}
first = false;
popup.List.AddChild(_system.CreateVerbButton(verb));
}
UserInterfaceManager.ModalRoot.AddChild(popup);
popup.Open(UIBox2.FromDimensions(GlobalPosition + (Width, 0), (1, 1)), GlobalPosition);
}, _openCancel.Token);
}
protected override void MouseExited()
{
base.MouseExited();
_openCancel?.Cancel();
_openCancel = null;
}
}
private sealed class ListedVerbData
{
public string Text { get; }
public bool Disabled { get; }
public string VerbName { get; }
public string OwnerName { get; }
public SpriteSpecifier? Icon { get; }
public Action Action { get; }
public ListedVerbData(string text, bool disabled, string verbName, string ownerName,
Action action, SpriteSpecifier? icon)
{
Text = text;
Disabled = disabled;
VerbName = verbName;
OwnerName = ownerName;
Action = action;
Icon = icon;
}
CurrentCategoryPopup?.Dispose();
CurrentCategoryPopup = null;
CurrentTarget = EntityUid.Invalid;
CurrentVerbs.Clear();
}
}
}

View File

@@ -1,38 +0,0 @@
using Content.Shared.Verbs;
using Robust.Client.Console;
using Robust.Client.ViewVariables;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Client.ViewVariables
{
/// <summary>
/// Global verb that opens a view variables window for the entity in question.
/// </summary>
[GlobalVerb]
class ViewVariablesVerb : GlobalVerb
{
public override bool RequireInteractionRange => false;
public override bool BlockedByContainers => false;
public override void GetData(IEntity user, IEntity target, VerbData data)
{
var groupController = IoCManager.Resolve<IClientConGroupController>();
if (!groupController.CanViewVar())
{
data.Visibility = VerbVisibility.Invisible;
return;
}
data.Text = "View Variables";
data.CategoryData = VerbCategories.Debug;
data.IconTexture = "/Textures/Interface/VerbIcons/vv.svg.192dpi.png";
}
public override void Activate(IEntity user, IEntity target)
{
var vvm = IoCManager.Resolve<IViewVariablesManager>();
vvm.OpenVV(target);
}
}
}