Predict Injector (syringes), cleanup (#25235)

At least the mode/transfer amount logic. Actual transfer logic needs Bloodstream which I didn't wanna move into shared.
This commit is contained in:
Pieter-Jan Briers
2024-02-15 00:05:01 +01:00
committed by GitHub
parent d0c24f9aff
commit 6d8be538c9
11 changed files with 613 additions and 642 deletions

View File

@@ -1,21 +0,0 @@
using Content.Shared.Chemistry.Components;
using Content.Shared.FixedPoint;
namespace Content.Client.Chemistry.Components
{
/// <summary>
/// Client behavior for injectors & syringes. Used for item status on injectors
/// </summary>
[RegisterComponent]
public sealed partial class InjectorComponent : SharedInjectorComponent
{
[ViewVariables]
public FixedPoint2 CurrentVolume;
[ViewVariables]
public FixedPoint2 TotalVolume;
[ViewVariables]
public InjectorToggleMode CurrentMode;
[ViewVariables(VVAccess.ReadWrite)]
public bool UiUpdateNeeded;
}
}

View File

@@ -2,34 +2,21 @@ using Content.Client.Chemistry.Components;
using Content.Client.Chemistry.UI;
using Content.Client.Items;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
using Robust.Shared.GameStates;
namespace Content.Client.Chemistry.EntitySystems;
public sealed class InjectorSystem : EntitySystem
public sealed class InjectorSystem : SharedInjectorSystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<InjectorComponent, ComponentHandleState>(OnHandleInjectorState);
Subs.ItemStatus<InjectorComponent>(ent => new InjectorStatusControl(ent));
Subs.ItemStatus<InjectorComponent>(ent => new InjectorStatusControl(ent, SolutionContainers));
SubscribeLocalEvent<HyposprayComponent, ComponentHandleState>(OnHandleHyposprayState);
Subs.ItemStatus<HyposprayComponent>(ent => new HyposprayStatusControl(ent));
}
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 OnHandleHyposprayState(EntityUid uid, HyposprayComponent component, ref ComponentHandleState args)
{
if (args.Current is not HyposprayComponentState cState)

View File

@@ -1,7 +1,7 @@
using Content.Client.Chemistry.Components;
using Content.Client.Message;
using Content.Client.Stylesheets;
using Content.Shared.Chemistry.Components;
using Content.Shared.Chemistry.EntitySystems;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
@@ -10,40 +10,37 @@ namespace Content.Client.Chemistry.UI;
public sealed class InjectorStatusControl : Control
{
private readonly InjectorComponent _parent;
private readonly Entity<InjectorComponent> _parent;
private readonly SharedSolutionContainerSystem _solutionContainers;
private readonly RichTextLabel _label;
public InjectorStatusControl(InjectorComponent parent)
public InjectorStatusControl(Entity<InjectorComponent> parent, SharedSolutionContainerSystem solutionContainers)
{
_parent = parent;
_solutionContainers = solutionContainers;
_label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
AddChild(_label);
Update();
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (!_parent.UiUpdateNeeded)
if (!_solutionContainers.TryGetSolution(_parent.Owner, InjectorComponent.SolutionName, out _, out var solution))
return;
Update();
}
public void Update()
{
_parent.UiUpdateNeeded = false;
//Update current volume and injector state
var modeStringLocalized = _parent.CurrentMode switch
// Update current volume and injector state
var modeStringLocalized = Loc.GetString(_parent.Comp.ToggleState switch
{
SharedInjectorComponent.InjectorToggleMode.Draw => Loc.GetString("injector-draw-text"),
SharedInjectorComponent.InjectorToggleMode.Inject => Loc.GetString("injector-inject-text"),
_ => Loc.GetString("injector-invalid-injector-toggle-mode")
};
InjectorToggleMode.Draw => "injector-draw-text",
InjectorToggleMode.Inject => "injector-inject-text",
_ => "injector-invalid-injector-toggle-mode"
});
_label.SetMarkup(Loc.GetString("injector-volume-label",
("currentVolume", _parent.CurrentVolume),
("totalVolume", _parent.TotalVolume),
("modeString", modeStringLocalized)));
("currentVolume", solution.Volume),
("totalVolume", solution.MaxVolume),
("modeString", modeStringLocalized),
("transferVolume", _parent.Comp.TransferAmount)));
}
}