Remove IItemStatus (#11055)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
/// <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)));
|
||||
}
|
||||
}
|
||||
[ViewVariables]
|
||||
public FixedPoint2 CurrentVolume;
|
||||
[ViewVariables]
|
||||
public FixedPoint2 TotalVolume;
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool UiUpdateNeeded;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,74 +17,15 @@ namespace Content.Client.Chemistry.Components
|
||||
/// Client behavior for injectors & syringes. Used for item status on injectors
|
||||
/// </summary>
|
||||
[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;
|
||||
}
|
||||
|
||||
/// <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)));
|
||||
}
|
||||
}
|
||||
[ViewVariables]
|
||||
public FixedPoint2 CurrentVolume;
|
||||
[ViewVariables]
|
||||
public FixedPoint2 TotalVolume;
|
||||
[ViewVariables]
|
||||
public InjectorToggleMode CurrentMode;
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool UiUpdateNeeded;
|
||||
}
|
||||
}
|
||||
|
||||
52
Content.Client/Chemistry/EntitySystems/InjectorSystem.cs
Normal file
52
Content.Client/Chemistry/EntitySystems/InjectorSystem.cs
Normal 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));
|
||||
}
|
||||
}
|
||||
42
Content.Client/Chemistry/UI/HyposprayStatusControl.cs
Normal file
42
Content.Client/Chemistry/UI/HyposprayStatusControl.cs
Normal 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)));
|
||||
}
|
||||
}
|
||||
49
Content.Client/Chemistry/UI/InjectorStatusControl.cs
Normal file
49
Content.Client/Chemistry/UI/InjectorStatusControl.cs
Normal 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)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user