GhostGui.xaml.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using Content.Client.Stylesheets;
  2. using Content.Client.UserInterface.Systems.Ghost.Controls;
  3. using Robust.Client.AutoGenerated;
  4. using Robust.Client.UserInterface.Controls;
  5. using Robust.Client.UserInterface.XAML;
  6. namespace Content.Client.UserInterface.Systems.Ghost.Widgets;
  7. [GenerateTypedNameReferences]
  8. public sealed partial class GhostGui : UIWidget
  9. {
  10. public GhostTargetWindow TargetWindow { get; }
  11. public event Action? RequestWarpsPressed;
  12. public event Action? ReturnToBodyPressed;
  13. public event Action? ReturnToLobbyPressed;
  14. public event Action? GhostRolesPressed;
  15. public GhostGui()
  16. {
  17. RobustXamlLoader.Load(this);
  18. TargetWindow = new GhostTargetWindow();
  19. MouseFilter = MouseFilterMode.Ignore;
  20. GhostWarpButton.OnPressed += _ => RequestWarpsPressed?.Invoke();
  21. ReturnToLobbyButton.OnPressed += _ => ReturnToLobbyPressed?.Invoke();
  22. ReturnToBodyButton.OnPressed += _ => ReturnToBodyPressed?.Invoke();
  23. GhostRolesButton.OnPressed += _ => GhostRolesPressed?.Invoke();
  24. }
  25. public void Hide()
  26. {
  27. TargetWindow.Close();
  28. Visible = false;
  29. }
  30. public void Update(int? roles, bool? canReturnToBody)
  31. {
  32. ReturnToBodyButton.Disabled = !canReturnToBody ?? true;
  33. if (roles != null)
  34. {
  35. GhostRolesButton.Text = Loc.GetString("ghost-gui-ghost-roles-button", ("count", roles));
  36. if (roles > 0)
  37. {
  38. GhostRolesButton.StyleClasses.Add(StyleBase.ButtonCaution);
  39. }
  40. else
  41. {
  42. GhostRolesButton.StyleClasses.Remove(StyleBase.ButtonCaution);
  43. }
  44. }
  45. TargetWindow.Populate();
  46. }
  47. protected override void Dispose(bool disposing)
  48. {
  49. base.Dispose(disposing);
  50. if (disposing)
  51. {
  52. TargetWindow.Dispose();
  53. }
  54. }
  55. }