using Robust.Client.UserInterface;
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.
/// 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, Control?> createControl)
where TComp : IComponent
{
subs.SubscribeLocalEvent((Entity entity, ref ItemStatusCollectMessage args) =>
{
var control = createControl(entity);
if (control == null)
return;
args.Controls.Add(control);
});
}
}
}