diff --git a/Content.Client/Chemistry/EntitySystems/InjectorSystem.cs b/Content.Client/Chemistry/EntitySystems/InjectorSystem.cs index eeca31220f..896349a161 100644 --- a/Content.Client/Chemistry/EntitySystems/InjectorSystem.cs +++ b/Content.Client/Chemistry/EntitySystems/InjectorSystem.cs @@ -12,9 +12,9 @@ public sealed class InjectorSystem : EntitySystem { base.Initialize(); SubscribeLocalEvent(OnHandleInjectorState); - SubscribeLocalEvent(OnItemInjectorStatus); + Subs.ItemStatus(ent => new InjectorStatusControl(ent)); SubscribeLocalEvent(OnHandleHyposprayState); - SubscribeLocalEvent(OnItemHyposprayStatus); + Subs.ItemStatus(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)); - } } diff --git a/Content.Client/Crayon/CrayonSystem.cs b/Content.Client/Crayon/CrayonSystem.cs index e6da15c3bc..dc03979481 100644 --- a/Content.Client/Crayon/CrayonSystem.cs +++ b/Content.Client/Crayon/CrayonSystem.cs @@ -18,7 +18,7 @@ public sealed class CrayonSystem : SharedCrayonSystem { base.Initialize(); SubscribeLocalEvent(OnCrayonHandleState); - SubscribeLocalEvent(OnCrayonItemStatus); + Subs.ItemStatus(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; diff --git a/Content.Client/Fluids/AbsorbentSystem.cs b/Content.Client/Fluids/AbsorbentSystem.cs index 97c1a80057..86b39948d3 100644 --- a/Content.Client/Fluids/AbsorbentSystem.cs +++ b/Content.Client/Fluids/AbsorbentSystem.cs @@ -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(GetAbsorbent); - } - - private Control GetAbsorbent(EntityUid arg) - { - return new AbsorbentItemStatus(arg, EntityManager); + Subs.ItemStatus(ent => new AbsorbentItemStatus(ent, EntityManager)); } } diff --git a/Content.Client/GPS/Systems/HandheldGpsSystem.cs b/Content.Client/GPS/Systems/HandheldGpsSystem.cs index fa680de1fc..cc2b888da3 100644 --- a/Content.Client/GPS/Systems/HandheldGpsSystem.cs +++ b/Content.Client/GPS/Systems/HandheldGpsSystem.cs @@ -9,11 +9,7 @@ public sealed class HandheldGpsSystem : EntitySystem public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnItemStatus); - } - private void OnItemStatus(Entity ent, ref ItemStatusCollectMessage args) - { - args.Controls.Add(new HandheldGpsStatusControl(ent)); + Subs.ItemStatus(ent => new HandheldGpsStatusControl(ent)); } } diff --git a/Content.Client/Implants/ImplanterSystem.cs b/Content.Client/Implants/ImplanterSystem.cs index 6949a94d67..13a90f3e39 100644 --- a/Content.Client/Implants/ImplanterSystem.cs +++ b/Content.Client/Implants/ImplanterSystem.cs @@ -12,16 +12,11 @@ public sealed class ImplanterSystem : SharedImplanterSystem base.Initialize(); SubscribeLocalEvent(OnHandleImplanterState); - SubscribeLocalEvent(OnItemImplanterStatus); + Subs.ItemStatus(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)); - } } diff --git a/Content.Client/Items/ItemStatusMessages.cs b/Content.Client/Items/ItemStatusMessages.cs index 58a302e882..3af02f0a4f 100644 --- a/Content.Client/Items/ItemStatusMessages.cs +++ b/Content.Client/Items/ItemStatusMessages.cs @@ -2,27 +2,51 @@ namespace Content.Client.Items { + /// + /// Raised by the HUD logic to collect item status controls for a held entity. + /// + /// + /// Handlers should add any controls they want to add to . + /// + /// public sealed class ItemStatusCollectMessage : EntityEventArgs { + /// + /// A list of controls that will be displayed on the HUD. Handlers should add their controls here. + /// public List Controls = new(); } + /// + /// Extension methods for registering item status controls. + /// + /// public static class ItemStatusRegisterExt { /// /// Register an item status control for a component. /// + /// + /// This is a convenience wrapper around . + /// /// The handle from within entity system initialize. - /// A delegate to create the actual control. + /// + /// A delegate to create the actual control. + /// If the delegate returns null, no control will be added to the item status. + /// /// The type of component for which this control should be made. public static void ItemStatus( this EntitySystem.Subscriptions subs, - Func createControl) + Func, Control?> createControl) where TComp : IComponent { - subs.SubscribeLocalEvent((uid, _, args) => + subs.SubscribeLocalEvent((Entity entity, ref ItemStatusCollectMessage args) => { - args.Controls.Add(createControl(uid)); + var control = createControl(entity); + if (control == null) + return; + + args.Controls.Add(control); }); } } diff --git a/Content.Client/Light/HandheldLightSystem.cs b/Content.Client/Light/HandheldLightSystem.cs index 1912fe91f0..7f18223811 100644 --- a/Content.Client/Light/HandheldLightSystem.cs +++ b/Content.Client/Light/HandheldLightSystem.cs @@ -17,15 +17,10 @@ public sealed class HandheldLightSystem : SharedHandheldLightSystem { base.Initialize(); - SubscribeLocalEvent(OnGetStatusControl); + Subs.ItemStatus(ent => new HandheldLightStatus(ent)); SubscribeLocalEvent(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)) diff --git a/Content.Client/NetworkConfigurator/Systems/NetworkConfiguratorSystem.cs b/Content.Client/NetworkConfigurator/Systems/NetworkConfiguratorSystem.cs index 9047d7cc8a..0cc090fcae 100644 --- a/Content.Client/NetworkConfigurator/Systems/NetworkConfiguratorSystem.cs +++ b/Content.Client/NetworkConfigurator/Systems/NetworkConfiguratorSystem.cs @@ -31,13 +31,13 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem base.Initialize(); SubscribeLocalEvent(_ => ClearAllOverlays()); - SubscribeLocalEvent(OnCollectItemStatus); + Subs.ItemStatus(OnCollectItemStatus); } - private void OnCollectItemStatus(EntityUid uid, NetworkConfiguratorComponent configurator, ItemStatusCollectMessage args) + private Control OnCollectItemStatus(Entity 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) diff --git a/Content.Client/Radiation/Systems/GeigerSystem.cs b/Content.Client/Radiation/Systems/GeigerSystem.cs index ffb0ad426e..0b5aa61a52 100644 --- a/Content.Client/Radiation/Systems/GeigerSystem.cs +++ b/Content.Client/Radiation/Systems/GeigerSystem.cs @@ -11,19 +11,11 @@ public sealed class GeigerSystem : SharedGeigerSystem { base.Initialize(); SubscribeLocalEvent(OnHandleState); - SubscribeLocalEvent(OnGetStatusMessage); + Subs.ItemStatus(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)); - } } diff --git a/Content.Client/Stack/StackSystem.cs b/Content.Client/Stack/StackSystem.cs index a5d7470b57..c081581338 100644 --- a/Content.Client/Stack/StackSystem.cs +++ b/Content.Client/Stack/StackSystem.cs @@ -16,13 +16,8 @@ namespace Content.Client.Stack public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnItemStatus); SubscribeLocalEvent(OnAppearanceChange); - } - - private void OnItemStatus(EntityUid uid, StackComponent component, ItemStatusCollectMessage args) - { - args.Controls.Add(new StackStatusControl(component)); + Subs.ItemStatus(ent => new StackStatusControl(ent)); } public override void SetCount(EntityUid uid, int amount, StackComponent? component = null) diff --git a/Content.Client/Tools/ToolSystem.cs b/Content.Client/Tools/ToolSystem.cs index a305fd5bb2..6811d58460 100644 --- a/Content.Client/Tools/ToolSystem.cs +++ b/Content.Client/Tools/ToolSystem.cs @@ -16,8 +16,8 @@ namespace Content.Client.Tools base.Initialize(); SubscribeLocalEvent(OnWelderHandleState); - SubscribeLocalEvent(OnWelderGetStatusMessage); - SubscribeLocalEvent(OnGetStatusMessage); + Subs.ItemStatus(ent => new WelderStatusControl(ent)); + Subs.ItemStatus(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)