]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Use item status extension method (#23884)
authorPieter-Jan Briers <pieterjan.briers+git@gmail.com>
Fri, 12 Jan 2024 00:14:13 +0000 (01:14 +0100)
committerGitHub <noreply@github.com>
Fri, 12 Jan 2024 00:14:13 +0000 (19:14 -0500)
Just removes some lines of code.

Content.Client/Chemistry/EntitySystems/InjectorSystem.cs
Content.Client/Crayon/CrayonSystem.cs
Content.Client/Fluids/AbsorbentSystem.cs
Content.Client/GPS/Systems/HandheldGpsSystem.cs
Content.Client/Implants/ImplanterSystem.cs
Content.Client/Items/ItemStatusMessages.cs
Content.Client/Light/HandheldLightSystem.cs
Content.Client/NetworkConfigurator/Systems/NetworkConfiguratorSystem.cs
Content.Client/Radiation/Systems/GeigerSystem.cs
Content.Client/Stack/StackSystem.cs
Content.Client/Tools/ToolSystem.cs

index eeca31220f73732dded2db488345694cdf26848f..896349a161420a6d539b8c3444089314ec3f03df 100644 (file)
@@ -12,9 +12,9 @@ public sealed class InjectorSystem : EntitySystem
     {
         base.Initialize();
         SubscribeLocalEvent<InjectorComponent, ComponentHandleState>(OnHandleInjectorState);
-        SubscribeLocalEvent<InjectorComponent, ItemStatusCollectMessage>(OnItemInjectorStatus);
+        Subs.ItemStatus<InjectorComponent>(ent => new InjectorStatusControl(ent));
         SubscribeLocalEvent<HyposprayComponent, ComponentHandleState>(OnHandleHyposprayState);
-        SubscribeLocalEvent<HyposprayComponent, ItemStatusCollectMessage>(OnItemHyposprayStatus);
+        Subs.ItemStatus<HyposprayComponent>(ent => new HyposprayStatusControl(ent));
     }
 
     private void OnHandleInjectorState(EntityUid uid, InjectorComponent component, ref ComponentHandleState args)
@@ -30,11 +30,6 @@ public sealed class InjectorSystem : EntitySystem
         component.UiUpdateNeeded = true;
     }
 
-    private void OnItemInjectorStatus(EntityUid uid, InjectorComponent component, ItemStatusCollectMessage args)
-    {
-        args.Controls.Add(new InjectorStatusControl(component));
-    }
-
     private void OnHandleHyposprayState(EntityUid uid, HyposprayComponent component, ref ComponentHandleState args)
     {
         if (args.Current is not HyposprayComponentState cState)
@@ -44,9 +39,4 @@ public sealed class InjectorSystem : EntitySystem
         component.TotalVolume = cState.MaxVolume;
         component.UiUpdateNeeded = true;
     }
-
-    private void OnItemHyposprayStatus(EntityUid uid, HyposprayComponent component, ItemStatusCollectMessage args)
-    {
-        args.Controls.Add(new HyposprayStatusControl(component));
-    }
 }
index e6da15c3bc56a8257dbe4fa28f3f2db3bf9ec234..dc039794813e9bdc3b08832a233d39c4c083b82d 100644 (file)
@@ -18,7 +18,7 @@ public sealed class CrayonSystem : SharedCrayonSystem
     {
         base.Initialize();
         SubscribeLocalEvent<CrayonComponent, ComponentHandleState>(OnCrayonHandleState);
-        SubscribeLocalEvent<CrayonComponent, ItemStatusCollectMessage>(OnCrayonItemStatus);
+        Subs.ItemStatus<CrayonComponent>(ent => new StatusControl(ent));
     }
 
     private static void OnCrayonHandleState(EntityUid uid, CrayonComponent component, ref ComponentHandleState args)
@@ -33,11 +33,6 @@ public sealed class CrayonSystem : SharedCrayonSystem
         component.UIUpdateNeeded = true;
     }
 
-    private static void OnCrayonItemStatus(EntityUid uid, CrayonComponent component, ItemStatusCollectMessage args)
-    {
-        args.Controls.Add(new StatusControl(component));
-    }
-
     private sealed class StatusControl : Control
     {
         private readonly CrayonComponent _parent;
index 97c1a8005720afe3607bfb201c4d6a3f1438bfc1..86b39948d321b74e23b02c2d71739e47b42f81d8 100644 (file)
@@ -1,7 +1,6 @@
 using Content.Client.Fluids.UI;
 using Content.Client.Items;
 using Content.Shared.Fluids;
-using Robust.Client.UserInterface;
 
 namespace Content.Client.Fluids;
 
@@ -11,11 +10,6 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
     public override void Initialize()
     {
         base.Initialize();
-        Subs.ItemStatus<AbsorbentComponent>(GetAbsorbent);
-    }
-
-    private Control GetAbsorbent(EntityUid arg)
-    {
-        return new AbsorbentItemStatus(arg, EntityManager);
+        Subs.ItemStatus<AbsorbentComponent>(ent => new AbsorbentItemStatus(ent, EntityManager));
     }
 }
