GhostRoleButtonsBox.xaml.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.Numerics;
  2. using Content.Shared.Ghost.Roles;
  3. using Robust.Client.AutoGenerated;
  4. using Robust.Client.GameObjects;
  5. using Robust.Client.UserInterface.Controls;
  6. using Robust.Client.UserInterface.CustomControls;
  7. using Robust.Client.UserInterface.XAML;
  8. using Robust.Shared.Utility;
  9. namespace Content.Client.UserInterface.Systems.Ghost.Controls.Roles
  10. {
  11. [GenerateTypedNameReferences]
  12. public sealed partial class GhostRoleButtonsBox : BoxContainer
  13. {
  14. private SpriteSystem _spriteSystem;
  15. public event Action<GhostRoleInfo>? OnRoleSelected;
  16. public event Action<GhostRoleInfo>? OnRoleFollow;
  17. public GhostRoleButtonsBox(bool hasAccess, FormattedMessage? reason, IEnumerable<GhostRoleInfo> roles, SpriteSystem spriteSystem)
  18. {
  19. RobustXamlLoader.Load(this);
  20. _spriteSystem = spriteSystem;
  21. foreach (var role in roles)
  22. {
  23. var button = new GhostRoleEntryButtons(role);
  24. button.RequestButton.OnPressed += _ => OnRoleSelected?.Invoke(role);
  25. button.FollowButton.OnPressed += _ => OnRoleFollow?.Invoke(role);
  26. if (!hasAccess)
  27. {
  28. button.RequestButton.Disabled = true;
  29. if (reason != null && !reason.IsEmpty)
  30. {
  31. var tooltip = new Tooltip();
  32. tooltip.SetMessage(reason);
  33. button.RequestButton.TooltipSupplier = _ => tooltip;
  34. }
  35. button.RequestButton.AddChild(new TextureRect
  36. {
  37. TextureScale = new Vector2(0.4f, 0.4f),
  38. Stretch = TextureRect.StretchMode.KeepCentered,
  39. Texture = _spriteSystem.Frame0(new SpriteSpecifier.Texture(new ("/Textures/Interface/Nano/lock.svg.192dpi.png"))),
  40. HorizontalExpand = true,
  41. HorizontalAlignment = HAlignment.Right,
  42. });
  43. }
  44. Buttons.AddChild(button);
  45. }
  46. }
  47. }
  48. }