mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* Mobs NightVision * update * Update Content.Client/Overlays/NightVisionOverlaySystem.cs Co-authored-by: Perry Fraser <perryprog@users.noreply.github.com> * Update Content.Shared/Overlays/NightVisionComponent.cs Co-authored-by: Perry Fraser <perryprog@users.noreply.github.com> * Update Content.Shared/Overlays/NightVisionComponent.cs Co-authored-by: Perry Fraser <perryprog@users.noreply.github.com> * Update Resources/Textures/Shaders/nightvision.swsl Co-authored-by: Perry Fraser <perryprog@users.noreply.github.com> * update * update * Update nightvision.swsl * 123 * refactoring * Update NightVisionOverlaySystem.cs * cleaning * imagine * cleaning cleaning * fix --------- Co-authored-by: Perry Fraser <perryprog@users.noreply.github.com> Co-authored-by: Pok245 <113675512+Pok27@users.noreply.github.com> Co-authored-by: ScarKy0 <scarky0@onet.eu>
70 lines
2 KiB
C#
70 lines
2 KiB
C#
using Content.Shared.Inventory.Events;
|
|
using Content.Shared.Overlays;
|
|
using Robust.Client.Graphics;
|
|
|
|
namespace Content.Client.Overlays;
|
|
|
|
/// <summary>
|
|
/// Shows/hides the <see cref="NightVisionOverlay"/> based on whether the observed
|
|
/// entity has a <see cref="NightVisionComponent"/> equipped.
|
|
/// </summary>
|
|
public sealed partial class NightVisionOverlaySystem : EquipmentHudSystem<NightVisionComponent>
|
|
{
|
|
[Dependency] private IOverlayManager _overlayMan = default!;
|
|
|
|
private NightVisionOverlay _overlay = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
_overlay = new NightVisionOverlay();
|
|
|
|
SubscribeLocalEvent<NightVisionComponent, AfterAutoHandleStateEvent>(OnHandleState);
|
|
}
|
|
|
|
protected override void UpdateInternal(RefreshEquipmentHudEvent<NightVisionComponent> component)
|
|
{
|
|
base.UpdateInternal(component);
|
|
|
|
// Find the component with the lowest noise.
|
|
NightVisionComponent? nvision = null;
|
|
var bestNoise = float.MaxValue;
|
|
foreach (var comp in component.Components)
|
|
{
|
|
if (!comp.Enabled)
|
|
continue;
|
|
|
|
var noise = comp.NoiseAmount * comp.NoiseMultiplier;
|
|
if (noise < bestNoise)
|
|
{
|
|
nvision = comp;
|
|
bestNoise = noise;
|
|
}
|
|
}
|
|
|
|
// There is no active night vision components, so we disable the overlay.
|
|
if (nvision == null)
|
|
{
|
|
DeactivateInternal();
|
|
return;
|
|
}
|
|
|
|
_overlay.SetParameters(nvision.OverlayColor, nvision.LightingColor, nvision.NoiseAmount, nvision.NoiseMultiplier);
|
|
|
|
if (!_overlayMan.HasOverlay<NightVisionOverlay>())
|
|
_overlayMan.AddOverlay(_overlay);
|
|
}
|
|
|
|
protected override void DeactivateInternal()
|
|
{
|
|
base.DeactivateInternal();
|
|
|
|
_overlayMan.RemoveOverlay(_overlay);
|
|
}
|
|
|
|
private void OnHandleState(Entity<NightVisionComponent> ent, ref AfterAutoHandleStateEvent args)
|
|
{
|
|
RefreshOverlay();
|
|
}
|
|
}
|