Remove IItemStatus (#11055)

This commit is contained in:
Alex Evgrashin
2022-09-11 08:53:17 +02:00
committed by GitHub
parent 61655c18b2
commit 385a52c390
18 changed files with 357 additions and 355 deletions

View File

@@ -8,44 +8,11 @@ using Robust.Shared.Timing;
namespace Content.Client.Stack
{
[RegisterComponent, Access(typeof(StackSystem), typeof(StatusControl))]
[RegisterComponent, Access(typeof(StackSystem), typeof(StackStatusControl))]
[ComponentReference(typeof(SharedStackComponent))]
public sealed class StackComponent : SharedStackComponent, IItemStatus
public sealed class StackComponent : SharedStackComponent
{
[ViewVariables]
public bool UiUpdateNeeded { get; set; }
public Control MakeControl()
{
return new StatusControl(this);
}
private sealed class StatusControl : Control
{
private readonly StackComponent _parent;
private readonly RichTextLabel _label;
public StatusControl(StackComponent parent)
{
_parent = parent;
_label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}};
_label.SetMarkup(Loc.GetString("comp-stack-status", ("count", _parent.Count)));
AddChild(_label);
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!_parent.UiUpdateNeeded)
{
return;
}
_parent.UiUpdateNeeded = false;
_label.SetMarkup(Loc.GetString("comp-stack-status", ("count", _parent.Count)));
}
}
}
}

View File

@@ -0,0 +1,35 @@
using Content.Client.Message;
using Content.Client.Stylesheets;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
namespace Content.Client.Stack;
public sealed class StackStatusControl : Control
{
private readonly StackComponent _parent;
private readonly RichTextLabel _label;
public StackStatusControl(StackComponent parent)
{
_parent = parent;
_label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}};
_label.SetMarkup(Loc.GetString("comp-stack-status", ("count", _parent.Count)));
AddChild(_label);
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!_parent.UiUpdateNeeded)
{
return;
}
_parent.UiUpdateNeeded = false;
_label.SetMarkup(Loc.GetString("comp-stack-status", ("count", _parent.Count)));
}
}

View File

@@ -1,3 +1,4 @@
using Content.Client.Items;
using Content.Shared.Stacks;
using JetBrains.Annotations;
@@ -6,6 +7,17 @@ namespace Content.Client.Stack
[UsedImplicitly]
public sealed class StackSystem : SharedStackSystem
{
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));
}
public override void SetCount(EntityUid uid, int amount, SharedStackComponent? component = null)
{
if (!Resolve(uid, ref component))