2020-05-11 15:26:07 +02:00
|
|
|
using System;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.Items.Components;
|
|
|
|
|
using Content.Client.Message;
|
|
|
|
|
using Content.Client.Stylesheets;
|
2021-10-07 13:01:27 +02:00
|
|
|
using Content.Shared.Tools.Components;
|
2020-05-11 15:26:07 +02:00
|
|
|
using Robust.Client.UserInterface;
|
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
2021-10-07 13:01:27 +02:00
|
|
|
using Robust.Shared.Analyzers;
|
2020-05-11 15:26:07 +02:00
|
|
|
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.Tools.Components
|
2020-05-11 15:26:07 +02:00
|
|
|
{
|
2021-10-07 13:01:27 +02:00
|
|
|
[RegisterComponent, Friend(typeof(ToolSystem), typeof(StatusControl))]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class WelderComponent : SharedWelderComponent, IItemStatus
|
2020-05-11 15:26:07 +02:00
|
|
|
{
|
2021-10-07 13:01:27 +02:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public bool UiUpdateNeeded { get; set; }
|
2020-05-11 15:26:07 +02:00
|
|
|
|
2021-10-07 13:01:27 +02:00
|
|
|
[ViewVariables]
|
|
|
|
|
public float FuelCapacity { get; set; }
|
2020-05-11 15:26:07 +02:00
|
|
|
|
2021-10-07 13:01:27 +02:00
|
|
|
[ViewVariables]
|
|
|
|
|
public float Fuel { get; set; }
|
2020-05-11 15:26:07 +02:00
|
|
|
|
|
|
|
|
public Control MakeControl() => new StatusControl(this);
|
|
|
|
|
|
|
|
|
|
private sealed class StatusControl : Control
|
|
|
|
|
{
|
|
|
|
|
private readonly WelderComponent _parent;
|
|
|
|
|
private readonly RichTextLabel _label;
|
|
|
|
|
|
|
|
|
|
public StatusControl(WelderComponent parent)
|
|
|
|
|
{
|
|
|
|
|
_parent = parent;
|
|
|
|
|
_label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}};
|
|
|
|
|
AddChild(_label);
|
|
|
|
|
|
2022-02-13 11:18:18 +13:00
|
|
|
UpdateDraw();
|
2020-05-11 15:26:07 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-26 17:10:31 -07:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
protected override void FrameUpdate(FrameEventArgs args)
|
2020-05-11 15:26:07 +02:00
|
|
|
{
|
2021-03-26 17:10:31 -07:00
|
|
|
base.FrameUpdate(args);
|
2020-05-11 15:26:07 +02:00
|
|
|
|
2021-10-07 13:01:27 +02:00
|
|
|
if (!_parent.UiUpdateNeeded)
|
2020-05-11 15:26:07 +02:00
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-02-13 11:18:18 +13:00
|
|
|
Update();
|
|
|
|
|
}
|
2020-05-11 15:26:07 +02:00
|
|
|
|
2022-02-13 11:18:18 +13:00
|
|
|
public void Update()
|
|
|
|
|
{
|
2021-10-07 13:01:27 +02:00
|
|
|
_parent.UiUpdateNeeded = false;
|
2020-05-11 15:26:07 +02:00
|
|
|
|
2020-05-19 13:55:52 +02:00
|
|
|
var fuelCap = _parent.FuelCapacity;
|
|
|
|
|
var fuel = _parent.Fuel;
|
2020-05-11 15:26:07 +02:00
|
|
|
|
2021-06-21 02:13:54 +02:00
|
|
|
_label.SetMarkup(Loc.GetString("welder-component-on-examine-detailed-message",
|
|
|
|
|
("colorName", fuel < fuelCap / 4f ? "darkorange" : "orange"),
|
|
|
|
|
("fuelLeft", Math.Round(fuel)),
|
|
|
|
|
("fuelCapacity", fuelCap)));
|
2020-05-11 15:26:07 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|