Misc stealth and box changes (#11809)
* git mv * Disable shader while box is open * Hide entity menu / prevent examine * fix recursion fix recursion fix recursion fix recursion * Better visibility checks * min and max visibility fields * fix reference point
This commit is contained in:
@@ -7,6 +7,7 @@ using Content.Client.Verbs;
|
||||
using Content.Client.Viewport;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.CombatMode;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Input;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
@@ -20,6 +21,7 @@ using Robust.Shared.Input;
|
||||
using Robust.Shared.Input.Binding;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
@@ -47,6 +49,7 @@ namespace Content.Client.ContextMenu.UI
|
||||
|
||||
private readonly VerbSystem _verbSystem;
|
||||
private readonly ExamineSystem _examineSystem;
|
||||
private readonly TransformSystem _xform;
|
||||
private readonly SharedCombatModeSystem _combatMode;
|
||||
|
||||
/// <summary>
|
||||
@@ -64,6 +67,7 @@ namespace Content.Client.ContextMenu.UI
|
||||
_verbSystem = verbSystem;
|
||||
_examineSystem = _entityManager.EntitySysManager.GetEntitySystem<ExamineSystem>();
|
||||
_combatMode = _entityManager.EntitySysManager.GetEntitySystem<CombatModeSystem>();
|
||||
_xform = _entityManager.EntitySysManager.GetEntitySystem<TransformSystem>();
|
||||
|
||||
_cfg.OnValueChanged(CCVars.EntityMenuGroupingType, OnGroupingChanged, true);
|
||||
|
||||
@@ -191,9 +195,24 @@ namespace Content.Client.ContextMenu.UI
|
||||
var ignoreFov = !_eyeManager.CurrentEye.DrawFov ||
|
||||
(_verbSystem.Visibility & MenuVisibility.NoFov) == MenuVisibility.NoFov;
|
||||
|
||||
_entityManager.TryGetComponent(player, out ExaminerComponent? examiner);
|
||||
var xformQuery = _entityManager.GetEntityQuery<TransformComponent>();
|
||||
|
||||
foreach (var entity in Elements.Keys.ToList())
|
||||
{
|
||||
if (_entityManager.Deleted(entity) || !ignoreFov && !_examineSystem.CanExamine(player, entity))
|
||||
if (!xformQuery.TryGetComponent(entity, out var xform))
|
||||
{
|
||||
// entity was deleted
|
||||
RemoveEntity(entity);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ignoreFov)
|
||||
continue;
|
||||
|
||||
var pos = new MapCoordinates(_xform.GetWorldPosition(xform, xformQuery), xform.MapID);
|
||||
|
||||
if (!_examineSystem.CanExamine(player, pos, e => e == player || e == entity, entity, examiner))
|
||||
RemoveEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,13 +63,23 @@ namespace Content.Client.Examine
|
||||
base.Shutdown();
|
||||
}
|
||||
|
||||
public override bool CanExamine(EntityUid examiner, MapCoordinates target, Ignored? predicate = null)
|
||||
public override bool CanExamine(EntityUid examiner, MapCoordinates target, Ignored? predicate = null, EntityUid? examined = null, ExaminerComponent? examinerComp = null)
|
||||
{
|
||||
var b = _eyeManager.GetWorldViewbounds();
|
||||
if (!b.Contains(target.Position))
|
||||
if (!Resolve(examiner, ref examinerComp, false))
|
||||
return false;
|
||||
|
||||
return base.CanExamine(examiner, target, predicate);
|
||||
if (examinerComp.SkipChecks)
|
||||
return true;
|
||||
|
||||
if (examinerComp.CheckInRangeUnOccluded)
|
||||
{
|
||||
// TODO fix this. This should be using the examiner's eye component, not eye manager.
|
||||
var b = _eyeManager.GetWorldViewbounds();
|
||||
if (!b.Contains(target.Position))
|
||||
return false;
|
||||
}
|
||||
|
||||
return base.CanExamine(examiner, target, predicate, examined, examinerComp);
|
||||
}
|
||||
|
||||
private bool HandleExamine(in PointerInputCmdHandler.PointerInputCmdArgs args)
|
||||
|
||||
@@ -22,35 +22,48 @@ public sealed class StealthSystem : SharedStealthSystem
|
||||
SubscribeLocalEvent<StealthComponent, BeforePostShaderRenderEvent>(OnShaderRender);
|
||||
}
|
||||
|
||||
protected override void OnInit(EntityUid uid, StealthComponent component, ComponentInit args)
|
||||
public override void SetEnabled(EntityUid uid, bool value, StealthComponent? component = null)
|
||||
{
|
||||
base.OnInit(uid, component, args);
|
||||
if (!TryComp(uid, out SpriteComponent? sprite))
|
||||
if (!Resolve(uid, ref component) || component.Enabled == value)
|
||||
return;
|
||||
|
||||
sprite.PostShader = _shader;
|
||||
sprite.GetScreenTexture = true;
|
||||
sprite.RaiseShaderEvent = true;
|
||||
base.SetEnabled(uid, value, component);
|
||||
SetShader(uid, value, component);
|
||||
}
|
||||
|
||||
private void SetShader(EntityUid uid, bool enabled, StealthComponent? component = null, SpriteComponent? sprite = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, ref sprite, false))
|
||||
return;
|
||||
|
||||
sprite.Color = Color.White;
|
||||
sprite.PostShader = enabled ? _shader : null;
|
||||
sprite.GetScreenTexture = enabled;
|
||||
sprite.RaiseShaderEvent = enabled;
|
||||
|
||||
if (!enabled)
|
||||
{
|
||||
if (component.HadOutline)
|
||||
AddComp<InteractionOutlineComponent>(uid);
|
||||
return;
|
||||
}
|
||||
|
||||
if (TryComp(uid, out InteractionOutlineComponent? outline))
|
||||
{
|
||||
RemComp(uid, outline);
|
||||
RemCompDeferred(uid, outline);
|
||||
component.HadOutline = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnInit(EntityUid uid, StealthComponent component, ComponentInit args)
|
||||
{
|
||||
base.OnInit(uid, component, args);
|
||||
SetShader(uid, component.Enabled, component);
|
||||
}
|
||||
|
||||
private void OnRemove(EntityUid uid, StealthComponent component, ComponentRemove args)
|
||||
{
|
||||
if (!TryComp(uid, out SpriteComponent? sprite))
|
||||
return;
|
||||
|
||||
sprite.PostShader = null;
|
||||
sprite.GetScreenTexture = false;
|
||||
sprite.RaiseShaderEvent = false;
|
||||
sprite.Color = Color.White;
|
||||
|
||||
if (component.HadOutline)
|
||||
AddComp<InteractionOutlineComponent>(uid);
|
||||
SetShader(uid, false, component);
|
||||
}
|
||||
|
||||
private void OnShaderRender(EntityUid uid, StealthComponent component, BeforePostShaderRenderEvent args)
|
||||
@@ -61,9 +74,17 @@ public sealed class StealthSystem : SharedStealthSystem
|
||||
// So we need to use relative screen coordinates. The reference frame we use is the parent's position on screen.
|
||||
// this ensures that if the Stealth is not moving relative to the parent, its relative screen position remains
|
||||
// unchanged.
|
||||
var parentXform = Transform(Transform(uid).ParentUid);
|
||||
var parent = Transform(uid).ParentUid;
|
||||
if (!parent.IsValid())
|
||||
return; // should never happen, but lets not kill the client.
|
||||
var parentXform = Transform(parent);
|
||||
var reference = args.Viewport.WorldToLocal(parentXform.WorldPosition);
|
||||
reference.X = -reference.X;
|
||||
var visibility = GetVisibility(uid, component);
|
||||
|
||||
// actual visual visibility effect is limited to +/- 1.
|
||||
visibility = Math.Clamp(visibility, -1f, 1f);
|
||||
|
||||
_shader.SetParameter("reference", reference);
|
||||
_shader.SetParameter("visibility", visibility);
|
||||
|
||||
|
||||
@@ -108,18 +108,34 @@ namespace Content.Client.Verbs
|
||||
? Visibility
|
||||
: Visibility | MenuVisibility.NoFov;
|
||||
|
||||
|
||||
// Get entities
|
||||
List<EntityUid> entities;
|
||||
|
||||
// Do we have to do FoV checks?
|
||||
if ((visibility & MenuVisibility.NoFov) == 0)
|
||||
{
|
||||
var entitiesUnderMouse = gameScreenBase.GetEntitiesUnderPosition(targetPos);
|
||||
bool Predicate(EntityUid e) => e == player || entitiesUnderMouse.Contains(e);
|
||||
|
||||
// first check the general location.
|
||||
if (!_examineSystem.CanExamine(player.Value, targetPos, Predicate))
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get entities
|
||||
var entities = _entityLookup.GetEntitiesInRange(targetPos, EntityMenuLookupSize)
|
||||
.ToList();
|
||||
TryComp(player.Value, out ExaminerComponent? examiner);
|
||||
|
||||
// Then check every entity
|
||||
entities = new();
|
||||
foreach (var ent in _entityLookup.GetEntitiesInRange(targetPos, EntityMenuLookupSize))
|
||||
{
|
||||
if (_examineSystem.CanExamine(player.Value, targetPos, Predicate, ent, examiner))
|
||||
entities.Add(ent);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
entities = _entityLookup.GetEntitiesInRange(targetPos, EntityMenuLookupSize).ToList();
|
||||
}
|
||||
|
||||
if (entities.Count == 0)
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user