HyposprayStatusControl.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 HyposprayStatusControl : Control
  11. {
  12. private readonly Entity<HyposprayComponent> _parent;
  13. private readonly RichTextLabel _label;
  14. private readonly SharedSolutionContainerSystem _solutionContainers;
  15. private FixedPoint2 PrevVolume;
  16. private FixedPoint2 PrevMaxVolume;
  17. private bool PrevOnlyAffectsMobs;
  18. public HyposprayStatusControl(Entity<HyposprayComponent> parent, SharedSolutionContainerSystem solutionContainers)
  19. {
  20. _parent = parent;
  21. _solutionContainers = solutionContainers;
  22. _label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
  23. AddChild(_label);
  24. }
  25. protected override void FrameUpdate(FrameEventArgs args)
  26. {
  27. base.FrameUpdate(args);
  28. if (!_solutionContainers.TryGetSolution(_parent.Owner, _parent.Comp.SolutionName, out _, out var solution))
  29. return;
  30. // only updates the UI if any of the details are different than they previously were
  31. if (PrevVolume == solution.Volume
  32. && PrevMaxVolume == solution.MaxVolume
  33. && PrevOnlyAffectsMobs == _parent.Comp.OnlyAffectsMobs)
  34. return;
  35. PrevVolume = solution.Volume;
  36. PrevMaxVolume = solution.MaxVolume;
  37. PrevOnlyAffectsMobs = _parent.Comp.OnlyAffectsMobs;
  38. var modeStringLocalized = Loc.GetString(_parent.Comp.OnlyAffectsMobs switch
  39. {
  40. false => "hypospray-all-mode-text",
  41. true => "hypospray-mobs-only-mode-text",
  42. });
  43. _label.SetMarkup(Loc.GetString("hypospray-volume-label",
  44. ("currentVolume", solution.Volume),
  45. ("totalVolume", solution.MaxVolume),
  46. ("modeString", modeStringLocalized)));
  47. }
  48. }