Restrict examine/context-menu usage when incapacitated. (#5416)
* wip * update in-view checks * cleanup
This commit is contained in:
@@ -46,6 +46,7 @@ namespace Content.Client.ContextMenu.UI
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
|
||||
private readonly VerbSystem _verbSystem;
|
||||
private readonly ExamineSystem _examineSystem;
|
||||
|
||||
/// <summary>
|
||||
/// This maps the currently displayed entities to the actual GUI elements.
|
||||
@@ -60,6 +61,7 @@ namespace Content.Client.ContextMenu.UI
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
_verbSystem = verbSystem;
|
||||
_examineSystem = EntitySystem.Get<ExamineSystem>();
|
||||
|
||||
_cfg.OnValueChanged(CCVars.EntityMenuGroupingType, OnGroupingChanged, true);
|
||||
|
||||
@@ -157,10 +159,9 @@ namespace Content.Client.ContextMenu.UI
|
||||
|
||||
var coords = args.Coordinates.ToMap(_entityManager);
|
||||
|
||||
if (!_verbSystem.TryGetEntityMenuEntities(coords, out var entities))
|
||||
return false;
|
||||
if (_verbSystem.TryGetEntityMenuEntities(coords, out var entities))
|
||||
OpenRootMenu(entities);
|
||||
|
||||
OpenRootMenu(entities);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -183,7 +184,7 @@ namespace Content.Client.ContextMenu.UI
|
||||
|
||||
foreach (var entity in Elements.Keys.ToList())
|
||||
{
|
||||
if (entity.Deleted || !ignoreFov && !player.InRangeUnOccluded(entity))
|
||||
if (entity.Deleted || !ignoreFov && !_examineSystem.CanExamine(player, entity))
|
||||
RemoveEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using Content.Shared.Input;
|
||||
using Content.Shared.Verbs;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
@@ -28,6 +29,7 @@ namespace Content.Client.Examine
|
||||
{
|
||||
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
|
||||
public const string StyleClassEntityTooltip = "entity-tooltip";
|
||||
|
||||
@@ -52,17 +54,8 @@ namespace Content.Client.Examine
|
||||
if (_examineTooltipOpen == null || !_examineTooltipOpen.Visible) return;
|
||||
if (_examinedEntity == null || _playerEntity == null) return;
|
||||
|
||||
Ignored predicate = entity => entity == _playerEntity || entity == _examinedEntity;
|
||||
|
||||
if (_playerEntity.TryGetContainer(out var container))
|
||||
{
|
||||
predicate += entity => entity == container.Owner;
|
||||
}
|
||||
|
||||
if (!InRangeUnOccluded(_playerEntity, _examinedEntity, ExamineRange, predicate))
|
||||
{
|
||||
if (!CanExamine(_playerEntity, _examinedEntity))
|
||||
CloseTooltip();
|
||||
}
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
@@ -71,6 +64,15 @@ namespace Content.Client.Examine
|
||||
base.Shutdown();
|
||||
}
|
||||
|
||||
public override bool CanExamine(IEntity examiner, MapCoordinates target, Ignored? predicate = null)
|
||||
{
|
||||
var b = _eyeManager.GetWorldViewbounds();
|
||||
if (!b.Contains(target.Position))
|
||||
return false;
|
||||
|
||||
return base.CanExamine(examiner, target, predicate);
|
||||
}
|
||||
|
||||
private bool HandleExamine(ICommonSession? session, EntityCoordinates coords, EntityUid uid)
|
||||
{
|
||||
if (!uid.IsValid() || !EntityManager.TryGetEntity(uid, out var entity))
|
||||
|
||||
@@ -3,22 +3,25 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Client.ContextMenu.UI;
|
||||
using Content.Client.Examine;
|
||||
using Content.Client.Popups;
|
||||
using Content.Client.Verbs.UI;
|
||||
using Content.Client.Viewport;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Interaction.Helpers;
|
||||
using Content.Shared.Tag;
|
||||
using Content.Shared.Verbs;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.State;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using static Content.Shared.Interaction.SharedInteractionSystem;
|
||||
|
||||
namespace Content.Client.Verbs
|
||||
{
|
||||
@@ -26,6 +29,8 @@ namespace Content.Client.Verbs
|
||||
public sealed class VerbSystem : SharedVerbSystem
|
||||
{
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly ExamineSystem _examineSystem = default!;
|
||||
[Dependency] private readonly IStateManager _stateManager = default!;
|
||||
[Dependency] private readonly IEntityLookup _entityLookup = default!;
|
||||
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||
|
||||
@@ -85,20 +90,28 @@ namespace Content.Client.Verbs
|
||||
public bool TryGetEntityMenuEntities(MapCoordinates targetPos, [NotNullWhen(true)] out List<IEntity>? result)
|
||||
{
|
||||
result = null;
|
||||
var player = _playerManager.LocalPlayer?.ControlledEntity;
|
||||
|
||||
if (_stateManager.CurrentState is not GameScreenBase gameScreenBase)
|
||||
return false;
|
||||
|
||||
var player = _playerManager.LocalPlayer?.ControlledEntity;
|
||||
if (player == null)
|
||||
return false;
|
||||
|
||||
// If FOV drawing is disabled, we will modify the visibility option to ignore visiblity checks.
|
||||
var visibility = _eyeManager.CurrentEye.DrawFov
|
||||
? Visibility
|
||||
: Visibility | MenuVisibility.NoFov;
|
||||
|
||||
// Check if we have LOS to the clicked-location.
|
||||
if ((visibility & MenuVisibility.NoFov) == 0 &&
|
||||
!player.InRangeUnOccluded(targetPos, range: ExamineSystemShared.ExamineRange))
|
||||
return false;
|
||||
|
||||
// Do we have to do FoV checks?
|
||||
if ((visibility & MenuVisibility.NoFov) == 0)
|
||||
{
|
||||
var entitiesUnderMouse = gameScreenBase.GetEntitiesUnderPosition(targetPos);
|
||||
Ignored? predicate = e => e == player || entitiesUnderMouse.Contains(e);
|
||||
if (!_examineSystem.CanExamine(player, targetPos, predicate))
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get entities
|
||||
var entities = _entityLookup.GetEntitiesInRange(targetPos.MapId, targetPos.Position, EntityMenuLookupSize)
|
||||
.ToList();
|
||||
|
||||
Reference in New Issue
Block a user