-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- ЭТО ШАБЛОН ВАШЕГО PULL REQUEST. Текст между стрелками - это комментарии - они не будут видны в PR. --> ## Описание PR <!-- Ниже опишите ваш Pull Request. Что он изменяет? На что еще это может повлиять? Постарайтесь описать все внесённые вами изменения! --> **Медиа** <!-- Если приемлемо, добавьте скриншоты для демонстрации вашего PR. Если ваш PR представляет собой визуальное изменение, добавьте скриншоты, иначе он может быть закрыт. --> **Проверки** <!-- Выполнение всех следующих действий, если это приемлемо для вида изменений сильно ускорит разбор вашего PR --> - [x] PR полностью завершён и мне не нужна помощь чтобы его закончить. - [x] Я внимательно просмотрел все свои изменения и багов в них не нашёл. - [x] Я запускал локальный сервер со своими изменениями и всё протестировал. - [ ] Я добавил скриншот/видео демонстрации PR в игре, **или** этот PR этого не требует. **Изменения** <!-- Здесь вы можете написать список изменений, который будет автоматически добавлен в игру, когда ваш PR будет принят. В журнал изменений следует помещать только то, что действительно важно игрокам. В списке изменений тип значка не является часть предложения, поэтому явно указывайте - Добавлен, Удалён, Изменён. плохо: - add: Новый инструмент для инженеров хорошо: - add: Добавлен новый инструмент для инженеров Вы можете указать своё имя после символа 🆑 именно оно будет отображаться в журнале изменений (иначе будет использоваться ваше имя на GitHub) Например: 🆑 Ian --> 🆑 - add: Добавлено ночное зрение визору ниндзя + сама система taken from https://github.com/RMC-14/RMC-14?ysclid=lzx00zxd6e53093995
- Loading branch information
1 parent
bf0d78a
commit 74d9298
Showing
11 changed files
with
546 additions
and
0 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
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; |
25 changes: 25 additions & 0 deletions
25
Content.Shared/ADT/NightVision/ADTNightVisionVisibleComponent.cs
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,25 @@ | ||
// taken and adapted from https://github.com/RMC-14/RMC-14?ysclid=lzx00zxd6e53093995 | ||
|
||
using Robust.Shared.GameStates; | ||
|
||
namespace Content.Shared.ADT.NightVision; | ||
|
||
/// <summary> | ||
/// For rendering sprites on top of FOV when the user has a <see cref="NightVisionComponent"/>. | ||
/// </summary> | ||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
public sealed partial class NightVisionVisibleComponent : Component | ||
{ | ||
/// <summary> | ||
/// Priority for rendering order. | ||
/// Rendered from lowest to highest, which means higher numbers will be rendered above lower numbers. | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public int Priority = 0; | ||
|
||
/// <summary> | ||
/// Transparency of the rendered sprite. | ||
/// </summary> | ||
[DataField, AutoNetworkedField] | ||
public float? Transparency = null; | ||
} |
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,36 @@ | ||
// taken and adapted from https://github.com/RMC-14/RMC-14?ysclid=lzx00zxd6e53093995 | ||
|
||
using Content.Shared.Alert; | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Prototypes; | ||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared.ADT.NightVision; | ||
|
||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)] | ||
[Access(typeof(SharedNightVisionSystem))] | ||
public sealed partial class NightVisionComponent : Component | ||
{ | ||
[DataField] | ||
public ProtoId<AlertPrototype>? Alert; | ||
|
||
[DataField, AutoNetworkedField] | ||
public NightVisionState State = NightVisionState.Full; | ||
|
||
[DataField, AutoNetworkedField] | ||
public bool Overlay; | ||
|
||
[DataField, AutoNetworkedField] | ||
public bool Innate; | ||
|
||
[DataField, AutoNetworkedField] | ||
public bool SeeThroughContainers; | ||
} | ||
|
||
[Serializable, NetSerializable] | ||
public enum NightVisionState | ||
{ | ||
Off, | ||
Half, | ||
Full | ||
} |
28 changes: 28 additions & 0 deletions
28
Content.Shared/ADT/NightVision/NightVisionItemComponent.cs
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,28 @@ | ||
// taken and adapted from https://github.com/RMC-14/RMC-14?ysclid=lzx00zxd6e53093995 | ||
|
||
using Content.Shared.Inventory; | ||
using Robust.Shared.GameStates; | ||
using Robust.Shared.Prototypes; | ||
|
||
namespace Content.Shared.ADT.NightVision; | ||
|
||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState] | ||
[Access(typeof(SharedNightVisionSystem))] | ||
public sealed partial class NightVisionItemComponent : Component | ||
{ | ||
[DataField, AutoNetworkedField] | ||
public EntProtoId ActionId = "ActionToggleNinjaNightVision"; | ||
|
||
[DataField, AutoNetworkedField] | ||
public EntityUid? Action; | ||
|
||
[DataField, AutoNetworkedField] | ||
public EntityUid? User; | ||
|
||
[DataField, AutoNetworkedField] | ||
public bool Toggleable = true; | ||
|
||
// Only allows for a single slotflag right now because some code uses strings and some code uses enums to determine slots :( | ||
[DataField, AutoNetworkedField] | ||
public SlotFlags SlotFlags { get; set; } = SlotFlags.EYES; | ||
} |
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,11 @@ | ||
// taken and adapted from https://github.com/RMC-14/RMC-14?ysclid=lzx00zxd6e53093995 | ||
|
||
using Robust.Shared.Serialization; | ||
|
||
namespace Content.Shared.ADT.NightVision; | ||
|
||
[Serializable, NetSerializable] | ||
public enum NightVisionItemVisuals | ||
{ | ||
Active, | ||
} |
Oops, something went wrong.