Remove IItemStatus (#11055)

This commit is contained in:
Alex Evgrashin
2022-09-11 08:53:17 +02:00
committed by GitHub
parent 61655c18b2
commit 385a52c390
18 changed files with 357 additions and 355 deletions

View File

@@ -1,75 +1,16 @@
using Content.Client.Items.Components;
using Content.Client.Message;
using Content.Client.Stylesheets;
using Content.Shared.Chemistry.Components; using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
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;
namespace Content.Client.Chemistry.Components namespace Content.Client.Chemistry.Components
{ {
[RegisterComponent] [RegisterComponent]
public sealed class HyposprayComponent : SharedHyposprayComponent, IItemStatus public sealed class HyposprayComponent : SharedHyposprayComponent
{ {
[ViewVariables] private FixedPoint2 CurrentVolume { get; set; } [ViewVariables]
[ViewVariables] private FixedPoint2 TotalVolume { get; set; } public FixedPoint2 CurrentVolume;
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded; [ViewVariables]
public FixedPoint2 TotalVolume;
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) [ViewVariables(VVAccess.ReadWrite)]
{ public bool UiUpdateNeeded;
if (curState is not HyposprayComponentState cState)
return;
CurrentVolume = cState.CurVolume;
TotalVolume = cState.MaxVolume;
_uiUpdateNeeded = true;
}
Control IItemStatus.MakeControl()
{
return new StatusControl(this);
}
private sealed class StatusControl : Control
{
private readonly HyposprayComponent _parent;
private readonly RichTextLabel _label;
public StatusControl(HyposprayComponent parent)
{
_parent = parent;
_label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}};
AddChild(_label);
Update();
}
/// <inheritdoc />
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!_parent._uiUpdateNeeded)
{
return;
}
Update();
}
public void Update()
{
_parent._uiUpdateNeeded = false;
_label.SetMarkup(Loc.GetString(
"hypospray-volume-text",
("currentVolume", _parent.CurrentVolume),
("totalVolume", _parent.TotalVolume)));
}
}
} }
} }

View File

@@ -17,74 +17,15 @@ namespace Content.Client.Chemistry.Components
/// Client behavior for injectors & syringes. Used for item status on injectors /// Client behavior for injectors & syringes. Used for item status on injectors
/// </summary> /// </summary>
[RegisterComponent] [RegisterComponent]
public sealed class InjectorComponent : SharedInjectorComponent, IItemStatus public sealed class InjectorComponent : SharedInjectorComponent
{ {
[ViewVariables] private FixedPoint2 CurrentVolume { get; set; } [ViewVariables]
[ViewVariables] private FixedPoint2 TotalVolume { get; set; } public FixedPoint2 CurrentVolume;
[ViewVariables] private InjectorToggleMode CurrentMode { get; set; } [ViewVariables]
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded; public FixedPoint2 TotalVolume;
[ViewVariables]
//Add/remove item status code public InjectorToggleMode CurrentMode;
Control IItemStatus.MakeControl() => new StatusControl(this); [ViewVariables(VVAccess.ReadWrite)]
void IItemStatus.DestroyControl(Control control) { } public bool UiUpdateNeeded;
//Handle net updates
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
if (curState is not InjectorComponentState state)
{
return;
}
CurrentVolume = state.CurrentVolume;
TotalVolume = state.TotalVolume;
CurrentMode = state.CurrentMode;
_uiUpdateNeeded = true;
}
/// <summary>
/// Item status control for injectors
/// </summary>
private sealed class StatusControl : Control
{
private readonly InjectorComponent _parent;
private readonly RichTextLabel _label;
public StatusControl(InjectorComponent parent)
{
_parent = parent;
_label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
AddChild(_label);
Update();
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!_parent._uiUpdateNeeded)
{
return;
}
Update();
}
public void Update()
{
_parent._uiUpdateNeeded = false;
//Update current volume and injector state
var modeStringLocalized = _parent.CurrentMode switch
{
InjectorToggleMode.Draw => Loc.GetString("injector-draw-text"),
InjectorToggleMode.Inject => Loc.GetString("injector-inject-text"),
_ => Loc.GetString("injector-invalid-injector-toggle-mode")
};
_label.SetMarkup(Loc.GetString("injector-volume-label",
("currentVolume", _parent.CurrentVolume),
("totalVolume", _parent.TotalVolume),
("modeString", modeStringLocalized)));
}
}
} }
} }

