2022-09-11 08:53:17 +02:00
|
|
|
using Content.Client.Items;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Stacks;
|
2021-05-26 10:20:57 +02:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Stack
|
2021-05-26 10:20:57 +02:00
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class StackSystem : SharedStackSystem
|
2021-05-26 10:20:57 +02:00
|
|
|
{
|
2022-09-11 08:53:17 +02:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<StackComponent, ItemStatusCollectMessage>(OnItemStatus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnItemStatus(EntityUid uid, StackComponent component, ItemStatusCollectMessage args)
|
|
|
|
|
{
|
|
|
|
|
args.Controls.Add(new StackStatusControl(component));
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-24 23:28:21 -05:00
|
|
|
public override void SetCount(EntityUid uid, int amount, StackComponent? component = null)
|
2021-05-26 10:20:57 +02:00
|
|
|
{
|
2022-03-28 17:03:14 +13:00
|
|
|
if (!Resolve(uid, ref component))
|
|
|
|
|
return;
|
2021-05-26 10:20:57 +02:00
|
|
|
|
2022-03-28 17:03:14 +13:00
|
|
|
base.SetCount(uid, amount, component);
|
|
|
|
|
|
|
|
|
|
// TODO PREDICT ENTITY DELETION: This should really just be a normal entity deletion call.
|
|
|
|
|
if (component.Count <= 0)
|
|
|
|
|
{
|
2023-02-22 12:45:32 +11:00
|
|
|
Xform.DetachParentToNull(uid, Transform(uid));
|
2022-03-28 17:03:14 +13:00
|
|
|
return;
|
|
|
|
|
}
|
2021-05-26 10:20:57 +02:00
|
|
|
|
|
|
|
|
// Dirty the UI now that the stack count has changed.
|
2022-03-28 17:03:14 +13:00
|
|
|
if (component is StackComponent clientComp)
|
|
|
|
|
clientComp.UiUpdateNeeded = true;
|
2021-05-26 10:20:57 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|