From 3a51f11cb2468978a363cd7112ad8e4fe85c3f2e Mon Sep 17 00:00:00 2001 From: Milon Date: Thu, 30 Jan 2025 06:09:25 +0100 Subject: [PATCH] make RefreshOverlay default to the player session (#32354) --- Content.Client/Overlays/EquipmentHudSystem.cs | 34 +++++++++---------- .../Overlays/ShowHealthBarsSystem.cs | 2 +- .../Overlays/ShowHealthIconsSystem.cs | 2 +- .../Events/RefreshEquipmentHudEvent.cs | 11 +++--- .../Inventory/InventorySystem.Relay.cs | 16 ++++----- 5 files changed, 31 insertions(+), 34 deletions(-) diff --git a/Content.Client/Overlays/EquipmentHudSystem.cs b/Content.Client/Overlays/EquipmentHudSystem.cs index 502a1f3627..f3c556961a 100644 --- a/Content.Client/Overlays/EquipmentHudSystem.cs +++ b/Content.Client/Overlays/EquipmentHudSystem.cs @@ -56,35 +56,35 @@ public abstract class EquipmentHudSystem : EntitySystem where T : IComponent protected virtual void DeactivateInternal() { } - private void OnStartup(EntityUid uid, T component, ComponentStartup args) + private void OnStartup(Entity ent, ref ComponentStartup args) { - RefreshOverlay(uid); + RefreshOverlay(); } - private void OnRemove(EntityUid uid, T component, ComponentRemove args) + private void OnRemove(Entity ent, ref ComponentRemove args) { - RefreshOverlay(uid); + RefreshOverlay(); } private void OnPlayerAttached(LocalPlayerAttachedEvent args) { - RefreshOverlay(args.Entity); + RefreshOverlay(); } private void OnPlayerDetached(LocalPlayerDetachedEvent args) { - if (_player.LocalSession?.AttachedEntity == null) + if (_player.LocalSession?.AttachedEntity is null) Deactivate(); } - private void OnCompEquip(EntityUid uid, T component, GotEquippedEvent args) + private void OnCompEquip(Entity ent, ref GotEquippedEvent args) { - RefreshOverlay(args.Equipee); + RefreshOverlay(); } - private void OnCompUnequip(EntityUid uid, T component, GotUnequippedEvent args) + private void OnCompUnequip(Entity ent, ref GotUnequippedEvent args) { - RefreshOverlay(args.Equipee); + RefreshOverlay(); } private void OnRoundRestart(RoundRestartCleanupEvent args) @@ -92,24 +92,24 @@ public abstract class EquipmentHudSystem : EntitySystem where T : IComponent Deactivate(); } - protected virtual void OnRefreshEquipmentHud(EntityUid uid, T component, InventoryRelayedEvent> args) + protected virtual void OnRefreshEquipmentHud(Entity ent, ref InventoryRelayedEvent> args) { - OnRefreshComponentHud(uid, component, args.Args); + OnRefreshComponentHud(ent, ref args.Args); } - protected virtual void OnRefreshComponentHud(EntityUid uid, T component, RefreshEquipmentHudEvent args) + protected virtual void OnRefreshComponentHud(Entity ent, ref RefreshEquipmentHudEvent args) { args.Active = true; - args.Components.Add(component); + args.Components.Add(ent.Comp); } - protected void RefreshOverlay(EntityUid uid) + protected void RefreshOverlay() { - if (uid != _player.LocalSession?.AttachedEntity) + if (_player.LocalSession?.AttachedEntity is not { } entity) return; var ev = new RefreshEquipmentHudEvent(TargetSlots); - RaiseLocalEvent(uid, ev); + RaiseLocalEvent(entity, ref ev); if (ev.Active) Update(ev); diff --git a/Content.Client/Overlays/ShowHealthBarsSystem.cs b/Content.Client/Overlays/ShowHealthBarsSystem.cs index b23209ff20..9fefe93094 100644 --- a/Content.Client/Overlays/ShowHealthBarsSystem.cs +++ b/Content.Client/Overlays/ShowHealthBarsSystem.cs @@ -28,7 +28,7 @@ public sealed class ShowHealthBarsSystem : EquipmentHudSystem ent, ref AfterAutoHandleStateEvent args) { - RefreshOverlay(ent); + RefreshOverlay(); } protected override void UpdateInternal(RefreshEquipmentHudEvent component) diff --git a/Content.Client/Overlays/ShowHealthIconsSystem.cs b/Content.Client/Overlays/ShowHealthIconsSystem.cs index b4d845e421..3301261bd0 100644 --- a/Content.Client/Overlays/ShowHealthIconsSystem.cs +++ b/Content.Client/Overlays/ShowHealthIconsSystem.cs @@ -47,7 +47,7 @@ public sealed class ShowHealthIconsSystem : EquipmentHudSystem ent, ref AfterAutoHandleStateEvent args) { - RefreshOverlay(ent); + RefreshOverlay(); } private void OnGetStatusIconsEvent(Entity entity, ref GetStatusIconsEvent args) diff --git a/Content.Shared/Inventory/Events/RefreshEquipmentHudEvent.cs b/Content.Shared/Inventory/Events/RefreshEquipmentHudEvent.cs index 4f486fe695..e39fb056b4 100644 --- a/Content.Shared/Inventory/Events/RefreshEquipmentHudEvent.cs +++ b/Content.Shared/Inventory/Events/RefreshEquipmentHudEvent.cs @@ -1,13 +1,10 @@ namespace Content.Shared.Inventory.Events; -public sealed class RefreshEquipmentHudEvent : EntityEventArgs, IInventoryRelayEvent where T : IComponent +[ByRefEvent] +public record struct RefreshEquipmentHudEvent(SlotFlags TargetSlots) : IInventoryRelayEvent + where T : IComponent { - public SlotFlags TargetSlots { get; init; } + public SlotFlags TargetSlots { get; } = TargetSlots; public bool Active = false; public List Components = new(); - - public RefreshEquipmentHudEvent(SlotFlags targetSlots) - { - TargetSlots = targetSlots; - } } diff --git a/Content.Shared/Inventory/InventorySystem.Relay.cs b/Content.Shared/Inventory/InventorySystem.Relay.cs index d431195a81..bb5dd02ab3 100644 --- a/Content.Shared/Inventory/InventorySystem.Relay.cs +++ b/Content.Shared/Inventory/InventorySystem.Relay.cs @@ -55,14 +55,14 @@ public partial class InventorySystem SubscribeLocalEvent(RelayInventoryEvent); // ComponentActivatedClientSystems - SubscribeLocalEvent>(RelayInventoryEvent); - SubscribeLocalEvent>(RelayInventoryEvent); - SubscribeLocalEvent>(RelayInventoryEvent); - SubscribeLocalEvent>(RelayInventoryEvent); - SubscribeLocalEvent>(RelayInventoryEvent); - SubscribeLocalEvent>(RelayInventoryEvent); - SubscribeLocalEvent>(RelayInventoryEvent); - SubscribeLocalEvent>(RelayInventoryEvent); + SubscribeLocalEvent>(RefRelayInventoryEvent); + SubscribeLocalEvent>(RefRelayInventoryEvent); + SubscribeLocalEvent>(RefRelayInventoryEvent); + SubscribeLocalEvent>(RefRelayInventoryEvent); + SubscribeLocalEvent>(RefRelayInventoryEvent); + SubscribeLocalEvent>(RefRelayInventoryEvent); + SubscribeLocalEvent>(RefRelayInventoryEvent); + SubscribeLocalEvent>(RefRelayInventoryEvent); SubscribeLocalEvent>(OnGetEquipmentVerbs); }