-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into deletesomething
- Loading branch information
Showing
78 changed files
with
1,162 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// taken and adapted from https://github.com/RMC-14/RMC-14?ysclid=lzx00zxd6e53093995 | ||
|
||
using System.Numerics; | ||
using Content.Shared.ADT.NightVision; | ||
// using Content.Shared._RMC14.Xenonids; | ||
using Robust.Client.GameObjects; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Enums; | ||
using Robust.Shared.Map; | ||
|
||
namespace Content.Client.ADT.NightVision; | ||
|
||
public sealed class NightVisionOverlay : Overlay | ||
{ | ||
[Dependency] private readonly IEntityManager _entity = default!; | ||
[Dependency] private readonly IPlayerManager _players = default!; | ||
|
||
private readonly ContainerSystem _container; | ||
private readonly TransformSystem _transform; | ||
// private readonly EntityQuery<XenoComponent> _xenoQuery; | ||
|
||
public override OverlaySpace Space => OverlaySpace.WorldSpace; | ||
|
||
private readonly List<NightVisionRenderEntry> _entries = new(); | ||
|
||
public NightVisionOverlay() | ||
{ | ||
IoCManager.InjectDependencies(this); | ||
|
||
_container = _entity.System<ContainerSystem>(); | ||
_transform = _entity.System<TransformSystem>(); | ||
// _xenoQuery = _entity.GetEntityQuery<XenoComponent>(); | ||
} | ||
|
||
protected override void Draw(in OverlayDrawArgs args) | ||
{ | ||
if (!_entity.TryGetComponent(_players.LocalEntity, out NightVisionComponent? nightVision) || | ||
nightVision.State == NightVisionState.Off) | ||
{ | ||
return; | ||
} | ||
|
||
var handle = args.WorldHandle; | ||
var eye = args.Viewport.Eye; | ||
var eyeRot = eye?.Rotation ?? default; | ||
|
||
_entries.Clear(); | ||
var entities = _entity.EntityQueryEnumerator<NightVisionVisibleComponent, SpriteComponent, TransformComponent>(); | ||
while (entities.MoveNext(out var uid, out var visible, out var sprite, out var xform)) | ||
{ | ||
_entries.Add(new NightVisionRenderEntry((uid, sprite, xform), | ||
eye?.Position.MapId, | ||
eyeRot, | ||
nightVision.SeeThroughContainers, | ||
visible.Priority, | ||
visible.Transparency)); | ||
} | ||
|
||
_entries.Sort(SortPriority); | ||
|
||
foreach (var entry in _entries) | ||
{ | ||
Render(entry.Ent, | ||
entry.Map, | ||
handle, | ||
entry.EyeRot, | ||
entry.NightVisionSeeThroughContainers, | ||
entry.Transparency); | ||
} | ||
|
||
handle.SetTransform(Matrix3x2.Identity); | ||
} | ||
|
||
private static int SortPriority(NightVisionRenderEntry x, NightVisionRenderEntry y) | ||
{ | ||
return x.Priority.CompareTo(y.Priority); | ||
} | ||
|
||
private void Render(Entity<SpriteComponent, TransformComponent> ent, | ||
MapId? map, | ||
DrawingHandleWorld handle, | ||
Angle eyeRot, | ||
bool seeThroughContainers, | ||
float? transparency) | ||
{ | ||
var (uid, sprite, xform) = ent; | ||
if (xform.MapID != map) | ||
return; | ||
|
||
var seeThrough = seeThroughContainers; // && !_xenoQuery.HasComp(uid); | ||
if (!seeThrough && _container.IsEntityOrParentInContainer(uid, xform: xform)) | ||
return; | ||
|
||
var (position, rotation) = _transform.GetWorldPositionRotation(xform); | ||
|
||
var colorCache = sprite.Color; | ||
if (transparency != null) | ||
{ | ||
var color = sprite.Color * Color.White.WithAlpha(transparency.Value); | ||
sprite.Color = color; | ||
} | ||
sprite.Render(handle, eyeRot, rotation, position: position); | ||
if (transparency != null) | ||
{ | ||
sprite.Color = colorCache; | ||
} | ||
} | ||
} | ||
|
||
public record struct NightVisionRenderEntry( | ||
(EntityUid, SpriteComponent, TransformComponent) Ent, | ||
MapId? Map, | ||
Angle EyeRot, | ||
bool NightVisionSeeThroughContainers, | ||
int Priority, | ||
float? Transparency); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// taken and adapted from https://github.com/RMC-14/RMC-14?ysclid=lzx00zxd6e53093995 | ||
|
||
using Content.Shared.ADT.NightVision; | ||
using Robust.Client.Graphics; | ||
using Robust.Client.Player; | ||
using Robust.Shared.Player; | ||
|
||
namespace Content.Client.ADT.NightVision; | ||
|
||
public sealed class NightVisionSystem : SharedNightVisionSystem | ||
{ | ||
[Dependency] private readonly ILightManager _light = default!; | ||
[Dependency] private readonly IOverlayManager _overlay = default!; | ||
[Dependency] private readonly IPlayerManager _player = default!; | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<NightVisionComponent, LocalPlayerAttachedEvent>(OnNightVisionAttached); | ||
SubscribeLocalEvent<NightVisionComponent, LocalPlayerDetachedEvent>(OnNightVisionDetached); | ||
} | ||
|
||
private void OnNightVisionAttached(Entity<NightVisionComponent> ent, ref LocalPlayerAttachedEvent args) | ||
{ | ||
NightVisionChanged(ent); | ||
} | ||
|
||
private void OnNightVisionDetached(Entity<NightVisionComponent> ent, ref LocalPlayerDetachedEvent args) | ||
{ | ||
Off(); | ||
} | ||
|
||
protected override void NightVisionChanged(Entity<NightVisionComponent> ent) | ||
{ | ||
if (ent != _player.LocalEntity) | ||
return; | ||
|
||
switch (ent.Comp.State) | ||
{ | ||
case NightVisionState.Off: | ||
Off(); | ||
break; | ||
case NightVisionState.Half: | ||
Half(ent); | ||
break; | ||
case NightVisionState.Full: | ||
Full(ent); | ||
break; | ||
default: | ||
throw new ArgumentOutOfRangeException(); | ||
} | ||
} | ||
|
||
protected override void NightVisionRemoved(Entity<NightVisionComponent> ent) | ||
{ | ||
if (ent != _player.LocalEntity) | ||
return; | ||
|
||
Off(); | ||
} | ||
|
||
private void Off() | ||
{ | ||
_overlay.RemoveOverlay(new NightVisionOverlay()); | ||
_light.DrawLighting = true; | ||
} | ||
|
||
private void Half(Entity<NightVisionComponent> ent) | ||
{ | ||
if (ent.Comp.Overlay) | ||
_overlay.AddOverlay(new NightVisionOverlay()); | ||
|
||
_light.DrawLighting = true; | ||
} | ||
|
||
private void Full(Entity<NightVisionComponent> ent) | ||
{ | ||
if (ent.Comp.Overlay) | ||
_overlay.AddOverlay(new NightVisionOverlay()); | ||
|
||
_light.DrawLighting = false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// taken and adapted from https://github.com/RMC-14/RMC-14?ysclid=lzx00zxd6e53093995 | ||
|
||
using Content.Shared.ADT.NightVision; | ||
|
||
namespace Content.Server.ADT.NightVision; | ||
|
||
public sealed class NightVisionSystem : SharedNightVisionSystem; |
Oops, something went wrong.