1
0

InjectorStatusControl.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using Content.Client.Message;
  2. using Content.Client.Stylesheets;
  3. using Content.Shared.Chemistry.Components;
  4. using Content.Shared.Chemistry.EntitySystems;
  5. using Content.Shared.FixedPoint;
  6. using Robust.Client.UserInterface;
  7. using Robust.Client.UserInterface.Controls;
  8. using Robust.Shared.Timing;
  9. namespace Content.Client.Chemistry.UI;
  10. public sealed class InjectorStatusControl : Control
  11. {
  12. private readonly Entity<InjectorComponent> _parent;
  13. private readonly SharedSolutionContainerSystem _solutionContainers;
  14. private readonly RichTextLabel _label;
  15. private FixedPoint2 PrevVolume;
  16. private FixedPoint2 PrevMaxVolume;
  17. private FixedPoint2 PrevTransferAmount;
  18. private InjectorToggleMode PrevToggleState;
  19. public InjectorStatusControl(Entity<InjectorComponent> parent, SharedSolutionContainerSystem solutionContainers)
  20. {
  21. _parent = parent;
  22. _solutionContainers = solutionContainers;
  23. _label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
  24. AddChild(_label);
  25. }
  26. protected override void FrameUpdate(FrameEventArgs args)
  27. {
  28. base.FrameUpdate(args);
  29. if (!_solutionContainers.TryGetSolution(_parent.Owner, _parent.Comp.SolutionName, out _, out var solution))
  30. return;
  31. // only updates the UI if any of the details are different than they previously were
  32. if (PrevVolume == solution.Volume
  33. && PrevMaxVolume == solution.MaxVolume
  34. && PrevTransferAmount == _parent.Comp.TransferAmount
  35. && PrevToggleState == _parent.Comp.ToggleState)
  36. return;
  37. PrevVolume = solution.Volume;
  38. PrevMaxVolume = solution.MaxVolume;
  39. PrevTransferAmount = _parent.Comp.TransferAmount;
  40. PrevToggleState = _parent.Comp.ToggleState;
  41. // Update current volume and injector state
  42. var modeStringLocalized = Loc.GetString(_parent.Comp.ToggleState switch
  43. {
  44. InjectorToggleMode.Draw => "injector-draw-text",
  45. InjectorToggleMode.Inject => "injector-inject-text",
  46. _ => "injector-invalid-injector-toggle-mode"
  47. });
  48. _label.SetMarkup(Loc.GetString("injector-volume-label",
  49. ("currentVolume", solution.Volume),
  50. ("totalVolume", solution.MaxVolume),
  51. ("modeString", modeStringLocalized),
  52. ("transferVolume", _parent.Comp.TransferAmount)));
  53. }
  54. }