GhostGui.xaml.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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? GhostRolesPressed;
  14. public GhostGui()
  15. {
  16. RobustXamlLoader.Load(this);
  17. TargetWindow = new GhostTargetWindow();
  18. MouseFilter = MouseFilterMode.Ignore;
  19. GhostWarpButton.OnPressed += _ => RequestWarpsPressed?.Invoke();
  20. ReturnToBodyButton.OnPressed += _ => ReturnToBodyPressed?.Invoke();
  21. GhostRolesButton.OnPressed += _ => GhostRolesPressed?.Invoke();
  22. }
  23. public void Hide()
  24. {
  25. TargetWindow.Close();
  26. Visible = false;
  27. }
  28. public void Update(int? roles, bool? canReturnToBody)
  29. {
  30. ReturnToBodyButton.Disabled = !canReturnToBody ?? true;
  31. if (roles != null)
  32. {
  33. GhostRolesButton.Text = Loc.GetString("ghost-gui-ghost-roles-button", ("count", roles));
  34. if (roles > 0)
  35. {
  36. GhostRolesButton.StyleClasses.Add(StyleBase.ButtonCaution);
  37. }
  38. else
  39. {
  40. GhostRolesButton.StyleClasses.Remove(StyleBase.ButtonCaution);
  41. }
  42. }
  43. TargetWindow.Populate();
  44. }
  45. protected override void Dispose(bool disposing)
  46. {
  47. base.Dispose(disposing);
  48. if (disposing)
  49. {
  50. TargetWindow.Dispose();
  51. }
  52. }
  53. }