Refactors stacks to be fully ECS. (#4046)
This commit is contained in:
committed by
GitHub
parent
0f8e330a3d
commit
33fa208214
@@ -1,9 +1,6 @@
|
||||
#nullable enable
|
||||
|
||||
using Content.Client.UserInterface.Stylesheets;
|
||||
using Content.Client.Utility;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -17,38 +14,17 @@ namespace Content.Client.GameObjects.Components
|
||||
[ComponentReference(typeof(SharedStackComponent))]
|
||||
public class StackComponent : SharedStackComponent, IItemStatus
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
|
||||
[ComponentDependency] private readonly AppearanceComponent? _appearanceComponent = default!;
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
private bool _uiUpdateNeeded;
|
||||
|
||||
public Control MakeControl() => new StatusControl(this);
|
||||
|
||||
public override int Count
|
||||
public Control MakeControl()
|
||||
{
|
||||
get => base.Count;
|
||||
set
|
||||
{
|
||||
var valueChanged = value != Count;
|
||||
base.Count = value;
|
||||
|
||||
if (valueChanged)
|
||||
{
|
||||
_appearanceComponent?.SetData(StackVisuals.Actual, Count);
|
||||
|
||||
}
|
||||
|
||||
_uiUpdateNeeded = true;
|
||||
}
|
||||
return new StatusControl(this);
|
||||
}
|
||||
|
||||
public override void Initialize()
|
||||
public void DirtyUI()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
if (!Owner.Deleted)
|
||||
{
|
||||
_appearanceComponent?.SetData(StackVisuals.MaxCount, MaxCount);
|
||||
_appearanceComponent?.SetData(StackVisuals.Hide, false);
|
||||
}
|
||||
_uiUpdateNeeded = true;
|
||||
}
|
||||
|
||||
private sealed class StatusControl : Control
|
||||
|
||||
25
Content.Client/GameObjects/EntitySystems/StackSystem.cs
Normal file
25
Content.Client/GameObjects/EntitySystems/StackSystem.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Content.Client.GameObjects.Components;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Client.GameObjects.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class StackSystem : SharedStackSystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<StackComponent, StackCountChangedEvent>(OnStackCountChanged);
|
||||
}
|
||||
|
||||
private void OnStackCountChanged(EntityUid uid, StackComponent component, StackCountChangedEvent args)
|
||||
{
|
||||
// Dirty the UI now that the stack count has changed.
|
||||
component.DirtyUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user