Skip to content

Commit

Permalink
Verb tweaks (#31309)
Browse files Browse the repository at this point in the history
* Verb tweaks

Remove the LOS check because this is already done above in CanExamine.

* Fix outlines

* import
  • Loading branch information
metalgearsloth authored and sleepyyapril committed Jan 4, 2025
1 parent d8ae58e commit c866ffb
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 40 deletions.
1 change: 1 addition & 0 deletions Content.Client/Commands/SetMenuVisibilityCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Client.Verbs;
using Content.Shared.Verbs;
using JetBrains.Annotations;
using Robust.Shared.Console;

Expand Down
19 changes: 16 additions & 3 deletions Content.Client/ContextMenu/UI/EntityMenuUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand Down Expand Up @@ -194,8 +195,20 @@ public override void FrameUpdate(FrameEventArgs args)
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<TransformComponent>();
Expand All @@ -209,7 +222,7 @@ public override void FrameUpdate(FrameEventArgs args)
continue;
}

if (ignoreFov)
if ((visibility & MenuVisibility.NoFov) == MenuVisibility.NoFov)
continue;

var pos = new MapCoordinates(_xform.GetWorldPosition(xform, xformQuery), xform.MapID);
Expand Down
45 changes: 8 additions & 37 deletions Content.Client/Verbs/VerbSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ public bool TryGetEntityMenuEntities(MapCoordinates targetPos, [NotNullWhen(true
? Visibility
: Visibility | MenuVisibility.NoFov;

var ev = new MenuVisibilityEvent()
{
TargetPos = targetPos,
Visibility = visibility,
};

RaiseLocalEvent(player.Value, ref ev);
visibility = ev.Visibility;

// Get entities
List<EntityUid> entities;
Expand All @@ -78,13 +86,8 @@ public bool TryGetEntityMenuEntities(MapCoordinates targetPos, [NotNullWhen(true
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, flags: examineFlags))
{
Expand Down Expand Up @@ -138,27 +141,6 @@ public bool TryGetEntityMenuEntities(MapCoordinates targetPos, [NotNullWhen(true
}
}

// Remove any entities that do not have LOS
if ((visibility & MenuVisibility.NoFov) == 0)
{
var xformQuery = GetEntityQuery<TransformComponent>();
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;

Expand Down Expand Up @@ -230,15 +212,4 @@ private void HandleVerbResponse(VerbsResponseEvent msg)
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
}
}
24 changes: 24 additions & 0 deletions Content.Shared/Verbs/SharedVerbSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Content.Shared.Interaction;
using Content.Shared.Inventory.VirtualItem;
using Robust.Shared.Containers;
using Robust.Shared.Map;

namespace Content.Shared.Verbs
{
Expand Down Expand Up @@ -174,4 +175,27 @@ public virtual void ExecuteVerb(Verb verb, EntityUid user, EntityUid target, boo
_interactionSystem.DoContactInteraction(user, target);
}
}

// Does nothing on server
/// <summary>
/// Raised directed when trying to get the entity menu visibility for entities.
/// </summary>
[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
}
}

0 comments on commit c866ffb

Please sign in to comment.