View File

@@ -0,0 +1,52 @@
using Content.Client.Chemistry.Components;
using Content.Client.Chemistry.UI;
using Content.Client.Items;
using Content.Shared.Chemistry.Components;
using Robust.Shared.GameStates;
namespace Content.Client.Chemistry.EntitySystems;
public sealed class InjectorSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<InjectorComponent, ComponentHandleState>(OnHandleInjectorState);
SubscribeLocalEvent<InjectorComponent, ItemStatusCollectMessage>(OnItemInjectorStatus);
SubscribeLocalEvent<HyposprayComponent, ComponentHandleState>(OnHandleHyposprayState);
SubscribeLocalEvent<HyposprayComponent, ItemStatusCollectMessage>(OnItemHyposprayStatus);
}
private void OnHandleInjectorState(EntityUid uid, InjectorComponent component, ref ComponentHandleState args)
{
if (args.Current is not SharedInjectorComponent.InjectorComponentState state)
{
return;
}
component.CurrentVolume = state.CurrentVolume;
component.TotalVolume = state.TotalVolume;
component.CurrentMode = state.CurrentMode;
component.UiUpdateNeeded = true;
}
private void OnItemInjectorStatus(EntityUid uid, InjectorComponent component, ItemStatusCollectMessage args)
{
args.Controls.Add(new InjectorStatusControl(component));
}
private void OnHandleHyposprayState(EntityUid uid, HyposprayComponent component, ref ComponentHandleState args)
{
if (args.Current is not HyposprayComponentState cState)
return;
component.CurrentVolume = cState.CurVolume;
component.TotalVolume = cState.MaxVolume;
component.UiUpdateNeeded = true;
}
private void OnItemHyposprayStatus(EntityUid uid, HyposprayComponent component, ItemStatusCollectMessage args)
{
args.Controls.Add(new HyposprayStatusControl(component));
}
}

View File

@@ -0,0 +1,42 @@
using Content.Client.Chemistry.Components;
using Content.Client.Message;
using Content.Client.Stylesheets;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
namespace Content.Client.Chemistry.UI;
public sealed class HyposprayStatusControl : Control
{
private readonly HyposprayComponent _parent;
private readonly RichTextLabel _label;
public HyposprayStatusControl(HyposprayComponent parent)
{
_parent = parent;
_label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}};
AddChild(_label);
Update();
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!_parent.UiUpdateNeeded)
return;
Update();
}
public void Update()
{
_parent.UiUpdateNeeded = false;
_label.SetMarkup(Loc.GetString(
"hypospray-volume-text",
("currentVolume", _parent.CurrentVolume),
("totalVolume", _parent.TotalVolume)));
}
}

View File

@@ -0,0 +1,49 @@
using Content.Client.Chemistry.Components;
using Content.Client.Message;
using Content.Client.Stylesheets;
using Content.Shared.Chemistry.Components;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
namespace Content.Client.Chemistry.UI;
public sealed class InjectorStatusControl : Control
{
private readonly InjectorComponent _parent;
private readonly RichTextLabel _label;
public InjectorStatusControl(InjectorComponent parent)
{
_parent = parent;
_label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
AddChild(_label);
Update();
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!_parent.UiUpdateNeeded)
return;
Update();
}
public void Update()
{
_parent.UiUpdateNeeded = false;
//Update current volume and injector state
var modeStringLocalized = _parent.CurrentMode switch
{
SharedInjectorComponent.InjectorToggleMode.Draw => Loc.GetString("injector-draw-text"),
SharedInjectorComponent.InjectorToggleMode.Inject => Loc.GetString("injector-inject-text"),
_ => Loc.GetString("injector-invalid-injector-toggle-mode")
};
_label.SetMarkup(Loc.GetString("injector-volume-label",
("currentVolume", _parent.CurrentVolume),
("totalVolume", _parent.TotalVolume),
("modeString", modeStringLocalized)));
}
}