index fa680de1fc055fb7c8b2a84d0bc2d21d8178d5d3..cc2b888da37f3d46e98aa8200630d50ccfc75562 100644 (file)
@@ -9,11 +9,7 @@ public sealed class HandheldGpsSystem : EntitySystem
     public override void Initialize()
     {
         base.Initialize();
-        SubscribeLocalEvent<HandheldGPSComponent, ItemStatusCollectMessage>(OnItemStatus);
-    }
 
-    private void OnItemStatus(Entity<HandheldGPSComponent> ent, ref ItemStatusCollectMessage args)
-    {
-        args.Controls.Add(new HandheldGpsStatusControl(ent));
+        Subs.ItemStatus<HandheldGPSComponent>(ent => new HandheldGpsStatusControl(ent));
     }
 }
index 6949a94d67c11aa54199184d204ca2b6d6dbbc68..13a90f3e3913df3443a8246eb7f1a03217692d0f 100644 (file)
@@ -12,16 +12,11 @@ public sealed class ImplanterSystem : SharedImplanterSystem
         base.Initialize();
 
         SubscribeLocalEvent<ImplanterComponent, AfterAutoHandleStateEvent>(OnHandleImplanterState);
-        SubscribeLocalEvent<ImplanterComponent, ItemStatusCollectMessage>(OnItemImplanterStatus);
+        Subs.ItemStatus<ImplanterComponent>(ent => new ImplanterStatusControl(ent));
     }
 
     private void OnHandleImplanterState(EntityUid uid, ImplanterComponent component, ref AfterAutoHandleStateEvent args)
     {
         component.UiUpdateNeeded = true;
     }
-
-    private void OnItemImplanterStatus(EntityUid uid, ImplanterComponent component, ItemStatusCollectMessage args)
-    {
-        args.Controls.Add(new ImplanterStatusControl(component));
-    }
 }
index 58a302e8821a31d8a59b49c9dc7994919fdcd92f..3af02f0a4fd5864a70192cca46057bcd5a6357e2 100644 (file)
@@ -2,27 +2,51 @@
 
 namespace Content.Client.Items
 {
+    /// <summary>
+    /// Raised by the HUD logic to collect item status controls for a held entity.
+    /// </summary>
+    /// <remarks>
+    /// Handlers should add any controls they want to add to <see cref="Controls"/>.
+    /// </remarks>
+    /// <seealso cref="ItemStatusRegisterExt"/>
     public sealed class ItemStatusCollectMessage : EntityEventArgs
     {
+        /// <summary>
+        /// A list of controls that will be displayed on the HUD. Handlers should add their controls here.
+        /// </summary>
         public List<Control> Controls = new();
     }
 
+    /// <summary>
+    /// Extension methods for registering item status controls.
+    /// </summary>
+    /// <seealso cref="ItemStatusCollectMessage"/>
     public static class ItemStatusRegisterExt
     {
         /// <summary>
         /// Register an item status control for a component.
         /// </summary>
+        /// <remarks>
+        /// This is a convenience wrapper around <see cref="ItemStatusCollectMessage"/>.
+        /// </remarks>
         /// <param name="subs">The <see cref="EntitySystem.Subs"/> handle from within entity system initialize.</param>
-        /// <param name="createControl">A delegate to create the actual control.</param>
+        /// <param name="createControl">
+        /// A delegate to create the actual control.
+        /// If the delegate returns null, no control will be added to the item status.
+        /// </param>
         /// <typeparam name="TComp">The type of component for which this control should be made.</typeparam>
         public static void ItemStatus<TComp>(
             this EntitySystem.Subscriptions subs,
-            Func<EntityUid, Control> createControl)
+            Func<Entity<TComp>, Control?> createControl)
             where TComp : IComponent
         {
-            subs.SubscribeLocalEvent<TComp, ItemStatusCollectMessage>((uid, _, args) =>
+            subs.SubscribeLocalEvent((Entity<TComp> entity, ref ItemStatusCollectMessage args) =>
             {
-                args.Controls.Add(createControl(uid));
+                var control = createControl(entity);
+                if (control == null)
+                    return;
+
+                args.Controls.Add(control);
             });
         }
     }
index 1912fe91f0b1ef5674d716c3e2fc3b3346fed21a..7f18223811d8da08c1e0bb4b211222387de9d4c3 100644 (file)
@@ -17,15 +17,10 @@ public sealed class HandheldLightSystem : SharedHandheldLightSystem
     {
         base.Initialize();
 
-        SubscribeLocalEvent<HandheldLightComponent, ItemStatusCollectMessage>(OnGetStatusControl);
+        Subs.ItemStatus<HandheldLightComponent>(ent => new HandheldLightStatus(ent));
         SubscribeLocalEvent<HandheldLightComponent, AppearanceChangeEvent>(OnAppearanceChange);
     }
 
-    private static void OnGetStatusControl(EntityUid uid, HandheldLightComponent component, ItemStatusCollectMessage args)
-    {
-        args.Controls.Add(new HandheldLightStatus(component));
-    }
-
     private void OnAppearanceChange(EntityUid uid, HandheldLightComponent? component, ref AppearanceChangeEvent args)
     {
         if (!Resolve(uid, ref component))
index 9047d7cc8a692c679d71a2ff0dbf5c315921b77f..0cc090fcaeb1f429b38a2f8fd500d7238fa2fcaa 100644 (file)
@@ -31,13 +31,13 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
         base.Initialize();
 
         SubscribeLocalEvent<ClearAllOverlaysEvent>(_ => ClearAllOverlays());
-        SubscribeLocalEvent<NetworkConfiguratorComponent, ItemStatusCollectMessage>(OnCollectItemStatus);
+        Subs.ItemStatus<NetworkConfiguratorComponent>(OnCollectItemStatus);
     }
 
-    private void OnCollectItemStatus(EntityUid uid, NetworkConfiguratorComponent configurator, ItemStatusCollectMessage args)
+    private Control OnCollectItemStatus(Entity<NetworkConfiguratorComponent> entity)
     {
         _inputManager.TryGetKeyBinding((ContentKeyFunctions.AltUseItemInHand), out var binding);
-        args.Controls.Add(new StatusControl(configurator, binding?.GetKeyString() ?? ""));
+        return new StatusControl(entity, binding?.GetKeyString() ?? "");
     }
 
     public bool ConfiguredListIsTracked(EntityUid uid, NetworkConfiguratorComponent? component = null)
index ffb0ad426e3c8225130efcaf32cc193105bc875b..0b5aa61a52a0ac65d751b29f916ed8d7c92a79d6 100644 (file)
@@ -11,19 +11,11 @@ public sealed class GeigerSystem : SharedGeigerSystem
     {
         base.Initialize();
         SubscribeLocalEvent<GeigerComponent, AfterAutoHandleStateEvent>(OnHandleState);
-        SubscribeLocalEvent<GeigerComponent, ItemStatusCollectMessage>(OnGetStatusMessage);
+        Subs.ItemStatus<GeigerComponent>(ent => ent.Comp.ShowControl ? new GeigerItemControl(ent) : null);
     }
 
     private void OnHandleState(EntityUid uid, GeigerComponent component, ref AfterAutoHandleStateEvent args)
     {
         component.UiUpdateNeeded = true;
     }
-
-    private void OnGetStatusMessage(EntityUid uid, GeigerComponent component, ItemStatusCollectMessage args)
-    {
-        if (!component.ShowControl)
-            return;
-
-        args.Controls.Add(new GeigerItemControl(component));
-    }
 }
