Just removes some lines of code.
{
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)
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)
component.TotalVolume = cState.MaxVolume;
component.UiUpdateNeeded = true;
}
-
- private void OnItemHyposprayStatus(EntityUid uid, HyposprayComponent component, ItemStatusCollectMessage args)
- {
- args.Controls.Add(new HyposprayStatusControl(component));
- }
}
{
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)
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;
using Content.Client.Fluids.UI;
using Content.Client.Items;
using Content.Shared.Fluids;
-using Robust.Client.UserInterface;
namespace Content.Client.Fluids;
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));
}
}
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));
}
}
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));
- }
}
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);
});
}
}
{
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))
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)
{
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));
- }
}
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)
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,
}
}
- 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)