View File

@@ -0,0 +1,9 @@
using Content.Shared.GPS;
namespace Content.Client.GPS.Components
{
[RegisterComponent]
public sealed class HandheldGPSComponent : SharedHandheldGPSComponent
{
}
}

View File

@@ -1,65 +0,0 @@
using Content.Client.Items.Components;
using Content.Client.Message;
using Content.Client.Stylesheets;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
using Content.Shared.GPS;
namespace Content.Client.GPS
{
[RegisterComponent]
internal sealed class HandheldGPSComponent : SharedHandheldGPSComponent, IItemStatus
{
Control IItemStatus.MakeControl()
{
return new StatusControl(this);
}
private sealed class StatusControl : Control
{
private readonly HandheldGPSComponent _parent;
private readonly RichTextLabel _label;
private float UpdateDif;
private readonly IEntityManager _entMan = default!;
public StatusControl(HandheldGPSComponent parent)
{
_parent = parent;
_entMan = IoCManager.Resolve<IEntityManager>();
_label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
AddChild(_label);
UpdateGPSDetails();
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
UpdateDif += args.DeltaSeconds;
if (UpdateDif < _parent.UpdateRate)
return;
UpdateDif -= _parent.UpdateRate;
UpdateGPSDetails();
}
public void UpdateGPSDetails()
{
string posText = "Error";
if (_entMan.TryGetComponent<TransformComponent>(_parent.Owner, out TransformComponent? transComp))
{
if (transComp.Coordinates != null)
{
var pos = transComp.MapPosition;
var x = (int) pos.X;
var y = (int) pos.Y;
posText = $"({x}, {y})";
}
}
_label.SetMarkup(Loc.GetString("handheld-gps-coordinates-title", ("coordinates", posText)));
}
}
}
}

View File

@@ -0,0 +1,19 @@
using Content.Client.GPS.Components;
using Content.Client.GPS.UI;
using Content.Client.Items;
namespace Content.Client.GPS.Systems;
public sealed class HandheldGpsSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<HandheldGPSComponent, ItemStatusCollectMessage>(OnItemStatus);
}
private void OnItemStatus(EntityUid uid, HandheldGPSComponent component, ItemStatusCollectMessage args)
{
args.Controls.Add(new HandheldGpsStatusControl(component));
}
}

View File

@@ -0,0 +1,51 @@
using Content.Client.GPS.Components;
using Content.Client.Message;
using Content.Client.Stylesheets;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
namespace Content.Client.GPS.UI;
public sealed class HandheldGpsStatusControl : Control
{
private readonly HandheldGPSComponent _parent;
private readonly RichTextLabel _label;
private float _updateDif;
private readonly IEntityManager _entMan;
public HandheldGpsStatusControl(HandheldGPSComponent parent)
{
_parent = parent;
_entMan = IoCManager.Resolve<IEntityManager>();
_label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
AddChild(_label);
UpdateGpsDetails();
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
_updateDif += args.DeltaSeconds;
if (_updateDif < _parent.UpdateRate)
return;
_updateDif -= _parent.UpdateRate;
UpdateGpsDetails();
}
private void UpdateGpsDetails()
{
var posText = "Error";
if (_entMan.TryGetComponent(_parent.Owner, out TransformComponent? transComp))
{
var pos = transComp.MapPosition;
var x = (int) pos.X;
var y = (int) pos.Y;
posText = $"({x}, {y})";
}
_label.SetMarkup(Loc.GetString("handheld-gps-coordinates-title", ("coordinates", posText)));
}
}

