ImplanterStatusControl.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Content.Client.Message;
  2. using Content.Client.Stylesheets;
  3. using Content.Client.UserInterface.Controls;
  4. using Content.Shared.Implants.Components;
  5. using Robust.Client.UserInterface;
  6. using Robust.Client.UserInterface.Controls;
  7. using Robust.Shared.Prototypes;
  8. using Robust.Shared.Timing;
  9. namespace Content.Client.Implants.UI;
  10. public sealed class ImplanterStatusControl : Control
  11. {
  12. [Dependency] private readonly IPrototypeManager _prototype = default!;
  13. private readonly ImplanterComponent _parent;
  14. private readonly RichTextLabel _label;
  15. public ImplanterStatusControl(ImplanterComponent parent)
  16. {
  17. IoCManager.InjectDependencies(this);
  18. _parent = parent;
  19. _label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
  20. _label.MaxWidth = 350;
  21. AddChild(new ClipControl { Children = { _label } });
  22. Update();
  23. }
  24. protected override void FrameUpdate(FrameEventArgs args)
  25. {
  26. base.FrameUpdate(args);
  27. if (!_parent.UiUpdateNeeded)
  28. return;
  29. Update();
  30. }
  31. private void Update()
  32. {
  33. _parent.UiUpdateNeeded = false;
  34. var modeStringLocalized = _parent.CurrentMode switch
  35. {
  36. ImplanterToggleMode.Draw => Loc.GetString("implanter-draw-text"),
  37. ImplanterToggleMode.Inject => Loc.GetString("implanter-inject-text"),
  38. _ => Loc.GetString("injector-invalid-injector-toggle-mode")
  39. };
  40. if (_parent.CurrentMode == ImplanterToggleMode.Draw)
  41. {
  42. string implantName = _parent.DeimplantChosen != null
  43. ? (_prototype.TryIndex(_parent.DeimplantChosen.Value, out EntityPrototype? implantProto) ? implantProto.Name : Loc.GetString("implanter-empty-text"))
  44. : Loc.GetString("implanter-empty-text");
  45. _label.SetMarkup(Loc.GetString("implanter-label-draw",
  46. ("implantName", implantName),
  47. ("modeString", modeStringLocalized)));
  48. }
  49. else
  50. {
  51. var implantName = _parent.ImplanterSlot.HasItem
  52. ? _parent.ImplantData.Item1
  53. : Loc.GetString("implanter-empty-text");
  54. _label.SetMarkup(Loc.GetString("implanter-label-inject",
  55. ("implantName", implantName),
  56. ("modeString", modeStringLocalized)));
  57. }
  58. }
  59. }