BarSignBoundUserInterface.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Linq;
  2. using Content.Shared.BarSign;
  3. using JetBrains.Annotations;
  4. using Robust.Shared.Prototypes;
  5. namespace Content.Client.BarSign.Ui;
  6. [UsedImplicitly]
  7. public sealed class BarSignBoundUserInterface(EntityUid owner, Enum uiKey) : BoundUserInterface(owner, uiKey)
  8. {
  9. [Dependency] private readonly IPrototypeManager _prototype = default!;
  10. private BarSignMenu? _menu;
  11. protected override void Open()
  12. {
  13. base.Open();
  14. var sign = EntMan.GetComponentOrNull<BarSignComponent>(Owner)?.Current is { } current
  15. ? _prototype.Index(current)
  16. : null;
  17. var allSigns = Shared.BarSign.BarSignSystem.GetAllBarSigns(_prototype)
  18. .OrderBy(p => Loc.GetString(p.Name))
  19. .ToList();
  20. _menu = new(sign, allSigns);
  21. _menu.OnSignSelected += id =>
  22. {
  23. SendMessage(new SetBarSignMessage(id));
  24. };
  25. _menu.OnClose += Close;
  26. _menu.OpenCentered();
  27. }
  28. public void Update(ProtoId<BarSignPrototype>? sign)
  29. {
  30. if (_prototype.TryIndex(sign, out var signPrototype))
  31. _menu?.UpdateState(signPrototype);
  32. }
  33. protected override void Dispose(bool disposing)
  34. {
  35. base.Dispose(disposing);
  36. if (!disposing)
  37. return;
  38. _menu?.Dispose();
  39. }
  40. }