View File

@@ -1,35 +0,0 @@
using Robust.Client.UserInterface;
namespace Content.Client.Items.Components
{
/// <summary>
/// Allows a component to provide status tooltips next to the hands interface.
/// </summary>
public interface IItemStatus
{
/// <summary>
/// Called to get a control that represents the status for this component.
/// </summary>
/// <returns>
/// The control to render as status.
/// </returns>
[Obsolete("Use ItemStatusCollectMessage")]
public Control MakeControl();
/// <summary>
/// Called when the item no longer needs this status (say, dropped from hand)
/// </summary>
/// <remarks>
/// <para>
/// Useful to allow you to drop the control for the GC, if you need to.
/// </para>
/// <para>
/// Note that this may be called after a second invocation of <see cref="MakeControl"/> (for example if the user switches the item between two hands).
/// </para>
/// </remarks>
[Obsolete("Use ItemStatusCollectMessage")]
public void DestroyControl(Control control)
{
}
}
}

View File

@@ -1,4 +1,3 @@
using Content.Client.Items.Components;
using Content.Client.Resources; using Content.Client.Resources;
using Content.Client.Stylesheets; using Content.Client.Stylesheets;
using Content.Shared.Hands.Components; using Content.Shared.Hands.Components;
@@ -17,9 +16,6 @@ namespace Content.Client.Items.UI
{ {
[Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IEntityManager _entityManager = default!;
[ViewVariables]
private readonly List<(IItemStatus, Control)> _activeStatusComponents = new();
[ViewVariables] [ViewVariables]
private readonly Label _itemNameLabel; private readonly Label _itemNameLabel;
[ViewVariables] [ViewVariables]
@@ -166,13 +162,6 @@ namespace Content.Client.Items.UI
private void ClearOldStatus() private void ClearOldStatus()
{ {
_statusContents.RemoveAllChildren(); _statusContents.RemoveAllChildren();
foreach (var (itemStatus, control) in _activeStatusComponents)
{
itemStatus.DestroyControl(control);
}
_activeStatusComponents.Clear();
} }
private void BuildNewEntityStatus() private void BuildNewEntityStatus()
@@ -181,14 +170,6 @@ namespace Content.Client.Items.UI
ClearOldStatus(); ClearOldStatus();
foreach (var statusComponent in _entityManager.GetComponents<IItemStatus>(_entity!.Value))
{
var control = statusComponent.MakeControl();
_statusContents.AddChild(control);
_activeStatusComponents.Add((statusComponent, control));
}
var collectMsg = new ItemStatusCollectMessage(); var collectMsg = new ItemStatusCollectMessage();
_entityManager.EventBus.RaiseLocalEvent(_entity!.Value, collectMsg, true); _entityManager.EventBus.RaiseLocalEvent(_entity!.Value, collectMsg, true);

View File

@@ -8,44 +8,11 @@ using Robust.Shared.Timing;
namespace Content.Client.Stack namespace Content.Client.Stack
{ {
[RegisterComponent, Access(typeof(StackSystem), typeof(StatusControl))] [RegisterComponent, Access(typeof(StackSystem), typeof(StackStatusControl))]
[ComponentReference(typeof(SharedStackComponent))] [ComponentReference(typeof(SharedStackComponent))]
public sealed class StackComponent : SharedStackComponent, IItemStatus public sealed class StackComponent : SharedStackComponent
{ {
[ViewVariables] [ViewVariables]
public bool UiUpdateNeeded { get; set; } public bool UiUpdateNeeded { get; set; }
public Control MakeControl()
{
return new StatusControl(this);
}
private sealed class StatusControl : Control
{
private readonly StackComponent _parent;
private readonly RichTextLabel _label;
public StatusControl(StackComponent parent)
{
_parent = parent;
_label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}};
_label.SetMarkup(Loc.GetString("comp-stack-status", ("count", _parent.Count)));
AddChild(_label);
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!_parent.UiUpdateNeeded)
{
return;
}
_parent.UiUpdateNeeded = false;
_label.SetMarkup(Loc.GetString("comp-stack-status", ("count", _parent.Count)));
}
}
} }
} }

