2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.Items.Components;
|
|
|
|
|
using Content.Client.Message;
|
|
|
|
|
using Content.Client.Stylesheets;
|
|
|
|
|
using Content.Shared.Chemistry.Components;
|
|
|
|
|
using Content.Shared.Chemistry.Reagent;
|
2021-11-03 16:48:03 -07:00
|
|
|
using Content.Shared.FixedPoint;
|
2021-01-24 14:18:12 +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.Chemistry.Components
|
2021-01-24 14:18:12 +01:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
public sealed class HyposprayComponent : SharedHyposprayComponent, IItemStatus
|
|
|
|
|
{
|
2021-11-03 16:48:03 -07:00
|
|
|
[ViewVariables] private FixedPoint2 CurrentVolume { get; set; }
|
|
|
|
|
[ViewVariables] private FixedPoint2 TotalVolume { get; set; }
|
2021-01-24 14:18:12 +01:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
|
|
|
|
|
|
|
|
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
|
|
|
|
{
|
|
|
|
|
if (curState is not HyposprayComponentState cState)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
CurrentVolume = cState.CurVolume;
|
|
|
|
|
TotalVolume = cState.MaxVolume;
|
|
|
|
|
_uiUpdateNeeded = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Control IItemStatus.MakeControl()
|
|
|
|
|
{
|
|
|
|
|
return new StatusControl(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private sealed class StatusControl : Control
|
|
|
|
|
{
|
|
|
|
|
private readonly HyposprayComponent _parent;
|
|
|
|
|
private readonly RichTextLabel _label;
|
|
|
|
|
|
|
|
|
|
public StatusControl(HyposprayComponent parent)
|
|
|
|
|
{
|
|
|
|
|
_parent = parent;
|
|
|
|
|
_label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}};
|
|
|
|
|
AddChild(_label);
|
|
|
|
|
|
2022-02-13 11:18:18 +13:00
|
|
|
Update();
|
2021-01-24 14:18:12 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-26 17:10:31 -07:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
protected override void FrameUpdate(FrameEventArgs args)
|
2021-01-24 14:18:12 +01:00
|
|
|
{
|
2021-03-26 17:10:31 -07:00
|
|
|
base.FrameUpdate(args);
|
2021-01-24 14:18:12 +01:00
|
|
|
if (!_parent._uiUpdateNeeded)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-13 11:18:18 +13:00
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update()
|
|
|
|
|
{
|
2021-01-24 14:18:12 +01:00
|
|
|
|
|
|
|
|
_parent._uiUpdateNeeded = false;
|
|
|
|
|
|
|
|
|
|
_label.SetMarkup(Loc.GetString(
|
2021-06-21 02:13:54 +02:00
|
|
|
"hypospray-volume-text",
|
|
|
|
|
("currentVolume", _parent.CurrentVolume),
|
|
|
|
|
("totalVolume", _parent.TotalVolume)));
|
2021-01-24 14:18:12 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|