Files
OldThink/Content.Client/Tools/Components/WelderComponent.cs

71 lines
2.2 KiB
C#
Raw Normal View History

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;
using Content.Shared.Tools.Components;
2020-05-11 15:26:07 +02:00
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
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
{
[RegisterComponent, Friend(typeof(ToolSystem), typeof(StatusControl))]
public sealed class WelderComponent : SharedWelderComponent, IItemStatus
2020-05-11 15:26:07 +02:00
{
[ViewVariables(VVAccess.ReadWrite)]
public bool UiUpdateNeeded { get; set; }
2020-05-11 15:26:07 +02:00
[ViewVariables]
public float FuelCapacity { get; set; }
2020-05-11 15:26:07 +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);
UpdateDraw();
2020-05-11 15:26:07 +02:00
}
/// <inheritdoc />
protected override void FrameUpdate(FrameEventArgs args)
2020-05-11 15:26:07 +02:00
{
base.FrameUpdate(args);
2020-05-11 15:26:07 +02:00
if (!_parent.UiUpdateNeeded)
2020-05-11 15:26:07 +02:00
{
return;
}
Update();
}
2020-05-11 15:26:07 +02:00
public void Update()
{
_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
_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
}
}
}
}