View File

@@ -0,0 +1,35 @@
using Content.Client.Message;
using Content.Client.Stylesheets;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
namespace Content.Client.Stack;
public sealed class StackStatusControl : Control
{
private readonly StackComponent _parent;
private readonly RichTextLabel _label;
public StackStatusControl(StackComponent parent)
{
_parent = parent;
_label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}};
_label.SetMarkup(Loc.GetString("comp-stack-status", ("count", _parent.Count)));
AddChild(_label);
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!_parent.UiUpdateNeeded)
{
return;
}
_parent.UiUpdateNeeded = false;
_label.SetMarkup(Loc.GetString("comp-stack-status", ("count", _parent.Count)));
}
}

View File

@@ -1,3 +1,4 @@
using Content.Client.Items;
using Content.Shared.Stacks; using Content.Shared.Stacks;
using JetBrains.Annotations; using JetBrains.Annotations;
@@ -6,6 +7,17 @@ namespace Content.Client.Stack
[UsedImplicitly] [UsedImplicitly]
public sealed class StackSystem : SharedStackSystem public sealed class StackSystem : SharedStackSystem
{ {
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<StackComponent, ItemStatusCollectMessage>(OnItemStatus);
}
private void OnItemStatus(EntityUid uid, StackComponent component, ItemStatusCollectMessage args)
{
args.Controls.Add(new StackStatusControl(component));
}
public override void SetCount(EntityUid uid, int amount, SharedStackComponent? component = null) public override void SetCount(EntityUid uid, int amount, SharedStackComponent? component = null)
{ {
if (!Resolve(uid, ref component)) if (!Resolve(uid, ref component))

View File

@@ -1,20 +1,10 @@
using System; using Content.Client.Tools.UI;
using Content.Client.Items.Components;
using Content.Client.Message;
using Content.Client.Stylesheets;
using Content.Shared.Tools.Components; using Content.Shared.Tools.Components;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Analyzers;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
namespace Content.Client.Tools.Components namespace Content.Client.Tools.Components
{ {
[RegisterComponent, Access(typeof(ToolSystem), typeof(StatusControl))] [RegisterComponent, Access(typeof(ToolSystem), typeof(WelderStatusControl))]
public sealed class WelderComponent : SharedWelderComponent, IItemStatus public sealed class WelderComponent : SharedWelderComponent
{ {
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public bool UiUpdateNeeded { get; set; } public bool UiUpdateNeeded { get; set; }
@@ -24,49 +14,5 @@ namespace Content.Client.Tools.Components
[ViewVariables] [ViewVariables]
public float Fuel { get; set; } public float Fuel { get; set; }
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();
}
/// <inheritdoc />
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!_parent.UiUpdateNeeded)
{
return;
}
Update();
}
public void Update()
{
_parent.UiUpdateNeeded = false;
var fuelCap = _parent.FuelCapacity;
var fuel = _parent.Fuel;
var lit = _parent.Lit;
_label.SetMarkup(Loc.GetString("welder-component-on-examine-detailed-message",
("colorName", fuel < fuelCap / 4f ? "darkorange" : "orange"),
("fuelLeft", Math.Round(fuel, 1)),
("fuelCapacity", fuelCap),
("status", Loc.GetString(lit ? "welder-component-on-examine-welder-lit-message" : "welder-component-on-examine-welder-not-lit-message"))));
}
}
} }
} }

View File

