2023-08-12 17:39:58 -04:00
|
|
|
using System.Linq;
|
2022-09-11 08:53:17 +02:00
|
|
|
using Content.Client.Items;
|
2023-05-17 23:16:53 -07:00
|
|
|
using Content.Client.Storage.Systems;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Stacks;
|
2021-05-26 10:20:57 +02:00
|
|
|
using JetBrains.Annotations;
|
2023-05-17 23:16:53 -07:00
|
|
|
using Robust.Client.GameObjects;
|
2021-05-26 10:20:57 +02:00
|
|
|
|
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
|
|
|
{
|
2023-05-17 23:16:53 -07:00
|
|
|
[Dependency] private readonly AppearanceSystem _appearanceSystem = default!;
|
|
|
|
|
[Dependency] private readonly ItemCounterSystem _counterSystem = default!;
|
|
|
|
|
|
2022-09-11 08:53:17 +02:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<StackComponent, ItemStatusCollectMessage>(OnItemStatus);
|
2023-05-17 23:16:53 -07:00
|
|
|
SubscribeLocalEvent<StackComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
2022-09-11 08:53:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2023-08-12 17:39:58 -04:00
|
|
|
if (component.Lingering &&
|
|
|
|
|
TryComp<SpriteComponent>(uid, out var sprite))
|
|
|
|
|
{
|
|
|
|
|
// tint the stack gray and make it transparent if it's lingering.
|
|
|
|
|
var color = component.Count == 0 && component.Lingering
|
|
|
|
|
? Color.DarkGray.WithAlpha(0.65f)
|
|
|
|
|
: Color.White;
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < sprite.AllLayers.Count(); i++)
|
|
|
|
|
{
|
|
|
|
|
sprite.LayerSetColor(i, color);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-28 17:03:14 +13:00
|
|
|
// TODO PREDICT ENTITY DELETION: This should really just be a normal entity deletion call.
|
2023-08-12 17:39:58 -04:00
|
|
|
if (component.Count <= 0 && !component.Lingering)
|
2022-03-28 17:03:14 +13:00
|
|
|
{
|
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
|
|
|
|
2023-06-25 11:44:37 -04:00
|
|
|
component.UiUpdateNeeded = true;
|
2021-05-26 10:20:57 +02:00
|
|
|
}
|
2023-05-17 23:16:53 -07:00
|
|
|
|
|
|
|
|
private void OnAppearanceChange(EntityUid uid, StackComponent comp, ref AppearanceChangeEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Sprite == null || comp.LayerStates.Count < 1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Skip processing if no actual
|
|
|
|
|
if (!_appearanceSystem.TryGetData<int>(uid, StackVisuals.Actual, out var actual, args.Component))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!_appearanceSystem.TryGetData<int>(uid, StackVisuals.MaxCount, out var maxCount, args.Component))
|
|
|
|
|
maxCount = comp.LayerStates.Count;
|
|
|
|
|
|
|
|
|
|
if (!_appearanceSystem.TryGetData<bool>(uid, StackVisuals.Hide, out var hidden, args.Component))
|
|
|
|
|
hidden = false;
|
|
|
|
|
|
|
|
|
|
if (comp.IsComposite)
|
|
|
|
|
_counterSystem.ProcessCompositeSprite(uid, actual, maxCount, comp.LayerStates, hidden, sprite: args.Sprite);
|
|
|
|
|
else
|
|
|
|
|
_counterSystem.ProcessOpaqueSprite(uid, comp.BaseLayer, actual, maxCount, comp.LayerStates, hidden, sprite: args.Sprite);
|
|
|
|
|
}
|
2021-05-26 10:20:57 +02:00
|
|
|
}
|
|
|
|
|
}
|