Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NVG (Port From _LostParadise) #1128

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Content.Client/IoC/ClientContentIoC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Content.Client.Replay;
using Content.Shared.Administration.Managers;
using Content.Shared.Players.PlayTimeTracking;
using Content.Client._LostParadise.Clothing; // _LostParadise
BL02DL marked this conversation as resolved.
Show resolved Hide resolved


namespace Content.Client.IoC
Expand Down Expand Up @@ -54,6 +55,7 @@ public static void Register()
collection.Register<ISharedPlaytimeManager, JobRequirementsManager>();
IoCManager.Register<JoinQueueManager>();
IoCManager.Register<DiscordAuthManager>();
IoCManager.Register<NightVisionEntitySystem>(); // _LostParadise
BL02DL marked this conversation as resolved.
Show resolved Hide resolved
BL02DL marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
54 changes: 54 additions & 0 deletions Content.Client/_LostParadise/Clothing/NightVisionOverlay.cs
BL02DL marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;

namespace Content.Client._LostParadise.Clothing;

/// <summary>
/// Made by BL02DL from _LostParadise
/// </summary>

public sealed class NightVisionOverlay : Overlay
{
private readonly IPrototypeManager _prototypeManager;
private readonly NightVisionEntitySystem _nightVisionEntitySystem;

public override bool RequestScreenTexture => true;
public override OverlaySpace Space => OverlaySpace.WorldSpace;

private readonly ShaderInstance _shader;

public NightVisionOverlay()
{
IoCManager.InjectDependencies(this);
_nightVisionEntitySystem = IoCManager.Resolve<NightVisionEntitySystem>();
_prototypeManager = IoCManager.Resolve<IPrototypeManager>();
_shader = _prototypeManager.Index<ShaderPrototype>("LPPNightVision").InstanceUnique();
}
BL02DL marked this conversation as resolved.
Show resolved Hide resolved

protected override void Draw(in OverlayDrawArgs args)
{
if (ScreenTexture == null)
return;

var handle = args.WorldHandle;
var nightcomp = _nightVisionEntitySystem.GetNightComp();

// Получение данных об оверлее Ночного Видения
BL02DL marked this conversation as resolved.
Show resolved Hide resolved
if (nightcomp == null)
{
Logger.Error("Failed to get night vision component from eyes.");
return;
}

_shader.SetParameter("SCREEN_TEXTURE", ScreenTexture);
_shader.SetParameter("tint", nightcomp.Tint);
_shader.SetParameter("luminance_threshold", nightcomp.Strength);
_shader.SetParameter("noise_amount", nightcomp.Noise);

handle.UseShader(_shader);
handle.DrawRect(args.WorldBounds, Color.White);
handle.UseShader(null);
}
}
91 changes: 91 additions & 0 deletions Content.Client/_LostParadise/Clothing/NightVisionSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using Content.Shared._LostParadise.Clothing;
using Content.Shared.GameTicking;
using Robust.Client.Player;
using Robust.Client.Graphics;
using Content.Client.Inventory;
using Content.Shared.Inventory.Events;

namespace Content.Client._LostParadise.Clothing;
BL02DL marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Made by BL02DL from _LostParadise
/// </summary>

public sealed class NightVisionSystem : SharedNightVisionSystem
{
[Dependency] private readonly IOverlayManager _overlayMan = default!;
[Dependency] private readonly ILightManager _lightManager = default!;

private NightVisionOverlay _overlay = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRestart);
SubscribeLocalEvent<NightVisionComponent, GotUnequippedEvent>(OnGotUnequipped);

_overlay = new();
BL02DL marked this conversation as resolved.
Show resolved Hide resolved
}