index a5d7470b57c96ea42e8db49be622876e1d20e51b..c081581338fffe49950b6ff5d78c33bc9ff8d20e 100644 (file)
@@ -16,13 +16,8 @@ namespace Content.Client.Stack
         public override void Initialize()
         {
             base.Initialize();
-            SubscribeLocalEvent<StackComponent, ItemStatusCollectMessage>(OnItemStatus);
             SubscribeLocalEvent<StackComponent, AppearanceChangeEvent>(OnAppearanceChange);
-        }
-
-        private void OnItemStatus(EntityUid uid, StackComponent component, ItemStatusCollectMessage args)
-        {
-            args.Controls.Add(new StackStatusControl(component));
+            Subs.ItemStatus<StackComponent>(ent => new StackStatusControl(ent));
         }
 
         public override void SetCount(EntityUid uid, int amount, StackComponent? component = null)
index a305fd5bb21c063a6b25b6bdd462fecb1a9b66ee..6811d58460d314963476df25b11748d18b125a54 100644 (file)
@@ -16,8 +16,8 @@ namespace Content.Client.Tools
             base.Initialize();
 
             SubscribeLocalEvent<WelderComponent, ComponentHandleState>(OnWelderHandleState);
-            SubscribeLocalEvent<WelderComponent, ItemStatusCollectMessage>(OnWelderGetStatusMessage);
-            SubscribeLocalEvent<MultipleToolComponent, ItemStatusCollectMessage>(OnGetStatusMessage);
+            Subs.ItemStatus<WelderComponent>(ent => new WelderStatusControl(ent));
+            Subs.ItemStatus<MultipleToolComponent>(ent => new MultipleToolStatusControl(ent));
         }
 
         public override void SetMultipleTool(EntityUid uid,
@@ -43,16 +43,6 @@ namespace Content.Client.Tools
             }
         }
 
-        private void OnGetStatusMessage(EntityUid uid, MultipleToolComponent welder, ItemStatusCollectMessage args)
-        {
-            args.Controls.Add(new MultipleToolStatusControl(welder));
-        }
-
-        private void OnWelderGetStatusMessage(EntityUid uid, WelderComponent component, ItemStatusCollectMessage args)
-        {
-            args.Controls.Add(new WelderStatusControl(component, uid));
-        }
-
         private void OnWelderHandleState(EntityUid uid, WelderComponent welder, ref ComponentHandleState args)
         {
             if (args.Current is not WelderComponentState state)