Use item status extension method (#23884)
Just removes some lines of code.
This commit is contained in:
committed by
GitHub
parent
e2dd30f640
commit
e665c2487e
@@ -12,9 +12,9 @@ public sealed class InjectorSystem : EntitySystem
|
|||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<InjectorComponent, ComponentHandleState>(OnHandleInjectorState);
|
SubscribeLocalEvent<InjectorComponent, ComponentHandleState>(OnHandleInjectorState);
|
||||||
SubscribeLocalEvent<InjectorComponent, ItemStatusCollectMessage>(OnItemInjectorStatus);
|
Subs.ItemStatus<InjectorComponent>(ent => new InjectorStatusControl(ent));
|
||||||
SubscribeLocalEvent<HyposprayComponent, ComponentHandleState>(OnHandleHyposprayState);
|
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)
|
private void OnHandleInjectorState(EntityUid uid, InjectorComponent component, ref ComponentHandleState args)
|
||||||
@@ -30,11 +30,6 @@ public sealed class InjectorSystem : EntitySystem
|
|||||||
component.UiUpdateNeeded = true;
|
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)
|
private void OnHandleHyposprayState(EntityUid uid, HyposprayComponent component, ref ComponentHandleState args)
|
||||||
{
|
{
|
||||||
if (args.Current is not HyposprayComponentState cState)
|
if (args.Current is not HyposprayComponentState cState)
|
||||||
@@ -44,9 +39,4 @@ public sealed class InjectorSystem : EntitySystem
|
|||||||
component.TotalVolume = cState.MaxVolume;
|
component.TotalVolume = cState.MaxVolume;
|
||||||
component.UiUpdateNeeded = true;
|
component.UiUpdateNeeded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnItemHyposprayStatus(EntityUid uid, HyposprayComponent component, ItemStatusCollectMessage args)
|
|
||||||
{
|
|
||||||
args.Controls.Add(new HyposprayStatusControl(component));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public sealed class CrayonSystem : SharedCrayonSystem
|
|||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<CrayonComponent, ComponentHandleState>(OnCrayonHandleState);
|
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)
|
private static void OnCrayonHandleState(EntityUid uid, CrayonComponent component, ref ComponentHandleState args)
|
||||||
@@ -33,11 +33,6 @@ public sealed class CrayonSystem : SharedCrayonSystem
|
|||||||
component.UIUpdateNeeded = true;
|
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 sealed class StatusControl : Control
|
||||||
{
|
{
|
||||||
private readonly CrayonComponent _parent;
|
private readonly CrayonComponent _parent;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using Content.Client.Fluids.UI;
|
using Content.Client.Fluids.UI;
|
||||||
using Content.Client.Items;
|
using Content.Client.Items;
|
||||||
using Content.Shared.Fluids;
|
using Content.Shared.Fluids;
|
||||||
using Robust.Client.UserInterface;
|
|
||||||
|
|
||||||
namespace Content.Client.Fluids;
|
namespace Content.Client.Fluids;
|
||||||
|
|
||||||
@@ -11,11 +10,6 @@ public sealed class AbsorbentSystem : SharedAbsorbentSystem
|
|||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
Subs.ItemStatus<AbsorbentComponent>(GetAbsorbent);
|
Subs.ItemStatus<AbsorbentComponent>(ent => new AbsorbentItemStatus(ent, EntityManager));
|
||||||
}
|
|
||||||
|
|
||||||
private Control GetAbsorbent(EntityUid arg)
|
|
||||||
{
|
|
||||||
return new AbsorbentItemStatus(arg, EntityManager);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,7 @@ public sealed class HandheldGpsSystem : EntitySystem
|
|||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<HandheldGPSComponent, ItemStatusCollectMessage>(OnItemStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnItemStatus(Entity<HandheldGPSComponent> ent, ref ItemStatusCollectMessage args)
|
Subs.ItemStatus<HandheldGPSComponent>(ent => new HandheldGpsStatusControl(ent));
|
||||||
{
|
|
||||||
args.Controls.Add(new HandheldGpsStatusControl(ent));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,16 +12,11 @@ public sealed class ImplanterSystem : SharedImplanterSystem
|
|||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<ImplanterComponent, AfterAutoHandleStateEvent>(OnHandleImplanterState);
|
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)
|
private void OnHandleImplanterState(EntityUid uid, ImplanterComponent component, ref AfterAutoHandleStateEvent args)
|
||||||
{
|
{
|
||||||
component.UiUpdateNeeded = true;
|
component.UiUpdateNeeded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnItemImplanterStatus(EntityUid uid, ImplanterComponent component, ItemStatusCollectMessage args)
|
|
||||||
{
|
|
||||||
args.Controls.Add(new ImplanterStatusControl(component));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,27 +2,51 @@
|
|||||||
|
|
||||||
namespace Content.Client.Items
|
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
|
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();
|
public List<Control> Controls = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Extension methods for registering item status controls.
|
||||||
|
/// </summary>
|
||||||
|
/// <seealso cref="ItemStatusCollectMessage"/>
|
||||||
public static class ItemStatusRegisterExt
|
public static class ItemStatusRegisterExt
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Register an item status control for a component.
|
/// Register an item status control for a component.
|
||||||
/// </summary>
|
/// </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="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>
|
/// <typeparam name="TComp">The type of component for which this control should be made.</typeparam>
|
||||||
public static void ItemStatus<TComp>(
|
public static void ItemStatus<TComp>(
|
||||||
this EntitySystem.Subscriptions subs,
|
this EntitySystem.Subscriptions subs,
|
||||||
Func<EntityUid, Control> createControl)
|
Func<Entity<TComp>, Control?> createControl)
|
||||||
where TComp : IComponent
|
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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,10 @@ public sealed class HandheldLightSystem : SharedHandheldLightSystem
|
|||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<HandheldLightComponent, ItemStatusCollectMessage>(OnGetStatusControl);
|
Subs.ItemStatus<HandheldLightComponent>(ent => new HandheldLightStatus(ent));
|
||||||
SubscribeLocalEvent<HandheldLightComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
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)
|
private void OnAppearanceChange(EntityUid uid, HandheldLightComponent? component, ref AppearanceChangeEvent args)
|
||||||
{
|
{
|
||||||
if (!Resolve(uid, ref component))
|
if (!Resolve(uid, ref component))
|
||||||
|
|||||||
@@ -31,13 +31,13 @@ public sealed class NetworkConfiguratorSystem : SharedNetworkConfiguratorSystem
|
|||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<ClearAllOverlaysEvent>(_ => ClearAllOverlays());
|
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);
|
_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)
|
public bool ConfiguredListIsTracked(EntityUid uid, NetworkConfiguratorComponent? component = null)
|
||||||
|
|||||||
@@ -11,19 +11,11 @@ public sealed class GeigerSystem : SharedGeigerSystem
|
|||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<GeigerComponent, AfterAutoHandleStateEvent>(OnHandleState);
|
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)
|
private void OnHandleState(EntityUid uid, GeigerComponent component, ref AfterAutoHandleStateEvent args)
|
||||||
{
|
{
|
||||||
component.UiUpdateNeeded = true;
|
component.UiUpdateNeeded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnGetStatusMessage(EntityUid uid, GeigerComponent component, ItemStatusCollectMessage args)
|
|
||||||
{
|
|
||||||
if (!component.ShowControl)
|
|
||||||
return;
|
|
||||||
|
|
||||||
args.Controls.Add(new GeigerItemControl(component));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,13 +16,8 @@ namespace Content.Client.Stack
|
|||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
SubscribeLocalEvent<StackComponent, ItemStatusCollectMessage>(OnItemStatus);
|
|
||||||
SubscribeLocalEvent<StackComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
SubscribeLocalEvent<StackComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
||||||
}
|
Subs.ItemStatus<StackComponent>(ent => new StackStatusControl(ent));
|
||||||
|
|
||||||
private void OnItemStatus(EntityUid uid, StackComponent component, ItemStatusCollectMessage args)
|
|
||||||
{
|
|
||||||
args.Controls.Add(new StackStatusControl(component));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetCount(EntityUid uid, int amount, StackComponent? component = null)
|
public override void SetCount(EntityUid uid, int amount, StackComponent? component = null)
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ namespace Content.Client.Tools
|
|||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<WelderComponent, ComponentHandleState>(OnWelderHandleState);
|
SubscribeLocalEvent<WelderComponent, ComponentHandleState>(OnWelderHandleState);
|
||||||
SubscribeLocalEvent<WelderComponent, ItemStatusCollectMessage>(OnWelderGetStatusMessage);
|
Subs.ItemStatus<WelderComponent>(ent => new WelderStatusControl(ent));
|
||||||
SubscribeLocalEvent<MultipleToolComponent, ItemStatusCollectMessage>(OnGetStatusMessage);
|
Subs.ItemStatus<MultipleToolComponent>(ent => new MultipleToolStatusControl(ent));
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SetMultipleTool(EntityUid uid,
|
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)
|
private void OnWelderHandleState(EntityUid uid, WelderComponent welder, ref ComponentHandleState args)
|
||||||
{
|
{
|
||||||
if (args.Current is not WelderComponentState state)
|
if (args.Current is not WelderComponentState state)
|
||||||
|
|||||||
Reference in New Issue
Block a user