WelderStatusControl.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Content.Client.Items.UI;
  2. using Content.Client.Message;
  3. using Content.Client.Stylesheets;
  4. using Content.Shared.FixedPoint;
  5. using Content.Shared.Tools.Components;
  6. using Content.Shared.Tools.Systems;
  7. using Robust.Client.UserInterface.Controls;
  8. namespace Content.Client.Tools.UI;
  9. public sealed class WelderStatusControl : PollingItemStatusControl<WelderStatusControl.Data>
  10. {
  11. private readonly Entity<WelderComponent> _parent;
  12. private readonly IEntityManager _entityManager;
  13. private readonly SharedToolSystem _toolSystem;
  14. private readonly RichTextLabel _label;
  15. public WelderStatusControl(Entity<WelderComponent> parent, IEntityManager entityManager, SharedToolSystem toolSystem)
  16. {
  17. _parent = parent;
  18. _entityManager = entityManager;
  19. _toolSystem = toolSystem;
  20. _label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
  21. AddChild(_label);
  22. UpdateDraw();
  23. }
  24. protected override Data PollData()
  25. {
  26. var (fuel, capacity) = _toolSystem.GetWelderFuelAndCapacity(_parent, _parent.Comp);
  27. return new Data(fuel, capacity, _parent.Comp.Enabled);
  28. }
  29. protected override void Update(in Data data)
  30. {
  31. _label.SetMarkup(Loc.GetString("welder-component-on-examine-detailed-message",
  32. ("colorName", data.Fuel < data.FuelCapacity / 4f ? "darkorange" : "orange"),
  33. ("fuelLeft", data.Fuel),
  34. ("fuelCapacity", data.FuelCapacity),
  35. ("status", Loc.GetString(data.Lit ? "welder-component-on-examine-welder-lit-message" : "welder-component-on-examine-welder-not-lit-message"))));
  36. }
  37. public record struct Data(FixedPoint2 Fuel, FixedPoint2 FuelCapacity, bool Lit);
  38. }