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;
/// <summary>
/// Shows the ElectrocutionOverlay to entities with the ElectrocutionOverlayComponent.
/// Shows the Electrocution HUD to entities with the ShowElectrocutionHUDComponent.
/// </summary>
public sealed class ElectrocutionOverlaySystem : EntitySystem
public sealed class ElectrifiedVisualizerSystem : VisualizerSystem<ElectrocutionHUDVisualsComponent>
{
[Dependency] private readonly AppearanceSystem _appearance = default!;
[Dependency] private readonly IPlayerManager _playerMan = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<ElectrocutionOverlayComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<ElectrocutionOverlayComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<ElectrocutionOverlayComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<ElectrocutionOverlayComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
base.Initialize();
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)
{
ShowOverlay();
ShowHUD();
}
}
private void OnShutdown(Entity<ElectrocutionOverlayComponent> ent, ref ComponentShutdown args)
private void OnShutdown(Entity<ShowElectrocutionHUDComponent> ent, ref ComponentShutdown args)
{
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))
{
if (!_appearance.TryGetData<bool>(uid, ElectrifiedVisuals.IsElectrified, out var electrified, appearanceComp))
continue;
if (!spriteComp.LayerMapTryGet(ElectrifiedLayers.Overlay, out var layer))
if (!AppearanceSystem.TryGetData<bool>(uid, ElectrifiedVisuals.IsElectrified, out var electrified, appearanceComp))
continue;
if (electrified)
spriteComp.LayerSetVisible(ElectrifiedLayers.Overlay, true);
spriteComp.LayerSetVisible(ElectrifiedLayers.HUD, true);
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))
{
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)
return;
if (!_appearance.TryGetData<bool>(ent.Owner, ElectrifiedVisuals.IsElectrified, out var electrified, args.Component))
return;
if (!args.Sprite.LayerMapTryGet(ElectrifiedLayers.Overlay, out var layer))
if (!AppearanceSystem.TryGetData<bool>(uid, ElectrifiedVisuals.IsElectrified, out var electrified, args.Component))
return;
var player = _playerMan.LocalEntity;
if (electrified && HasComp<ElectrocutionOverlayComponent>(player))
args.Sprite.LayerSetVisible(layer, true);
if (electrified && HasComp<ShowElectrocutionHUDComponent>(player))
args.Sprite.LayerSetVisible(ElectrifiedLayers.HUD, true);
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;
/// <summary>
/// Allow an entity to see the ElectrocutionOverlay showing electrocuted doors.
/// Allow an entity to see the Electrocution HUD showing electrocuted doors.
/// </summary>
[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
{
Sparks,
Overlay,
HUD,
}
[Serializable, NetSerializable]

View File

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

View File

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

View File

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

View File

@@ -30,24 +30,6 @@
hard: false
- type: Sprite
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
layoutId: Docking
- type: Door