DoorRemoteStatusControl.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using Content.Client.Message;
  2. using Content.Client.Stylesheets;
  3. using Content.Shared.Remotes.Components;
  4. using Robust.Client.UserInterface;
  5. using Robust.Client.UserInterface.Controls;
  6. using Robust.Shared.Timing;
  7. namespace Content.Client.Remote.UI;
  8. public sealed class DoorRemoteStatusControl : Control
  9. {
  10. private readonly Entity<DoorRemoteComponent> _entity;
  11. private readonly RichTextLabel _label;
  12. // set to toggle bolts initially just so that it updates on first pickup of remote
  13. private OperatingMode PrevOperatingMode = OperatingMode.placeholderForUiUpdates;
  14. public DoorRemoteStatusControl(Entity<DoorRemoteComponent> entity)
  15. {
  16. _entity = entity;
  17. _label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
  18. AddChild(_label);
  19. }
  20. protected override void FrameUpdate(FrameEventArgs args)
  21. {
  22. base.FrameUpdate(args);
  23. // only updates the UI if any of the details are different than they previously were
  24. if (PrevOperatingMode == _entity.Comp.Mode)
  25. return;
  26. PrevOperatingMode = _entity.Comp.Mode;
  27. // Update current volume and injector state
  28. var modeStringLocalized = Loc.GetString(_entity.Comp.Mode switch
  29. {
  30. OperatingMode.OpenClose => "door-remote-open-close-text",
  31. OperatingMode.ToggleBolts => "door-remote-toggle-bolt-text",
  32. OperatingMode.ToggleEmergencyAccess => "door-remote-emergency-access-text",
  33. _ => "door-remote-invalid-text"
  34. });
  35. _label.SetMarkup(Loc.GetString("door-remote-mode-label", ("modeString", modeStringLocalized)));
  36. }
  37. }