Files
OldThink/Content.Client/Stack/StackComponent.cs

61 lines
1.6 KiB
C#
Raw Normal View History

2021-06-09 22:19:39 +02:00
using Content.Client.Items.Components;
using Content.Client.Message;
using Content.Client.Stylesheets;
using Content.Shared.Stacks;
2020-01-09 00:27:52 +01:00
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
2021-06-09 22:19:39 +02:00
namespace Content.Client.Stack
2020-01-09 00:27:52 +01:00
{
[RegisterComponent]
[ComponentReference(typeof(SharedStackComponent))]
2020-01-09 00:27:52 +01:00
public class StackComponent : SharedStackComponent, IItemStatus
{
[ViewVariables(VVAccess.ReadWrite)]
private bool _uiUpdateNeeded;
2020-01-09 00:27:52 +01:00
public Control MakeControl()
2020-01-09 00:27:52 +01:00
{
return new StatusControl(this);
2020-01-09 00:27:52 +01:00
}
public void DirtyUI()
{
_uiUpdateNeeded = true;
}
2020-01-09 00:27:52 +01:00
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}};
2020-01-09 00:27:52 +01:00
AddChild(_label);
parent._uiUpdateNeeded = true;
}
protected override void FrameUpdate(FrameEventArgs args)
2020-01-09 00:27:52 +01:00
{
base.FrameUpdate(args);
2020-01-09 00:27:52 +01:00
if (!_parent._uiUpdateNeeded)
{
return;
}
_parent._uiUpdateNeeded = false;
2021-02-28 20:02:03 -04:00
_label.SetMarkup(Loc.GetString("comp-stack-status", ("count", _parent.Count)));
2020-01-09 00:27:52 +01:00
}
}
}
2021-02-28 20:02:03 -04:00
}