Files
wwdpublic/Content.Client/Overlays/Switchable/ThermalVisionSystem.cs
Remuchi 4c8c415eed [Fix] Парад фиксов (#1110)
* fix: thermals and night vision now work

* fix: it has to be this way

Signed-off-by: Remuchi <RemuchiOfficial@gmail.com>

* fix: I hate the way they are separated

* fix: now cult actions close examine menu (#1046)

Signed-off-by: Remuchi <RemuchiOfficial@gmail.com>

* fix: railins and some other things now dont snap to south upon being built (#1029)

* fix: who did this translation wtf

* fix: assball bat can now wideswing (#1030)

Signed-off-by: Remuchi <RemuchiOfficial@gmail.com>

* fix: spend flares are actually spent now (#959)

Signed-off-by: Remuchi <RemuchiOfficial@gmail.com>

* fix: made part exchange system a bit less shitty

I really have no time or interest in it to rewrite it completely rn

Signed-off-by: Remuchi <RemuchiOfficial@gmail.com>

* fix: fixed cult factories timers being broken

Also fixed them being openable by anyone.

Signed-off-by: Remuchi <RemuchiOfficial@gmail.com>

* Apply suggestions from code review

Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com>
Co-authored-by: RedFoxIV <38788538+RedFoxIV@users.noreply.github.com>

---------

Signed-off-by: Remuchi <RemuchiOfficial@gmail.com>
Co-authored-by: Spatison <137375981+Spatison@users.noreply.github.com>
Co-authored-by: RedFoxIV <38788538+RedFoxIV@users.noreply.github.com>
2026-04-16 10:53:08 +03:00

79 lines
2.4 KiB
C#

using Content.Shared.Inventory.Events;
using Content.Shared.Overlays.Switchable;
using Robust.Client.Graphics;
using Robust.Shared.Timing;
namespace Content.Client.Overlays.Switchable;
public sealed class ThermalVisionSystem : EquipmentHudSystem<ThermalVisionComponent>
{
[Dependency] private readonly IOverlayManager _overlayMan = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
private ThermalVisionOverlay _thermalOverlay = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ThermalVisionComponent, SwitchableOverlayToggledEvent>(OnToggle);
_thermalOverlay = new();
}
private void OnToggle(Entity<ThermalVisionComponent> ent, ref SwitchableOverlayToggledEvent args)
{
if (_gameTiming.IsFirstTimePredicted)
RefreshOverlay();
}
protected override void UpdateInternal(RefreshEquipmentHudEvent<ThermalVisionComponent> args)
{
base.UpdateInternal(args);
ThermalVisionComponent? tvComp = null;
var lightRadius = 0f;
foreach (var comp in args.Components)
{
if (!comp.IsActive && (comp.PulseTime <= 0f || comp.PulseAccumulator >= comp.PulseTime))
continue;
if (tvComp == null)
tvComp = comp;
else if (!tvComp.DrawOverlay && comp.DrawOverlay)
tvComp = comp;
else if (tvComp.DrawOverlay == comp.DrawOverlay && tvComp.PulseTime > 0f && comp.PulseTime <= 0f)
tvComp = comp;
lightRadius = MathF.Max(lightRadius, comp.LightRadius);
}
UpdateThermalOverlay(tvComp, lightRadius);
}
protected override void DeactivateInternal()
{
base.DeactivateInternal();
_thermalOverlay.ResetLight(false);
UpdateThermalOverlay(null, 0f);
}
private void UpdateThermalOverlay(ThermalVisionComponent? comp, float lightRadius)
{
_thermalOverlay.LightRadius = lightRadius;
_thermalOverlay.Comp = comp;
switch (comp)
{
case not null when !_overlayMan.HasOverlay<ThermalVisionOverlay>():
_overlayMan.AddOverlay(_thermalOverlay);
break;
case null:
_overlayMan.RemoveOverlay(_thermalOverlay);
_thermalOverlay.ResetLight();
break;
}
}
}