protected override void UpdateNightVisionEffects(EntityUid parent, EntityUid uid, bool state, NightVisionComponent? component)
BL02DL marked this conversation as resolved.
Show resolved Hide resolved
{
if (!Resolve(uid, ref component))
{
return;
}
BL02DL marked this conversation as resolved.
Show resolved Hide resolved

state = state && component.On;

if (state)
{
_lightManager.DrawLighting = false;

/// Adding an overlay when the effect is activated
/// Добавление наложения при активированном эффекте
BL02DL marked this conversation as resolved.
Show resolved Hide resolved
_overlayMan.AddOverlay(_overlay);
}
else
{
_lightManager.DrawLighting = true;

/// Removing an overlay when the effect is deactivated
/// Удаление наложения при деактивированном эффекте
BL02DL marked this conversation as resolved.
Show resolved Hide resolved
_overlayMan.RemoveOverlay(_overlay);
}
}
private void OnGotUnequipped(EntityUid uid, NightVisionComponent component, GotUnequippedEvent args)
{
if (args.Slot == "eyes")
{
UpdateNightVisionEffects(args.Equipee, uid, false, component);
_overlayMan.RemoveOverlay(_overlay);
_lightManager.DrawLighting = true;
BL02DL marked this conversation as resolved.
Show resolved Hide resolved
}
}
private void OnRestart(RoundRestartCleanupEvent ev)
{
/// Удаляем оверлей и врубаем свет на всякий по окончанию раунда
/// We remove the overlay and turn on the light just in case at the end of the round.
_overlayMan.RemoveOverlay(_overlay);
_lightManager.DrawLighting = true;
}
}

public sealed class NightVisionEntitySystem : EntitySystem
{
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
public override void Initialize()
{
base.Initialize();
}

public NightVisionComponent? GetNightComp()
{
var playerUid = EntityUid.Parse(_playerManager.LocalPlayer?.ControlledEntity.ToString());
var slot = _entityManager.GetComponent<InventorySlotsComponent>(playerUid);
_entityManager.TryGetComponent<NightVisionComponent>(slot.SlotData["eyes"].HeldEntity, out var nightvision);
return nightvision;
}
}
BL02DL marked this conversation as resolved.
Show resolved Hide resolved
56 changes: 56 additions & 0 deletions Content.Server/_LostParadise/Clothing/NightVisionSystem.cs
BL02DL marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Content.Shared._LostParadise.Clothing;
using Content.Shared.Alert;
using Content.Shared.Inventory.Events;

namespace Content.Server._LostParadise.Clothing;
BL02DL marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Made by BL02DL from _LostParadise
/// </summary>

public sealed class NightVisionSystem : SharedNightVisionSystem
{
[Dependency] private readonly AlertsSystem _alertsSystem = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<NightVisionComponent, GotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<NightVisionComponent, GotUnequippedEvent>(OnGotUnequipped);

}
BL02DL marked this conversation as resolved.
Show resolved Hide resolved

protected override void UpdateNightVisionEffects(EntityUid parent, EntityUid uid, bool state, NightVisionComponent? component)
{
if (!Resolve(uid, ref component))
return;
state = state && component.On;

if (state)
{
_alertsSystem.ShowAlert(parent, AlertType.LPPNightVision);
}
else
{
_alertsSystem.ClearAlert(parent, AlertType.LPPNightVision);
}
BL02DL marked this conversation as resolved.
Show resolved Hide resolved
}

private void OnGotUnequipped(EntityUid uid, NightVisionComponent component, GotUnequippedEvent args)
{
if (args.Slot == "eyes")
{
UpdateNightVisionEffects(args.Equipee, uid, false, component);
_alertsSystem.ClearAlert(uid, AlertType.LPPNightVision);
BL02DL marked this conversation as resolved.
Show resolved Hide resolved
}
}

private void OnGotEquipped(EntityUid uid, NightVisionComponent component, GotEquippedEvent args)
{
if (args.Slot == "eyes")
{
UpdateNightVisionEffects(args.Equipee, uid, true, component);
}
}
}
7 changes: 7 additions & 0 deletions Content.Shared/Alert/AlertType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public enum AlertType : byte
Pulled,
Pulling,
Magboots,

// Start _LostParadise

LPPNightVision,

// End _LostParadise

BL02DL marked this conversation as resolved.
Show resolved Hide resolved
Internals,
Toxins,
Muted,
Expand Down
49 changes: 49 additions & 0 deletions Content.Shared/_LostParadise/Clothing/NightVisionComponent.cs
BL02DL marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;

namespace Content.Shared._LostParadise.Clothing;
BL02DL marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Made by BL02DL from _LostParadise
/// </summary>

