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

Fix Night Vision #1554

Merged
merged 5 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion Content.Client/Overlays/EquipmentHudSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ private void OnRoundRestart(RoundRestartCleanupEvent args)

protected virtual void OnRefreshEquipmentHud(EntityUid uid, T component, InventoryRelayedEvent<RefreshEquipmentHudEvent<T>> args)
{
OnRefreshComponentHud(uid, component, args.Args);
args.Args.Active = true;
args.Args.Components.Add(component);
}

protected virtual void OnRefreshComponentHud(EntityUid uid, T component, RefreshEquipmentHudEvent<T> args)
Expand Down
21 changes: 21 additions & 0 deletions Content.Client/Overlays/Switchable/NightVisionSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
using Content.Shared.Overlays.Switchable;
using Robust.Client.Graphics;
Expand All @@ -20,6 +21,26 @@ public override void Initialize()
_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);
Expand Down
4 changes: 2 additions & 2 deletions Content.Client/Overlays/Switchable/ThermalVisionOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ private bool CanSee(EntityUid uid, SpriteComponent sprite)
_stealth.GetVisibility(uid, stealth) > 0.5f);
}

public void ResetLight()
public void ResetLight(bool checkFirstTimePredicted = true)
{
if (_lightEntity == null || !_timing.IsFirstTimePredicted)
if (_lightEntity == null || checkFirstTimePredicted && !_timing.IsFirstTimePredicted)
return;

_entity.DeleteEntity(_lightEntity);
Expand Down
22 changes: 22 additions & 0 deletions Content.Client/Overlays/Switchable/ThermalVisionSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
using Content.Shared.Overlays.Switchable;
using Robust.Client.Graphics;
Expand All @@ -21,6 +22,26 @@ public override void Initialize()
_overlay = new BaseSwitchableOverlay<ThermalVisionComponent>();
}

protected override void OnRefreshComponentHud(EntityUid uid,
ThermalVisionComponent component,
RefreshEquipmentHudEvent<ThermalVisionComponent> args)
{
if (component.IsEquipment)
return;

base.OnRefreshComponentHud(uid, component, args);
}

protected override void OnRefreshEquipmentHud(EntityUid uid,
ThermalVisionComponent component,
InventoryRelayedEvent<RefreshEquipmentHudEvent<ThermalVisionComponent>> args)
{
if (!component.IsEquipment)
return;

base.OnRefreshEquipmentHud(uid, component, args);
}

private void OnToggle(Entity<ThermalVisionComponent> ent, ref SwitchableOverlayToggledEvent args)
{
RefreshOverlay(args.User);
Expand Down Expand Up @@ -54,6 +75,7 @@ protected override void DeactivateInternal()
{
base.DeactivateInternal();

_thermalOverlay.ResetLight(false);
UpdateOverlay(null);
UpdateThermalOverlay(null, 0f);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public abstract partial class SwitchableOverlayComponent : BaseOverlayComponent
[DataField]
public bool DrawOverlay = true;

/// <summary>
/// Whether it should grant equipment enhanced vision or is it mob vision
/// </summary>
[DataField]
public bool IsEquipment;

/// <summary>
/// If it is greater than 0, overlay isn't toggled but pulsed instead
/// </summary>
Expand Down
12 changes: 8 additions & 4 deletions Content.Shared/Overlays/Switchable/SwitchableOverlaySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,22 @@ private void OnHandleState(EntityUid uid, TComp component, ref ComponentHandleSt

component.IsActive = state.IsActive;

RaiseSwitchableOverlayToggledEvent(uid, uid, component.IsActive);
RaiseSwitchableOverlayToggledEvent(uid, Transform(uid).ParentUid, component.IsActive);
RaiseSwitchableOverlayToggledEvent(uid,
component.IsEquipment ? Transform(uid).ParentUid : uid,
component.IsActive);
}

private void OnGetItemActions(Entity<TComp> ent, ref GetItemActionsEvent args)
{
if (ent.Comp.ToggleAction != null && args.SlotFlags is not SlotFlags.POCKET and not null)
if (ent.Comp.IsEquipment && ent.Comp.ToggleAction != null && args.SlotFlags is not SlotFlags.POCKET and not null)
args.AddAction(ref ent.Comp.ToggleActionEntity, ent.Comp.ToggleAction);
}

private void OnShutdown(EntityUid uid, TComp component, ComponentShutdown args)
{
if (component.IsEquipment)
return;

_actions.RemoveAction(uid, component.ToggleActionEntity);
}

Expand All @@ -124,7 +128,7 @@ private void OnInit(EntityUid uid, TComp component, ComponentInit args)

private void OnMapInit(EntityUid uid, TComp component, MapInitEvent args)
{
if (component.ToggleActionEntity == null && component.ToggleAction != null)
if (component is { IsEquipment: false, ToggleActionEntity: null, ToggleAction: not null })
_actions.AddAction(uid, ref component.ToggleActionEntity, component.ToggleAction);
}

Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Clothing/Eyes/glasses.yml
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@
sprite: Clothing/Eyes/Glasses/ninjavisor.rsi
- type: FlashImmunity
- type: NightVision
isEquipment: true

- type: entity #Fake goggles, the latest in anti-valid hunting technology
parent: ClothingEyesBase
Expand Down
2 changes: 2 additions & 0 deletions Resources/Prototypes/Entities/Clothing/Eyes/goggles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- type: Clothing
sprite: Clothing/Eyes/Goggles/nightvision.rsi
- type: NightVision
isEquipment: true
- type: IdentityBlocker
coverage: EYES

Expand Down Expand Up @@ -77,6 +78,7 @@
- type: Clothing
sprite: Clothing/Eyes/Goggles/thermal.rsi
- type: ThermalVision
isEquipment: true
pulseTime: 2
toggleAction: PulseThermalVision
- type: IdentityBlocker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@
Radiation: 0.80
Caustic: 0.95
- type: ThermalVision
isEquipment: true
color: "#98EEFB"
lightRadius: 15

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
- type: EyeProtection
- type: NightVision
isActive: true
isEquipment: true
toggleAction: null
activateSound: null
deactivateSound: null
Expand Down
Loading