@@ -1,5 +1,6 @@
using Content.Client.Items; using Content.Client.Items;
using Content.Client.Tools.Components; using Content.Client.Tools.Components;
using Content.Client.Tools.UI;
using Content.Shared.Tools; using Content.Shared.Tools;
using Content.Shared.Tools.Components; using Content.Shared.Tools.Components;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
@@ -14,6 +15,7 @@ namespace Content.Client.Tools
base.Initialize(); base.Initialize();
SubscribeLocalEvent<WelderComponent, ComponentHandleState>(OnWelderHandleState); SubscribeLocalEvent<WelderComponent, ComponentHandleState>(OnWelderHandleState);
SubscribeLocalEvent<WelderComponent, ItemStatusCollectMessage>(OnWelderGetStatusMessage);
SubscribeLocalEvent<MultipleToolComponent, ItemStatusCollectMessage>(OnGetStatusMessage); SubscribeLocalEvent<MultipleToolComponent, ItemStatusCollectMessage>(OnGetStatusMessage);
} }
@@ -45,6 +47,11 @@ namespace Content.Client.Tools
args.Controls.Add(new MultipleToolStatusControl(welder)); args.Controls.Add(new MultipleToolStatusControl(welder));
} }
private void OnWelderGetStatusMessage(EntityUid uid, WelderComponent component, ItemStatusCollectMessage args)
{
args.Controls.Add(new WelderStatusControl(component));
}
private void OnWelderHandleState(EntityUid uid, WelderComponent welder, ref ComponentHandleState args) private void OnWelderHandleState(EntityUid uid, WelderComponent welder, ref ComponentHandleState args)
{ {
if (args.Current is not WelderComponentState state) if (args.Current is not WelderComponentState state)

View File

@@ -0,0 +1,50 @@
using Content.Client.Message;
using Content.Client.Stylesheets;
using Content.Client.Tools.Components;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
namespace Content.Client.Tools.UI;
public sealed class WelderStatusControl : Control
{
private readonly WelderComponent _parent;
private readonly RichTextLabel _label;
public WelderStatusControl(WelderComponent parent)
{
_parent = parent;
_label = new RichTextLabel {StyleClasses = {StyleNano.StyleClassItemStatus}};
AddChild(_label);
UpdateDraw();
}
/// <inheritdoc />
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!_parent.UiUpdateNeeded)
{
return;
}
Update();
}
public void Update()
{
_parent.UiUpdateNeeded = false;
var fuelCap = _parent.FuelCapacity;
var fuel = _parent.Fuel;
var lit = _parent.Lit;
_label.SetMarkup(Loc.GetString("welder-component-on-examine-detailed-message",
("colorName", fuel < fuelCap / 4f ? "darkorange" : "orange"),
("fuelLeft", Math.Round(fuel, 1)),
("fuelCapacity", fuelCap),
("status", Loc.GetString(lit ? "welder-component-on-examine-welder-lit-message" : "welder-component-on-examine-welder-not-lit-message"))));
}
}

View File

@@ -9,18 +9,18 @@ namespace Content.Shared.Chemistry.Components
{ {
[DataField("solutionName")] [DataField("solutionName")]
public string SolutionName = "hypospray"; public string SolutionName = "hypospray";
}
[Serializable, NetSerializable] [Serializable, NetSerializable]
protected sealed class HyposprayComponentState : ComponentState public sealed class HyposprayComponentState : ComponentState
{
public FixedPoint2 CurVolume { get; }
public FixedPoint2 MaxVolume { get; }
public HyposprayComponentState(FixedPoint2 curVolume, FixedPoint2 maxVolume)
{ {
public FixedPoint2 CurVolume { get; } CurVolume = curVolume;
public FixedPoint2 MaxVolume { get; } MaxVolume = maxVolume;
public HyposprayComponentState(FixedPoint2 curVolume, FixedPoint2 maxVolume)
{
CurVolume = curVolume;
MaxVolume = maxVolume;
}
} }
} }
} }