diff --git a/Content.Client/Chemistry/Components/HyposprayComponent.cs b/Content.Client/Chemistry/Components/HyposprayComponent.cs index 3756497bc4..0010270b92 100644 --- a/Content.Client/Chemistry/Components/HyposprayComponent.cs +++ b/Content.Client/Chemistry/Components/HyposprayComponent.cs @@ -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.Reagent; 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 { [RegisterComponent] - public sealed class HyposprayComponent : SharedHyposprayComponent, IItemStatus + public sealed class HyposprayComponent : SharedHyposprayComponent { - [ViewVariables] private FixedPoint2 CurrentVolume { get; set; } - [ViewVariables] private FixedPoint2 TotalVolume { get; set; } - [ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded; - - public override void HandleComponentState(ComponentState? curState, ComponentState? nextState) - { - 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(); - } - - /// - 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))); - } - } + [ViewVariables] + public FixedPoint2 CurrentVolume; + [ViewVariables] + public FixedPoint2 TotalVolume; + [ViewVariables(VVAccess.ReadWrite)] + public bool UiUpdateNeeded; } } diff --git a/Content.Client/Chemistry/Components/InjectorComponent.cs b/Content.Client/Chemistry/Components/InjectorComponent.cs index 4a6864cad2..5a7c07315e 100644 --- a/Content.Client/Chemistry/Components/InjectorComponent.cs +++ b/Content.Client/Chemistry/Components/InjectorComponent.cs @@ -17,74 +17,15 @@ namespace Content.Client.Chemistry.Components /// Client behavior for injectors & syringes. Used for item status on injectors /// [RegisterComponent] - public sealed class InjectorComponent : SharedInjectorComponent, IItemStatus + public sealed class InjectorComponent : SharedInjectorComponent { - [ViewVariables] private FixedPoint2 CurrentVolume { get; set; } - [ViewVariables] private FixedPoint2 TotalVolume { get; set; } - [ViewVariables] private InjectorToggleMode CurrentMode { get; set; } - [ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded; - - //Add/remove item status code - Control IItemStatus.MakeControl() => new StatusControl(this); - void IItemStatus.DestroyControl(Control control) { } - - //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; - } - - /// - /// Item status control for injectors - /// - 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))); - } - } + [ViewVariables] + public FixedPoint2 CurrentVolume; + [ViewVariables] + public FixedPoint2 TotalVolume; + [ViewVariables] + public InjectorToggleMode CurrentMode; + [ViewVariables(VVAccess.ReadWrite)] + public bool UiUpdateNeeded; } } diff --git a/Content.Client/Chemistry/EntitySystems/InjectorSystem.cs b/Content.Client/Chemistry/EntitySystems/InjectorSystem.cs new file mode 100644 index 0000000000..eeca31220f --- /dev/null +++ b/Content.Client/Chemistry/EntitySystems/InjectorSystem.cs @@ -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(OnHandleInjectorState); + SubscribeLocalEvent(OnItemInjectorStatus); + SubscribeLocalEvent(OnHandleHyposprayState); + SubscribeLocalEvent(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)); + } +} diff --git a/Content.Client/Chemistry/UI/HyposprayStatusControl.cs b/Content.Client/Chemistry/UI/HyposprayStatusControl.cs new file mode 100644 index 0000000000..bd85cd546c --- /dev/null +++ b/Content.Client/Chemistry/UI/HyposprayStatusControl.cs @@ -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))); + } +} diff --git a/Content.Client/Chemistry/UI/InjectorStatusControl.cs b/Content.Client/Chemistry/UI/InjectorStatusControl.cs new file mode 100644 index 0000000000..f772320168 --- /dev/null +++ b/Content.Client/Chemistry/UI/InjectorStatusControl.cs @@ -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))); + } +} diff --git a/Content.Client/GPS/Components/HandheldGPSComponent.cs b/Content.Client/GPS/Components/HandheldGPSComponent.cs new file mode 100644 index 0000000000..987211ac34 --- /dev/null +++ b/Content.Client/GPS/Components/HandheldGPSComponent.cs @@ -0,0 +1,9 @@ +using Content.Shared.GPS; + +namespace Content.Client.GPS.Components +{ + [RegisterComponent] + public sealed class HandheldGPSComponent : SharedHandheldGPSComponent + { + } +} diff --git a/Content.Client/GPS/HandheldGPSComponent.cs b/Content.Client/GPS/HandheldGPSComponent.cs deleted file mode 100644 index 3d216d4d4c..0000000000 --- a/Content.Client/GPS/HandheldGPSComponent.cs +++ /dev/null @@ -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(); - _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(_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))); - } - } - } -} diff --git a/Content.Client/GPS/Systems/HandheldGpsSystem.cs b/Content.Client/GPS/Systems/HandheldGpsSystem.cs new file mode 100644 index 0000000000..5bc92f0c28 --- /dev/null +++ b/Content.Client/GPS/Systems/HandheldGpsSystem.cs @@ -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(OnItemStatus); + } + + private void OnItemStatus(EntityUid uid, HandheldGPSComponent component, ItemStatusCollectMessage args) + { + args.Controls.Add(new HandheldGpsStatusControl(component)); + } +} diff --git a/Content.Client/GPS/UI/HandheldGpsStatusControl.cs b/Content.Client/GPS/UI/HandheldGpsStatusControl.cs new file mode 100644 index 0000000000..2b703105ea --- /dev/null +++ b/Content.Client/GPS/UI/HandheldGpsStatusControl.cs @@ -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(); + _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))); + } +} diff --git a/Content.Client/Items/Components/IItemStatus.cs b/Content.Client/Items/Components/IItemStatus.cs deleted file mode 100644 index 67a1180568..0000000000 --- a/Content.Client/Items/Components/IItemStatus.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Robust.Client.UserInterface; - -namespace Content.Client.Items.Components -{ - /// - /// Allows a component to provide status tooltips next to the hands interface. - /// - public interface IItemStatus - { - /// - /// Called to get a control that represents the status for this component. - /// - /// - /// The control to render as status. - /// - [Obsolete("Use ItemStatusCollectMessage")] - public Control MakeControl(); - - /// - /// Called when the item no longer needs this status (say, dropped from hand) - /// - /// - /// - /// Useful to allow you to drop the control for the GC, if you need to. - /// - /// - /// Note that this may be called after a second invocation of (for example if the user switches the item between two hands). - /// - /// - [Obsolete("Use ItemStatusCollectMessage")] - public void DestroyControl(Control control) - { - } - } -} diff --git a/Content.Client/Items/UI/ItemStatusPanel.cs b/Content.Client/Items/UI/ItemStatusPanel.cs index 99d55445b4..31afcbd36d 100644 --- a/Content.Client/Items/UI/ItemStatusPanel.cs +++ b/Content.Client/Items/UI/ItemStatusPanel.cs @@ -1,4 +1,3 @@ -using Content.Client.Items.Components; using Content.Client.Resources; using Content.Client.Stylesheets; using Content.Shared.Hands.Components; @@ -17,9 +16,6 @@ namespace Content.Client.Items.UI { [Dependency] private readonly IEntityManager _entityManager = default!; - [ViewVariables] - private readonly List<(IItemStatus, Control)> _activeStatusComponents = new(); - [ViewVariables] private readonly Label _itemNameLabel; [ViewVariables] @@ -166,13 +162,6 @@ namespace Content.Client.Items.UI private void ClearOldStatus() { _statusContents.RemoveAllChildren(); - - foreach (var (itemStatus, control) in _activeStatusComponents) - { - itemStatus.DestroyControl(control); - } - - _activeStatusComponents.Clear(); } private void BuildNewEntityStatus() @@ -181,14 +170,6 @@ namespace Content.Client.Items.UI ClearOldStatus(); - foreach (var statusComponent in _entityManager.GetComponents(_entity!.Value)) - { - var control = statusComponent.MakeControl(); - _statusContents.AddChild(control); - - _activeStatusComponents.Add((statusComponent, control)); - } - var collectMsg = new ItemStatusCollectMessage(); _entityManager.EventBus.RaiseLocalEvent(_entity!.Value, collectMsg, true); diff --git a/Content.Client/Stack/StackComponent.cs b/Content.Client/Stack/StackComponent.cs index 8bf098de64..094179ba43 100644 --- a/Content.Client/Stack/StackComponent.cs +++ b/Content.Client/Stack/StackComponent.cs @@ -8,44 +8,11 @@ using Robust.Shared.Timing; namespace Content.Client.Stack { - [RegisterComponent, Access(typeof(StackSystem), typeof(StatusControl))] + [RegisterComponent, Access(typeof(StackSystem), typeof(StackStatusControl))] [ComponentReference(typeof(SharedStackComponent))] - public sealed class StackComponent : SharedStackComponent, IItemStatus + public sealed class StackComponent : SharedStackComponent { [ViewVariables] 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))); - } - } } } diff --git a/Content.Client/Stack/StackStatusControl.cs b/Content.Client/Stack/StackStatusControl.cs new file mode 100644 index 0000000000..c0254df202 --- /dev/null +++ b/Content.Client/Stack/StackStatusControl.cs @@ -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))); + } +} diff --git a/Content.Client/Stack/StackSystem.cs b/Content.Client/Stack/StackSystem.cs index 97eef22b93..ced790c2de 100644 --- a/Content.Client/Stack/StackSystem.cs +++ b/Content.Client/Stack/StackSystem.cs @@ -1,3 +1,4 @@ +using Content.Client.Items; using Content.Shared.Stacks; using JetBrains.Annotations; @@ -6,6 +7,17 @@ namespace Content.Client.Stack [UsedImplicitly] public sealed class StackSystem : SharedStackSystem { + public override void Initialize() + { + base.Initialize(); + SubscribeLocalEvent(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) { if (!Resolve(uid, ref component)) diff --git a/Content.Client/Tools/Components/WelderComponent.cs b/Content.Client/Tools/Components/WelderComponent.cs index a42d67c08f..e69814a9d1 100644 --- a/Content.Client/Tools/Components/WelderComponent.cs +++ b/Content.Client/Tools/Components/WelderComponent.cs @@ -1,20 +1,10 @@ -using System; -using Content.Client.Items.Components; -using Content.Client.Message; -using Content.Client.Stylesheets; +using Content.Client.Tools.UI; 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 { - [RegisterComponent, Access(typeof(ToolSystem), typeof(StatusControl))] - public sealed class WelderComponent : SharedWelderComponent, IItemStatus + [RegisterComponent, Access(typeof(ToolSystem), typeof(WelderStatusControl))] + public sealed class WelderComponent : SharedWelderComponent { [ViewVariables(VVAccess.ReadWrite)] public bool UiUpdateNeeded { get; set; } @@ -24,49 +14,5 @@ namespace Content.Client.Tools.Components [ViewVariables] 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(); - } - - /// - 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")))); - } - } } } diff --git a/Content.Client/Tools/ToolSystem.cs b/Content.Client/Tools/ToolSystem.cs index 7c59ed7d6c..db56149f79 100644 --- a/Content.Client/Tools/ToolSystem.cs +++ b/Content.Client/Tools/ToolSystem.cs @@ -1,5 +1,6 @@ using Content.Client.Items; using Content.Client.Tools.Components; +using Content.Client.Tools.UI; using Content.Shared.Tools; using Content.Shared.Tools.Components; using Robust.Client.GameObjects; @@ -14,6 +15,7 @@ namespace Content.Client.Tools base.Initialize(); SubscribeLocalEvent(OnWelderHandleState); + SubscribeLocalEvent(OnWelderGetStatusMessage); SubscribeLocalEvent(OnGetStatusMessage); } @@ -45,6 +47,11 @@ namespace Content.Client.Tools 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) { if (args.Current is not WelderComponentState state) diff --git a/Content.Client/Tools/UI/WelderStatusControl.cs b/Content.Client/Tools/UI/WelderStatusControl.cs new file mode 100644 index 0000000000..c8d4df2b8f --- /dev/null +++ b/Content.Client/Tools/UI/WelderStatusControl.cs @@ -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(); + } + + /// + 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")))); + } +} diff --git a/Content.Shared/Chemistry/Components/SharedHyposprayComponent.cs b/Content.Shared/Chemistry/Components/SharedHyposprayComponent.cs index c13981fc40..59d3192cfb 100644 --- a/Content.Shared/Chemistry/Components/SharedHyposprayComponent.cs +++ b/Content.Shared/Chemistry/Components/SharedHyposprayComponent.cs @@ -9,18 +9,18 @@ namespace Content.Shared.Chemistry.Components { [DataField("solutionName")] public string SolutionName = "hypospray"; + } - [Serializable, NetSerializable] - protected sealed class HyposprayComponentState : ComponentState + [Serializable, NetSerializable] + public sealed class HyposprayComponentState : ComponentState + { + public FixedPoint2 CurVolume { get; } + public FixedPoint2 MaxVolume { get; } + + public HyposprayComponentState(FixedPoint2 curVolume, FixedPoint2 maxVolume) { - public FixedPoint2 CurVolume { get; } - public FixedPoint2 MaxVolume { get; } - - public HyposprayComponentState(FixedPoint2 curVolume, FixedPoint2 maxVolume) - { - CurVolume = curVolume; - MaxVolume = maxVolume; - } + CurVolume = curVolume; + MaxVolume = maxVolume; } } }