1
0

BarSignMenu.xaml.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Content.Client.UserInterface.Controls;
  2. using Content.Shared.BarSign;
  3. using Robust.Client.AutoGenerated;
  4. using Robust.Client.UserInterface.XAML;
  5. namespace Content.Client.BarSign.Ui;
  6. [GenerateTypedNameReferences]
  7. public sealed partial class BarSignMenu : FancyWindow
  8. {
  9. private string? _currentId;
  10. private readonly List<BarSignPrototype> _cachedPrototypes = new();
  11. public event Action<string>? OnSignSelected;
  12. public BarSignMenu(BarSignPrototype? currentSign, List<BarSignPrototype> signs)
  13. {
  14. RobustXamlLoader.Load(this);
  15. _currentId = currentSign?.ID;
  16. _cachedPrototypes.Clear();
  17. _cachedPrototypes = signs;
  18. foreach (var proto in _cachedPrototypes)
  19. {
  20. SignOptions.AddItem(Loc.GetString(proto.Name));
  21. }
  22. SignOptions.OnItemSelected += idx =>
  23. {
  24. OnSignSelected?.Invoke(_cachedPrototypes[idx.Id].ID);
  25. SignOptions.SelectId(idx.Id);
  26. };
  27. if (currentSign != null)
  28. {
  29. var idx = _cachedPrototypes.IndexOf(currentSign);
  30. SignOptions.TrySelectId(idx);
  31. }
  32. }
  33. public void UpdateState(BarSignPrototype newSign)
  34. {
  35. if (_currentId != null && newSign.ID == _currentId)
  36. return;
  37. _currentId = newSign.ID;
  38. var idx = _cachedPrototypes.IndexOf(newSign);
  39. SignOptions.TrySelectId(idx);
  40. }
  41. }