2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.Items.Components;
|
|
|
|
|
using Content.Client.Message;
|
|
|
|
|
using Content.Client.Stylesheets;
|
|
|
|
|
using Content.Shared.Crayon;
|
2020-10-13 13:40:05 +02: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.Crayon
|
2020-10-13 13:40:05 +02:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
public class CrayonComponent : SharedCrayonComponent, IItemStatus
|
|
|
|
|
{
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)] private string Color => _color;
|
|
|
|
|
[ViewVariables] private int Charges { get; set; }
|
|
|
|
|
[ViewVariables] private int Capacity { get; set; }
|
|
|
|
|
|
|
|
|
|
Control IItemStatus.MakeControl()
|
|
|
|
|
{
|
|
|
|
|
return new StatusControl(this);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
2020-10-13 13:40:05 +02:00
|
|
|
{
|
2020-11-26 14:33:31 +01:00
|
|
|
if (curState is not CrayonComponentState state)
|
2020-10-13 13:40:05 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
_color = state.Color;
|
|
|
|
|
SelectedState = state.State;
|
|
|
|
|
Charges = state.Charges;
|
|
|
|
|
Capacity = state.Capacity;
|
|
|
|
|
|
|
|
|
|
_uiUpdateNeeded = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private sealed class StatusControl : Control
|
|
|
|
|
{
|
|
|
|
|
private readonly CrayonComponent _parent;
|
|
|
|
|
private readonly RichTextLabel _label;
|
|
|
|
|
|
|
|
|
|
public StatusControl(CrayonComponent parent)
|
|
|
|
|
{
|
|
|
|
|
_parent = parent;
|
|
|
|
|
_label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
|
|
|
|
|
AddChild(_label);
|
|
|
|
|
|
|
|
|
|
parent._uiUpdateNeeded = true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-26 17:10:31 -07:00
|
|
|
protected override void FrameUpdate(FrameEventArgs args)
|
2020-10-13 13:40:05 +02:00
|
|
|
{
|
2021-03-26 17:10:31 -07:00
|
|
|
base.FrameUpdate(args);
|
2020-10-13 13:40:05 +02:00
|
|
|
|
|
|
|
|
if (!_parent._uiUpdateNeeded)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_parent._uiUpdateNeeded = false;
|
2021-06-21 02:13:54 +02:00
|
|
|
_label.SetMarkup(Loc.GetString("crayon-drawing-label",
|
|
|
|
|
("color",_parent.Color),
|
|
|
|
|
("state",_parent.SelectedState),
|
|
|
|
|
("charges", _parent.Charges),
|
|
|
|
|
("capacity",_parent.Capacity)));
|
2020-10-13 13:40:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|