2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.Items.Components;
|
|
|
|
|
using Content.Client.Message;
|
|
|
|
|
using Content.Client.Stylesheets;
|
2021-06-19 13:25:05 +02:00
|
|
|
using Content.Shared.Atmos.Components;
|
2020-08-08 18:24:41 +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-19 13:25:05 +02:00
|
|
|
namespace Content.Client.Atmos.Components
|
2020-08-08 18:24:41 +02:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2022-02-16 00:23:23 -07:00
|
|
|
internal sealed class GasAnalyzerComponent : SharedGasAnalyzerComponent, IItemStatus
|
2020-08-08 18:24:41 +02:00
|
|
|
{
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
|
2021-03-26 17:10:31 -07:00
|
|
|
[ViewVariables] private GasAnalyzerDanger Danger { get; set; }
|
2020-08-08 18:24:41 +02:00
|
|
|
|
|
|
|
|
Control IItemStatus.MakeControl()
|
|
|
|
|
{
|
|
|
|
|
return new StatusControl(this);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-26 17:10:31 -07:00
|
|
|
/// <inheritdoc />
|
2021-03-10 14:48:29 +01:00
|
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
2020-08-08 18:24:41 +02:00
|
|
|
{
|
2020-11-26 14:33:31 +01:00
|
|
|
if (curState is not GasAnalyzerComponentState state)
|
2020-08-08 18:24:41 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Danger = state.Danger;
|
|
|
|
|
_uiUpdateNeeded = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private sealed class StatusControl : Control
|
|
|
|
|
{
|
|
|
|
|
private readonly GasAnalyzerComponent _parent;
|
|
|
|
|
private readonly RichTextLabel _label;
|
|
|
|
|
|
|
|
|
|
public StatusControl(GasAnalyzerComponent parent)
|
|
|
|
|
{
|
|
|
|
|
_parent = parent;
|
|
|
|
|
_label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
|
|
|
|
|
AddChild(_label);
|
|
|
|
|
|
2022-02-13 11:18:18 +13:00
|
|
|
Update();
|
2020-08-08 18:24:41 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-26 17:10:31 -07:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
protected override void FrameUpdate(FrameEventArgs args)
|
2020-08-08 18:24:41 +02:00
|
|
|
{
|
2021-03-26 17:10:31 -07:00
|
|
|
base.FrameUpdate(args);
|
2020-08-08 18:24:41 +02:00
|
|
|
|
|
|
|
|
if (!_parent._uiUpdateNeeded)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-13 11:18:18 +13:00
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update()
|
|
|
|
|
{
|
2020-08-08 18:24:41 +02:00
|
|
|
_parent._uiUpdateNeeded = false;
|
2021-03-10 14:48:29 +01:00
|
|
|
|
2020-08-08 18:24:41 +02:00
|
|
|
var color = _parent.Danger switch
|
|
|
|
|
{
|
|
|
|
|
GasAnalyzerDanger.Warning => "orange",
|
|
|
|
|
GasAnalyzerDanger.Hazard => "red",
|
|
|
|
|
_ => "green",
|
|
|
|
|
};
|
2021-03-10 14:48:29 +01:00
|
|
|
|
2021-03-26 17:10:31 -07:00
|
|
|
_label.SetMarkup(Loc.GetString("itemstatus-pressure-warn", ("color", color), ("danger", _parent.Danger)));
|
2020-08-08 18:24:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|