From 7cb6b5e972cbb0bd28e0891e370f90ff79b24194 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sun, 25 Aug 2024 22:05:39 +1000 Subject: [PATCH] Verb tweaks (#31309) * Verb tweaks Remove the LOS check because this is already done above in CanExamine. * Fix outlines * import --- .../Commands/SetMenuVisibilityCommand.cs | 1 + .../ContextMenu/UI/EntityMenuUIController.cs | 19 ++++++-- Content.Client/Verbs/VerbSystem.cs | 45 ++++--------------- Content.Shared/Verbs/SharedVerbSystem.cs | 24 ++++++++++ 4 files changed, 49 insertions(+), 40 deletions(-) diff --git a/Content.Client/Commands/SetMenuVisibilityCommand.cs b/Content.Client/Commands/SetMenuVisibilityCommand.cs index ddfb0b1692..17a544daba 100644 --- a/Content.Client/Commands/SetMenuVisibilityCommand.cs +++ b/Content.Client/Commands/SetMenuVisibilityCommand.cs @@ -1,4 +1,5 @@ using Content.Client.Verbs; +using Content.Shared.Verbs; using JetBrains.Annotations; using Robust.Shared.Console; diff --git a/Content.Client/ContextMenu/UI/EntityMenuUIController.cs b/Content.Client/ContextMenu/UI/EntityMenuUIController.cs index 0462c095ba..bda831394d 100644 --- a/Content.Client/ContextMenu/UI/EntityMenuUIController.cs +++ b/Content.Client/ContextMenu/UI/EntityMenuUIController.cs @@ -9,6 +9,7 @@ using Content.Shared.CCVar; using Content.Shared.Examine; using Content.Shared.IdentityManagement; using Content.Shared.Input; +using Content.Shared.Verbs; using Robust.Client.GameObjects; using Robust.Client.Graphics; using Robust.Client.Input; @@ -194,8 +195,20 @@ namespace Content.Client.ContextMenu.UI return; // Do we need to do in-range unOccluded checks? - var ignoreFov = !_eyeManager.CurrentEye.DrawFov || - (_verbSystem.Visibility & MenuVisibility.NoFov) == MenuVisibility.NoFov; + var visibility = _verbSystem.Visibility; + + if (!_eyeManager.CurrentEye.DrawFov) + { + visibility &= ~MenuVisibility.NoFov; + } + + var ev = new MenuVisibilityEvent() + { + Visibility = visibility, + }; + + _entityManager.EventBus.RaiseLocalEvent(player, ref ev); + visibility = ev.Visibility; _entityManager.TryGetComponent(player, out ExaminerComponent? examiner); var xformQuery = _entityManager.GetEntityQuery(); @@ -209,7 +222,7 @@ namespace Content.Client.ContextMenu.UI continue; } - if (ignoreFov) + if ((visibility & MenuVisibility.NoFov) == MenuVisibility.NoFov) continue; var pos = new MapCoordinates(_xform.GetWorldPosition(xform, xformQuery), xform.MapID); diff --git a/Content.Client/Verbs/VerbSystem.cs b/Content.Client/Verbs/VerbSystem.cs index 5f1f49e5fd..c3e03528a7 100644 --- a/Content.Client/Verbs/VerbSystem.cs +++ b/Content.Client/Verbs/VerbSystem.cs @@ -67,6 +67,14 @@ namespace Content.Client.Verbs ? Visibility : Visibility | MenuVisibility.NoFov; + var ev = new MenuVisibilityEvent() + { + TargetPos = targetPos, + Visibility = visibility, + }; + + RaiseLocalEvent(player.Value, ref ev); + visibility = ev.Visibility; // Get entities List entities; @@ -77,13 +85,8 @@ namespace Content.Client.Verbs var entitiesUnderMouse = gameScreenBase.GetClickableEntities(targetPos).ToHashSet(); bool Predicate(EntityUid e) => e == player || entitiesUnderMouse.Contains(e); - // first check the general location. - if (!_examine.CanExamine(player.Value, targetPos, Predicate)) - return false; - TryComp(player.Value, out ExaminerComponent? examiner); - // Then check every entity entities = new(); foreach (var ent in _entityLookup.GetEntitiesInRange(targetPos, EntityMenuLookupSize)) { @@ -137,27 +140,6 @@ namespace Content.Client.Verbs } } - // Remove any entities that do not have LOS - if ((visibility & MenuVisibility.NoFov) == 0) - { - var xformQuery = GetEntityQuery(); - var playerPos = _transform.GetMapCoordinates(player.Value, xform: xformQuery.GetComponent(player.Value)); - - for (var i = entities.Count - 1; i >= 0; i--) - { - var entity = entities[i]; - - if (!_examine.InRangeUnOccluded( - playerPos, - _transform.GetMapCoordinates(entity, xform: xformQuery.GetComponent(entity)), - ExamineSystemShared.ExamineRange, - null)) - { - entities.RemoveSwap(i); - } - } - } - if (entities.Count == 0) return false; @@ -229,15 +211,4 @@ namespace Content.Client.Verbs OnVerbsResponse?.Invoke(msg); } } - - [Flags] - public enum MenuVisibility - { - // What entities can a user see on the entity menu? - Default = 0, // They can only see entities in FoV. - NoFov = 1 << 0, // They ignore FoV restrictions - InContainer = 1 << 1, // They can see through containers. - Invisible = 1 << 2, // They can see entities without sprites and the "HideContextMenu" tag is ignored. - All = NoFov | InContainer | Invisible - } } diff --git a/Content.Shared/Verbs/SharedVerbSystem.cs b/Content.Shared/Verbs/SharedVerbSystem.cs index 319f927c7b..db17599d87 100644 --- a/Content.Shared/Verbs/SharedVerbSystem.cs +++ b/Content.Shared/Verbs/SharedVerbSystem.cs @@ -3,6 +3,7 @@ using Content.Shared.Hands.Components; using Content.Shared.Interaction; using Content.Shared.Inventory.VirtualItem; using Robust.Shared.Containers; +using Robust.Shared.Map; namespace Content.Shared.Verbs { @@ -173,4 +174,27 @@ namespace Content.Shared.Verbs _interactionSystem.DoContactInteraction(user, target); } } + + // Does nothing on server + /// + /// Raised directed when trying to get the entity menu visibility for entities. + /// + [ByRefEvent] + public record struct MenuVisibilityEvent + { + public MapCoordinates TargetPos; + public MenuVisibility Visibility; + } + + // Does nothing on server + [Flags] + public enum MenuVisibility + { + // What entities can a user see on the entity menu? + Default = 0, // They can only see entities in FoV. + NoFov = 1 << 0, // They ignore FoV restrictions + InContainer = 1 << 1, // They can see through containers. + Invisible = 1 << 2, // They can see entities without sprites and the "HideContextMenu" tag is ignored. + All = NoFov | InContainer | Invisible + } }