]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
make RefreshOverlay default to the player session (#32354)
authorMilon <milonpl.git@proton.me>
Thu, 30 Jan 2025 05:09:25 +0000 (06:09 +0100)
committerGitHub <noreply@github.com>
Thu, 30 Jan 2025 05:09:25 +0000 (16:09 +1100)
Content.Client/Overlays/EquipmentHudSystem.cs
Content.Client/Overlays/ShowHealthBarsSystem.cs
Content.Client/Overlays/ShowHealthIconsSystem.cs
Content.Shared/Inventory/Events/RefreshEquipmentHudEvent.cs
Content.Shared/Inventory/InventorySystem.Relay.cs

index 502a1f36274bd0dfb35fc980510dc673a975a698..f3c556961a550cbb6e912884775e2b5423189c13 100644 (file)
@@ -56,35 +56,35 @@ public abstract class EquipmentHudSystem<T> : EntitySystem where T : IComponent
 
     protected virtual void DeactivateInternal() { }
 
-    private void OnStartup(EntityUid uid, T component, ComponentStartup args)
+    private void OnStartup(Entity<T> ent, ref ComponentStartup args)
     {
-        RefreshOverlay(uid);
+        RefreshOverlay();
     }
 
-    private void OnRemove(EntityUid uid, T component, ComponentRemove args)
+    private void OnRemove(Entity<T> 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<T> ent, ref GotEquippedEvent args)
     {
-        RefreshOverlay(args.Equipee);
+        RefreshOverlay();
     }
 
-    private void OnCompUnequip(EntityUid uid, T component, GotUnequippedEvent args)
+    private void OnCompUnequip(Entity<T> ent, ref GotUnequippedEvent args)
     {
-        RefreshOverlay(args.Equipee);
+        RefreshOverlay();
     }
 
     private void OnRoundRestart(RoundRestartCleanupEvent args)
@@ -92,24 +92,24 @@ public abstract class EquipmentHudSystem<T> : EntitySystem where T : IComponent
         Deactivate();
     }
 
-    protected virtual void OnRefreshEquipmentHud(EntityUid uid, T component, InventoryRelayedEvent<RefreshEquipmentHudEvent<T>> args)
+    protected virtual void OnRefreshEquipmentHud(Entity<T> ent, ref InventoryRelayedEvent<RefreshEquipmentHudEvent<T>> args)
     {
-        OnRefreshComponentHud(uid, component, args.Args);
+        OnRefreshComponentHud(ent, ref args.Args);
     }
 
-    protected virtual void OnRefreshComponentHud(EntityUid uid, T component, RefreshEquipmentHudEvent<T> args)
+    protected virtual void OnRefreshComponentHud(Entity<T> ent, ref RefreshEquipmentHudEvent<T> 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<T>(TargetSlots);
-        RaiseLocalEvent(uid, ev);
+        RaiseLocalEvent(entity, ref ev);
 
         if (ev.Active)
             Update(ev);
index b23209ff202bab6fa6bc626f1cb0289369d3850b..9fefe93094efde524ca6ca8c20d346f65e862aab 100644 (file)
@@ -28,7 +28,7 @@ public sealed class ShowHealthBarsSystem : EquipmentHudSystem<ShowHealthBarsComp
 
     private void OnHandleState(Entity<ShowHealthBarsComponent> ent, ref AfterAutoHandleStateEvent args)
     {
-        RefreshOverlay(ent);
+        RefreshOverlay();
     }
 
     protected override void UpdateInternal(RefreshEquipmentHudEvent<ShowHealthBarsComponent> component)
index b4d845e4217ae66ac3fc7a8da641f36f75a3169a..3301261bd09e3931089160d64946c15e27242b34 100644 (file)
@@ -47,7 +47,7 @@ public sealed class ShowHealthIconsSystem : EquipmentHudSystem<ShowHealthIconsCo
 
     private void OnHandleState(Entity<ShowHealthIconsComponent> ent, ref AfterAutoHandleStateEvent args)
     {
-        RefreshOverlay(ent);
+        RefreshOverlay();
     }
 
     private void OnGetStatusIconsEvent(Entity<DamageableComponent> entity, ref GetStatusIconsEvent args)
index 4f486fe695e7b47cd9fab07319f1ddccd85e6b7d..e39fb056b4a5e1995378692f75a69d8794cc4c10 100644 (file)
@@ -1,13 +1,10 @@
 namespace Content.Shared.Inventory.Events;
 
-public sealed class RefreshEquipmentHudEvent<T> : EntityEventArgs, IInventoryRelayEvent where T : IComponent
+[ByRefEvent]
+public record struct RefreshEquipmentHudEvent<T>(SlotFlags TargetSlots) : IInventoryRelayEvent
+    where T : IComponent
 {
-    public SlotFlags TargetSlots { get; init; }
+    public SlotFlags TargetSlots { get; } = TargetSlots;
     public bool Active = false;
     public List<T> Components = new();
-
-    public RefreshEquipmentHudEvent(SlotFlags targetSlots)
-    {
-        TargetSlots = targetSlots;
-    }
 }
index d431195a816621ca2e13840b83d232bf01a6c41c..bb5dd02ab3d82b7d337f77a9cd16b14c30b87663 100644 (file)
@@ -55,14 +55,14 @@ public partial class InventorySystem
         SubscribeLocalEvent<InventoryComponent, SolutionScanEvent>(RelayInventoryEvent);
 
         // ComponentActivatedClientSystems
-        SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowJobIconsComponent>>(RelayInventoryEvent);
-        SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHealthBarsComponent>>(RelayInventoryEvent);
-        SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHealthIconsComponent>>(RelayInventoryEvent);
-        SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHungerIconsComponent>>(RelayInventoryEvent);
-        SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowThirstIconsComponent>>(RelayInventoryEvent);
-        SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowMindShieldIconsComponent>>(RelayInventoryEvent);
-        SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowSyndicateIconsComponent>>(RelayInventoryEvent);
-        SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowCriminalRecordIconsComponent>>(RelayInventoryEvent);
+        SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowJobIconsComponent>>(RefRelayInventoryEvent);
+        SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHealthBarsComponent>>(RefRelayInventoryEvent);
+        SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHealthIconsComponent>>(RefRelayInventoryEvent);
+        SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowHungerIconsComponent>>(RefRelayInventoryEvent);
+        SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowThirstIconsComponent>>(RefRelayInventoryEvent);
+        SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowMindShieldIconsComponent>>(RefRelayInventoryEvent);
+        SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowSyndicateIconsComponent>>(RefRelayInventoryEvent);
+        SubscribeLocalEvent<InventoryComponent, RefreshEquipmentHudEvent<ShowCriminalRecordIconsComponent>>(RefRelayInventoryEvent);
 
         SubscribeLocalEvent<InventoryComponent, GetVerbsEvent<EquipmentVerb>>(OnGetEquipmentVerbs);
     }