[RegisterComponent, NetworkedComponent(), AutoGenerateComponentState]
[Access(typeof(SharedNightVisionSystem))]
public sealed partial class NightVisionComponent : Component
{
[DataField]
public EntProtoId ToggleAction = "LPPActionToggleNightVision";

[DataField, AutoNetworkedField]
public EntityUid? ToggleActionEntity;

[DataField("on"), AutoNetworkedField]
public bool On;
BL02DL marked this conversation as resolved.
Show resolved Hide resolved

[DataField("tint1"), ViewVariables(VVAccess.ReadWrite)]
public float Tint1 { get; set; } = 0.3f;

[DataField("tint2"), ViewVariables(VVAccess.ReadWrite)]
public float Tint2 { get; set; } = 0.3f;

[DataField("tint3"), ViewVariables(VVAccess.ReadWrite)]
public float Tint3 { get; set; } = 0.3f;

[DataField("tint"), ViewVariables(VVAccess.ReadWrite)]
public Vector3 Tint
{
get => new(Tint1, Tint2, Tint3);
set
{
Tint1 = value.X;
Tint2 = value.Y;
Tint3 = value.Z;
}
}
BL02DL marked this conversation as resolved.
Show resolved Hide resolved

[DataField("strength"), ViewVariables(VVAccess.ReadWrite)]
public float Strength = 2f;

[DataField("noise"), ViewVariables(VVAccess.ReadWrite)]
public float Noise = 0.5f;
}
94 changes: 94 additions & 0 deletions Content.Shared/_LostParadise/Clothing/SharedNightVisionSystem.cs
BL02DL marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
using Content.Shared.Actions;
using Content.Shared.Clothing.EntitySystems;
using Content.Shared.Inventory;
using Content.Shared.Item;
using Content.Shared.Toggleable;
using Content.Shared.Verbs;
using Robust.Shared.Containers;

namespace Content.Shared._LostParadise.Clothing;
BL02DL marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Made by BL02DL from _LostParadise
/// </summary>

public abstract class SharedNightVisionSystem : EntitySystem
{
[Dependency] private readonly ClothingSystem _clothing = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly SharedActionsSystem _sharedActions = default!;
[Dependency] private readonly SharedActionsSystem _actionContainer = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedContainerSystem _sharedContainer = default!;
[Dependency] private readonly SharedItemSystem _item = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<NightVisionComponent, GetVerbsEvent<ActivationVerb>>(AddToggleVerb);
SubscribeLocalEvent<NightVisionComponent, GetItemActionsEvent>(OnGetActions);
SubscribeLocalEvent<NightVisionComponent, ToggleNightVisionEvent>(OnToggleNightVision);
SubscribeLocalEvent<NightVisionComponent, MapInitEvent>(OnMapInit);
}

private void OnMapInit(EntityUid uid, NightVisionComponent component, MapInitEvent args)
{
_actionContainer.AddAction(uid, ref component.ToggleActionEntity, component.ToggleAction);
Dirty(uid, component);
}

private void OnToggleNightVision(EntityUid uid, NightVisionComponent component, ToggleNightVisionEvent args)
{
if (args.Handled)
return;

args.Handled = true;

ToggleNightVision(uid, component);
}

private void ToggleNightVision(EntityUid uid, NightVisionComponent nightvision)
{
nightvision.On = !nightvision.On;

if (_sharedContainer.TryGetContainingContainer(uid, out var container) &&
_inventory.TryGetSlotEntity(container.Owner, "eyes", out var entityUid) && entityUid == uid)
UpdateNightVisionEffects(container.Owner, uid, true, nightvision);

if (TryComp<ItemComponent>(uid, out var item))
{
_item.SetHeldPrefix(uid, nightvision.On ? "on" : null, component: item);
_clothing.SetEquippedPrefix(uid, nightvision.On ? "on" : null);
}

_appearance.SetData(uid, ToggleVisuals.Toggled, nightvision.On);
OnChanged(uid, nightvision);
Dirty(uid, nightvision);
}

protected virtual void UpdateNightVisionEffects(EntityUid parent, EntityUid uid, bool state, NightVisionComponent? component) { }

protected void OnChanged(EntityUid uid, NightVisionComponent component)
{
_sharedActions.SetToggled(component.ToggleActionEntity, component.On);
}

private void AddToggleVerb(EntityUid uid, NightVisionComponent component, GetVerbsEvent<ActivationVerb> args)
{
if (!args.CanAccess || !args.CanInteract)
return;

ActivationVerb verb = new();
verb.Text = Loc.GetString("lpp-toggle-nightvision-verb-get-data-text");
verb.Act = () => ToggleNightVision(uid, component);
args.Verbs.Add(verb);
}

private void OnGetActions(EntityUid uid, NightVisionComponent component, GetItemActionsEvent args)
{
args.AddAction(ref component.ToggleActionEntity, component.ToggleAction);
}
}

public sealed partial class ToggleNightVisionEvent : InstantActionEvent {}
Loading
Loading