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

81 lines
2.6 KiB
C#
Raw Normal View History

2020-05-11 15:26:07 +02:00
using System;
using Content.Client.UserInterface.Stylesheets;
using Content.Client.Utility;
using Content.Shared.GameObjects;
using Content.Shared.GameObjects.Components.Interactable;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
namespace Content.Client.GameObjects.Components.Interactable
{
[RegisterComponent]
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";
public override uint? NetID => ContentNetIDs.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 ExposeData(ObjectSerializer serializer)
{
}
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
{
if (!(curState is WelderComponentState weld))
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;
}
protected override void Update(FrameEventArgs args)
{
base.Update(args);
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
2020-05-19 13:55:52 +02:00
_label.SetMarkup(Loc.GetString("Fuel: [color={0}]{1}/{2}[/color]",
fuel < fuelCap / 4f ? "darkorange" : "orange", Math.Round(fuel), fuelCap));
2020-05-11 15:26:07 +02:00
}
}
}
}