Merge remote-tracking branch 'upstream/master' into UPS
This commit is contained in:
@@ -7,7 +7,8 @@ using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Client._White.Overlays;
|
||||
|
||||
public sealed class NightVisionSystem : SharedNightVisionSystem
|
||||
public sealed class NightVisionSystem : SharedEnhancedVisionSystem<NightVisionComponent, TemporaryNightVisionComponent,
|
||||
ToggleNightVisionEvent>
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _player = default!;
|
||||
[Dependency] private readonly IOverlayManager _overlayMan = default!;
|
||||
@@ -46,12 +47,12 @@ public sealed class NightVisionSystem : SharedNightVisionSystem
|
||||
if (TryComp(ent, out NightVisionComponent? nightVision) && nightVision.IsActive)
|
||||
return;
|
||||
|
||||
UpdateNightVision(ent, false);
|
||||
UpdateEnhancedVision(ent, false);
|
||||
}
|
||||
|
||||
private void OnTempInit(Entity<TemporaryNightVisionComponent> ent, ref ComponentInit args)
|
||||
{
|
||||
UpdateNightVision(ent, true);
|
||||
UpdateEnhancedVision(ent, true);
|
||||
}
|
||||
|
||||
private void OnPlayerAttached(EntityUid uid, NightVisionComponent component, PlayerAttachedEvent args)
|
||||
@@ -76,7 +77,7 @@ public sealed class NightVisionSystem : SharedNightVisionSystem
|
||||
UpdateNightVision(active);
|
||||
}
|
||||
|
||||
protected override void UpdateNightVision(EntityUid uid, bool active)
|
||||
protected override void UpdateEnhancedVision(EntityUid uid, bool active)
|
||||
{
|
||||
if (_player.LocalSession?.AttachedEntity != uid)
|
||||
return;
|
||||
|
||||
@@ -22,6 +22,7 @@ public sealed class ThermalVisionOverlay : Overlay
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpace;
|
||||
|
||||
private readonly List<NightVisionRenderEntry> _entries = new();
|
||||
private EntityUid _pointLightEntity;
|
||||
|
||||
public ThermalVisionOverlay()
|
||||
{
|
||||
@@ -46,23 +47,50 @@ public sealed class ThermalVisionOverlay : Overlay
|
||||
return;
|
||||
}
|
||||
|
||||
var transform = _entity.GetComponent<TransformComponent>(ent);
|
||||
if (_pointLightEntity == default)
|
||||
{
|
||||
_pointLightEntity = _entity.SpawnAttachedTo(null, transform.Coordinates);
|
||||
_entity.EnsureComponent<PointLightComponent>(_pointLightEntity);
|
||||
_transform.SetParent(_pointLightEntity, ent);
|
||||
}
|
||||
else
|
||||
{
|
||||
var pointLightXForm = _entity.GetComponent<TransformComponent>(_pointLightEntity);
|
||||
if (pointLightXForm.ParentUid != ent)
|
||||
_transform.SetParent(_pointLightEntity, pointLightXForm, ent, transform);
|
||||
}
|
||||
|
||||
if (HasOccluders(ent))
|
||||
return;
|
||||
|
||||
var handle = args.WorldHandle;
|
||||
var eye = args.Viewport.Eye;
|
||||
var mapId = eye?.Position.MapId;
|
||||
var eyeRot = eye?.Rotation ?? default;
|
||||
|
||||
_entries.Clear();
|
||||
var entities = _entity.EntityQueryEnumerator<BodyComponent, SpriteComponent, TransformComponent>();
|
||||
while (entities.MoveNext(out var uid, out _, out var sprite, out var xform))
|
||||
{
|
||||
if (HasOccluders(uid))
|
||||
var entity = uid;
|
||||
|
||||
if (_container.TryGetOuterContainer(uid, xform, out var container))
|
||||
{
|
||||
var owner = container.Owner;
|
||||
if (_entity.TryGetComponent<SpriteComponent>(owner, out var ownerSprite) &&
|
||||
_entity.TryGetComponent<TransformComponent>(owner, out var ownerXform))
|
||||
{
|
||||
entity = owner;
|
||||
sprite = ownerSprite;
|
||||
xform = ownerXform;
|
||||
}
|
||||
}
|
||||
|
||||
if (_entries.Any(e => e.Ent.Item1 == entity))
|
||||
continue;
|
||||
|
||||
_entries.Add(new NightVisionRenderEntry((uid, sprite, xform),
|
||||
eye?.Position.MapId,
|
||||
eyeRot));
|
||||
_entries.Add(new NightVisionRenderEntry((entity, sprite, xform), mapId, eyeRot));
|
||||
}
|
||||
|
||||
foreach (var entry in _entries)
|
||||
@@ -79,7 +107,7 @@ public sealed class ThermalVisionOverlay : Overlay
|
||||
Angle eyeRot)
|
||||
{
|
||||
var (uid, sprite, xform) = ent;
|
||||
if (xform.MapID != map || _container.IsEntityOrParentInContainer(uid))
|
||||
if (xform.MapID != map || HasOccluders(uid))
|
||||
return;
|
||||
|
||||
var position = _transform.GetWorldPosition(xform);
|
||||
@@ -95,6 +123,15 @@ public sealed class ThermalVisionOverlay : Overlay
|
||||
Box2.CenteredAround(mapCoordinates.Position, new Vector2(0.4f, 0.4f)));
|
||||
return occluders.Any(o => o.Component.Enabled);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
if (_pointLightEntity == default)
|
||||
return;
|
||||
|
||||
_entity.DeleteEntity(_pointLightEntity);
|
||||
_pointLightEntity = default;
|
||||
}
|
||||
}
|
||||
|
||||
public record struct NightVisionRenderEntry(
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
using Content.Shared._Miracle.Systems;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared._White.Overlays;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Client._White.Overlays;
|
||||
|
||||
public sealed class ThermalVisionSystem : SharedThermalVisionSystem
|
||||
public sealed class ThermalVisionSystem : SharedEnhancedVisionSystem<ThermalVisionComponent,
|
||||
TemporaryThermalVisionComponent, ToggleThermalVisionEvent>
|
||||
{
|
||||
[Dependency] private readonly IPlayerManager _player = default!;
|
||||
[Dependency] private readonly IOverlayManager _overlayMan = default!;
|
||||
@@ -46,12 +48,12 @@ public sealed class ThermalVisionSystem : SharedThermalVisionSystem
|
||||
if (TryComp(ent, out ThermalVisionComponent? thermalVision) && thermalVision.IsActive)
|
||||
return;
|
||||
|
||||
UpdateThermalVision(ent, false);
|
||||
UpdateEnhancedVision(ent, false);
|
||||
}
|
||||
|
||||
private void OnTempInit(Entity<TemporaryThermalVisionComponent> ent, ref ComponentInit args)
|
||||
{
|
||||
UpdateThermalVision(ent, true);
|
||||
UpdateEnhancedVision(ent, true);
|
||||
}
|
||||
|
||||
private void OnPlayerAttached(EntityUid uid, ThermalVisionComponent component, PlayerAttachedEvent args)
|
||||
@@ -76,7 +78,7 @@ public sealed class ThermalVisionSystem : SharedThermalVisionSystem
|
||||
UpdateThermalVision(active);
|
||||
}
|
||||
|
||||
protected override void UpdateThermalVision(EntityUid uid, bool active)
|
||||
protected override void UpdateEnhancedVision(EntityUid uid, bool active)
|
||||
{
|
||||
if (_player.LocalSession?.AttachedEntity != uid)
|
||||
return;
|
||||
@@ -89,6 +91,7 @@ public sealed class ThermalVisionSystem : SharedThermalVisionSystem
|
||||
{
|
||||
if (_player.LocalEntity == null)
|
||||
{
|
||||
_overlay.Reset();
|
||||
_overlayMan.RemoveOverlay(_overlay);
|
||||
return;
|
||||
}
|
||||
@@ -99,11 +102,15 @@ public sealed class ThermalVisionSystem : SharedThermalVisionSystem
|
||||
if (active)
|
||||
_overlayMan.AddOverlay(_overlay);
|
||||
else
|
||||
{
|
||||
_overlay.Reset();
|
||||
_overlayMan.RemoveOverlay(_overlay);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRestart(RoundRestartCleanupEvent ev)
|
||||
{
|
||||
_overlay.Reset();
|
||||
_overlayMan.RemoveOverlay(_overlay);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user