mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 05:27:38 +03:00
Removed all unused variables i could find, built and tested on a simple upstart and clicking trough most systems. Change Loc references to localization. <!-- This is default collapsed, readers click to expand it and see all your media The PR media section can get very large at times, so this is a good way to keep it clean The title is written using HTML tags The title must be within the <summary> tags or you won't see it --> <details><summary><h1>Media</h1></summary> <p> "using Robust.Shared.Prototypes;" to "" "[dependency] private readonly ISpriteComponent" to "" </p> </details> --- No CL this isn't player facing. --------- Co-authored-by: ilmenwe <no@mail.com>
108 lines
3.1 KiB
C#
108 lines
3.1 KiB
C#
using Content.Shared.Inventory;
|
|
using Content.Shared.Inventory.Events;
|
|
using Content.Shared.Overlays.Switchable;
|
|
using Robust.Client.Graphics;
|
|
|
|
namespace Content.Client.Overlays.Switchable;
|
|
|
|
public sealed class NightVisionSystem : EquipmentHudSystem<NightVisionComponent>
|
|
{
|
|
[Dependency] private readonly IOverlayManager _overlayMan = default!;
|
|
[Dependency] private readonly ILightManager _lightManager = default!;
|
|
|
|
private BaseSwitchableOverlay<NightVisionComponent> _overlay = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<NightVisionComponent, SwitchableOverlayToggledEvent>(OnToggle);
|
|
|
|
_overlay = new BaseSwitchableOverlay<NightVisionComponent>();
|
|
}
|
|
|
|
protected override void OnRefreshComponentHud(EntityUid uid,
|
|
NightVisionComponent component,
|
|
RefreshEquipmentHudEvent<NightVisionComponent> args)
|
|
{
|
|
if (component.IsEquipment)
|
|
return;
|
|
|
|
base.OnRefreshComponentHud(uid, component, args);
|
|
}
|
|
|
|
protected override void OnRefreshEquipmentHud(EntityUid uid,
|
|
NightVisionComponent component,
|
|
InventoryRelayedEvent<RefreshEquipmentHudEvent<NightVisionComponent>> args)
|
|
{
|
|
if (!component.IsEquipment)
|
|
return;
|
|
|
|
base.OnRefreshEquipmentHud(uid, component, args);
|
|
}
|
|
|
|
private void OnToggle(Entity<NightVisionComponent> ent, ref SwitchableOverlayToggledEvent args)
|
|
{
|
|
RefreshOverlay(args.User);
|
|
}
|
|
|
|
protected override void UpdateInternal(RefreshEquipmentHudEvent<NightVisionComponent> args)
|
|
{
|
|
base.UpdateInternal(args);
|
|
|
|
var active = false;
|
|
NightVisionComponent? nvComp = null;
|
|
foreach (var comp in args.Components)
|
|
{
|
|
if (comp.IsActive || comp.PulseTime > 0f && comp.PulseAccumulator < comp.PulseTime)
|
|
active = true;
|
|
else
|
|
continue;
|
|
if (comp.DrawOverlay)
|
|
{
|
|
if (nvComp == null)
|
|
nvComp = comp;
|
|
else if (nvComp.PulseTime > 0f && comp.PulseTime <= 0f)
|
|
nvComp = comp;
|
|
}
|
|
|
|
if (active && nvComp is { PulseTime: <= 0 })
|
|
break;
|
|
}
|
|
|
|
UpdateNightVision(active);
|
|
UpdateOverlay(nvComp);
|
|
}
|
|
|
|
protected override void DeactivateInternal()
|
|
{
|
|
base.DeactivateInternal();
|
|
|
|
UpdateNightVision(false);
|
|
UpdateOverlay(null);
|
|
}
|
|
|
|
private void UpdateNightVision(bool active)
|
|
{
|
|
_lightManager.DrawLighting = !active;
|
|
}
|
|
|
|
private void UpdateOverlay(NightVisionComponent? nvComp)
|
|
{
|
|
_overlay.Comp = nvComp;
|
|
|
|
switch (nvComp)
|
|
{
|
|
case not null when !_overlayMan.HasOverlay<BaseSwitchableOverlay<NightVisionComponent>>():
|
|
_overlayMan.AddOverlay(_overlay);
|
|
break;
|
|
case null:
|
|
_overlayMan.RemoveOverlay(_overlay);
|
|
break;
|
|
}
|
|
|
|
if (_overlayMan.TryGetOverlay<BaseSwitchableOverlay<ThermalVisionComponent>>(out var overlay))
|
|
overlay.IsActive = nvComp == null;
|
|
}
|
|
}
|