This commit is contained in:
slarticodefast
2024-11-22 23:02:59 +01:00
parent 5a9a2d463b
commit 08bfb43feb
8 changed files with 47 additions and 63 deletions

View File

@@ -6,96 +6,90 @@ using Robust.Shared.Player;
namespace Content.Client.Electrocution; namespace Content.Client.Electrocution;
/// <summary> /// <summary>
/// Shows the ElectrocutionOverlay to entities with the ElectrocutionOverlayComponent. /// Shows the Electrocution HUD to entities with the ShowElectrocutionHUDComponent.
/// </summary> /// </summary>
public sealed class ElectrocutionOverlaySystem : EntitySystem public sealed class ElectrifiedVisualizerSystem : VisualizerSystem<ElectrocutionHUDVisualsComponent>
{ {
[Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly IPlayerManager _playerMan = default!; [Dependency] private readonly IPlayerManager _playerMan = default!;
/// <inheritdoc/>
public override void Initialize() public override void Initialize()
{ {
SubscribeLocalEvent<ElectrocutionOverlayComponent, ComponentInit>(OnInit); base.Initialize();
SubscribeLocalEvent<ElectrocutionOverlayComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<ElectrocutionOverlayComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<ElectrocutionOverlayComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
SubscribeLocalEvent<ElectrifiedComponent, AppearanceChangeEvent>(OnAppearanceChange); SubscribeLocalEvent<ShowElectrocutionHUDComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<ShowElectrocutionHUDComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<ShowElectrocutionHUDComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<ShowElectrocutionHUDComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
} }
private void OnPlayerAttached(Entity<ElectrocutionOverlayComponent> ent, ref LocalPlayerAttachedEvent args) private void OnPlayerAttached(Entity<ShowElectrocutionHUDComponent> ent, ref LocalPlayerAttachedEvent args)
{ {
ShowOverlay(); ShowHUD();
} }
private void OnPlayerDetached(Entity<ElectrocutionOverlayComponent> ent, ref LocalPlayerDetachedEvent args) private void OnPlayerDetached(Entity<ShowElectrocutionHUDComponent> ent, ref LocalPlayerDetachedEvent args)
{ {
RemoveOverlay(); RemoveHUD();
} }
private void OnInit(Entity<ElectrocutionOverlayComponent> ent, ref ComponentInit args) private void OnInit(Entity<ShowElectrocutionHUDComponent> ent, ref ComponentInit args)
{ {
if (_playerMan.LocalEntity == ent) if (_playerMan.LocalEntity == ent)
{ {
ShowOverlay(); ShowHUD();
} }
} }
private void OnShutdown(Entity<ElectrocutionOverlayComponent> ent, ref ComponentShutdown args) private void OnShutdown(Entity<ShowElectrocutionHUDComponent> ent, ref ComponentShutdown args)
{ {
if (_playerMan.LocalEntity == ent) if (_playerMan.LocalEntity == ent)
{ {
RemoveOverlay(); RemoveHUD();
} }
} }
private void ShowOverlay() // Show the HUD to the client.
// We have to look for all current entities that can be electrified and toggle the HUD layer on if they are.
private void ShowHUD()
{ {
var electrifiedQuery = AllEntityQuery<ElectrifiedComponent, AppearanceComponent, SpriteComponent>(); var electrifiedQuery = AllEntityQuery<ElectrocutionHUDVisualsComponent, AppearanceComponent, SpriteComponent>();
while (electrifiedQuery.MoveNext(out var uid, out var _, out var appearanceComp, out var spriteComp)) while (electrifiedQuery.MoveNext(out var uid, out var _, out var appearanceComp, out var spriteComp))
{ {
if (!_appearance.TryGetData<bool>(uid, ElectrifiedVisuals.IsElectrified, out var electrified, appearanceComp)) if (!AppearanceSystem.TryGetData<bool>(uid, ElectrifiedVisuals.IsElectrified, out var electrified, appearanceComp))
continue;
if (!spriteComp.LayerMapTryGet(ElectrifiedLayers.Overlay, out var layer))
continue; continue;
if (electrified) if (electrified)
spriteComp.LayerSetVisible(ElectrifiedLayers.Overlay, true); spriteComp.LayerSetVisible(ElectrifiedLayers.HUD, true);
else else
spriteComp.LayerSetVisible(ElectrifiedLayers.Overlay, false); spriteComp.LayerSetVisible(ElectrifiedLayers.HUD, false);
} }
} }
private void RemoveOverlay() // Remove the HUD from the client.
// Find all current entities that can be electrified and hide the HUD layer.
private void RemoveHUD()
{ {
var electrifiedQuery = AllEntityQuery<ElectrifiedComponent, AppearanceComponent, SpriteComponent>(); var electrifiedQuery = AllEntityQuery<ElectrocutionHUDVisualsComponent, AppearanceComponent, SpriteComponent>();
while (electrifiedQuery.MoveNext(out var uid, out var _, out var appearanceComp, out var spriteComp)) while (electrifiedQuery.MoveNext(out var uid, out var _, out var appearanceComp, out var spriteComp))
{ {
if (!spriteComp.LayerMapTryGet(ElectrifiedLayers.Overlay, out var layer))
continue;
spriteComp.LayerSetVisible(layer, false); spriteComp.LayerSetVisible(ElectrifiedLayers.HUD, false);
} }
} }
private void OnAppearanceChange(Entity<ElectrifiedComponent> ent, ref AppearanceChangeEvent args) // Toggle the HUD layer if an entity becomes (de-)electrified
protected override void OnAppearanceChange(EntityUid uid, ElectrocutionHUDVisualsComponent comp, ref AppearanceChangeEvent args)
{ {
if (args.Sprite == null) if (args.Sprite == null)
return; return;
if (!_appearance.TryGetData<bool>(ent.Owner, ElectrifiedVisuals.IsElectrified, out var electrified, args.Component)) if (!AppearanceSystem.TryGetData<bool>(uid, ElectrifiedVisuals.IsElectrified, out var electrified, args.Component))
return;
if (!args.Sprite.LayerMapTryGet(ElectrifiedLayers.Overlay, out var layer))
return; return;
var player = _playerMan.LocalEntity; var player = _playerMan.LocalEntity;
if (electrified && HasComp<ElectrocutionOverlayComponent>(player)) if (electrified && HasComp<ShowElectrocutionHUDComponent>(player))
args.Sprite.LayerSetVisible(layer, true); args.Sprite.LayerSetVisible(ElectrifiedLayers.HUD, true);
else else
args.Sprite.LayerSetVisible(layer, false); args.Sprite.LayerSetVisible(ElectrifiedLayers.HUD, false);
} }
} }

View File

@@ -0,0 +1,7 @@
namespace Content.Shared.Electrocution;
/// <summary>
/// Handles toggling sprite layers for the electrocution HUD to show if an entity with the ElectrifiedComponent is electrified.
/// </summary>
[RegisterComponent]
public sealed partial class ElectrocutionHUDVisualsComponent : Component;

View File

@@ -3,7 +3,7 @@ using Robust.Shared.GameStates;
namespace Content.Shared.Electrocution; namespace Content.Shared.Electrocution;
/// <summary> /// <summary>
/// Allow an entity to see the ElectrocutionOverlay showing electrocuted doors. /// Allow an entity to see the Electrocution HUD showing electrocuted doors.
/// </summary> /// </summary>
[RegisterComponent, NetworkedComponent] [RegisterComponent, NetworkedComponent]
public sealed partial class ElectrocutionOverlayComponent : Component; public sealed partial class ShowElectrocutionHUDComponent : Component;

View File

@@ -6,7 +6,7 @@ namespace Content.Shared.Electrocution;
public enum ElectrifiedLayers : byte public enum ElectrifiedLayers : byte
{ {
Sparks, Sparks,
Overlay, HUD,
} }
[Serializable, NetSerializable] [Serializable, NetSerializable]

View File

@@ -55,7 +55,7 @@
skipChecks: true skipChecks: true
- type: Ghost - type: Ghost
- type: GhostHearing - type: GhostHearing
- type: ElectrocutionOverlay - type: ShowElectrocutionHUD
- type: IntrinsicRadioReceiver - type: IntrinsicRadioReceiver
- type: ActiveRadio - type: ActiveRadio
receiveAllChannels: true receiveAllChannels: true

View File

@@ -30,7 +30,7 @@
- type: IgnoreUIRange - type: IgnoreUIRange
- type: StationAiHeld - type: StationAiHeld
- type: StationAiOverlay - type: StationAiOverlay
- type: ElectrocutionOverlay - type: ShowElectrocutionHUD
- type: ActionGrant - type: ActionGrant
actions: actions:
- ActionJumpToCore - ActionJumpToCore

View File

@@ -35,7 +35,7 @@
sprite: Interface/Misc/ai_hud.rsi sprite: Interface/Misc/ai_hud.rsi
shader: unshaded shader: unshaded
visible: false visible: false
map: ["enum.ElectrifiedLayers.Overlay"] map: ["enum.ElectrifiedLayers.HUD"]
- type: AnimationPlayer - type: AnimationPlayer
- type: Physics - type: Physics
- type: Fixtures - type: Fixtures
@@ -78,6 +78,7 @@
- type: DoorBolt - type: DoorBolt
- type: Appearance - type: Appearance
- type: WiresVisuals - type: WiresVisuals
- type: ElectrocutionHUDVisuals
- type: ApcPowerReceiver - type: ApcPowerReceiver
powerLoad: 20 powerLoad: 20
- type: ExtensionCableReceiver - type: ExtensionCableReceiver

View File

@@ -30,24 +30,6 @@
hard: false hard: false
- type: Sprite - type: Sprite
sprite: Structures/Doors/Airlocks/Standard/shuttle.rsi sprite: Structures/Doors/Airlocks/Standard/shuttle.rsi
snapCardinals: false
layers:
- state: closed
map: ["enum.DoorVisualLayers.Base"]
- state: closed_unlit
shader: unshaded
map: ["enum.DoorVisualLayers.BaseUnlit"]
visible: false
- state: welded
map: ["enum.WeldableLayers.BaseWelded"]
- state: bolted_unlit
shader: unshaded
map: ["enum.DoorVisualLayers.BaseBolted"]
- state: emergency_unlit
shader: unshaded
map: ["enum.DoorVisualLayers.BaseEmergencyAccess"]
- state: panel_open
map: ["enum.WiresVisualLayers.MaintenancePanel"]
- type: Wires - type: Wires
layoutId: Docking layoutId: Docking
- type: Door - type: Door