Files
crystall-punk-14/Content.Client/Tools/Components/WelderComponent.cs

82 lines
2.7 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.Tool;
2020-05-11 15:26:07 +02:00
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
using Robust.Shared.GameStates;
2020-05-11 15:26:07 +02:00
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]
[NetworkedComponent()]
2020-05-19 13:55:52 +02:00
public class WelderComponent : SharedToolComponent, IItemStatus
2020-05-11 15:26:07 +02:00
{
public override string Name => "Welder";
2020-05-19 13:55:52 +02:00
private ToolQuality _behavior;
2020-05-11 15:26:07 +02:00
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
[ViewVariables] public float FuelCapacity { get; private set; }
[ViewVariables] public float Fuel { get; private set; }
[ViewVariables] public bool Activated { get; private set; }
2020-05-19 13:55:52 +02:00
[ViewVariables] public override ToolQuality Qualities => _behavior;
2020-05-11 15:26:07 +02:00
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
2020-05-11 15:26:07 +02:00
{
base.HandleComponentState(curState, nextState);
if (curState is not WelderComponentState weld)
2020-05-11 15:26:07 +02:00
return;
FuelCapacity = weld.FuelCapacity;
Fuel = weld.Fuel;
Activated = weld.Activated;
2020-05-19 13:55:52 +02:00
_behavior = weld.Quality;
2020-05-11 15:26:07 +02:00
_uiUpdateNeeded = true;
}
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);
parent._uiUpdateNeeded = true;
}
/// <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)
{
return;
}
_parent._uiUpdateNeeded = false;
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
}
}
}
}