FactionWindow.xaml.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using Robust.Client.AutoGenerated;
  2. using Robust.Client.UserInterface.CustomControls;
  3. using Robust.Client.UserInterface.XAML;
  4. using Robust.Client.UserInterface.Controls; // Required for ButtonEventArgs
  5. using System; // Required for Action
  6. // Remove the duplicate/unused using directive if FactionUIController isn't directly used here
  7. using Robust.Shared.Log; // Required for ISawmill
  8. // using Content.Client.UserInterface.Systems.Faction;
  9. namespace Content.Client.UserInterface.Systems.Faction.Windows;
  10. [GenerateTypedNameReferences]
  11. public sealed partial class FactionWindow : DefaultWindow
  12. {
  13. // For logging within the window itself
  14. private static readonly ISawmill Sawmill = Logger.GetSawmill("faction.window");
  15. // Events for the controller to subscribe to
  16. public event Action? OnListFactionsPressed;
  17. public event Action? OnCreateFactionPressed;
  18. public event Action? OnLeaveFactionPressed;
  19. public event Action? OnInvitePlayerPressed;
  20. // This property relies on the XAML generator succeeding
  21. public string FactionNameInputText => FactionNameInput?.Text ?? string.Empty;
  22. // Property for the new invite player name input
  23. public string InvitePlayerNameInputText => InvitePlayerNameInput?.Text ?? string.Empty;
  24. /// <summary>
  25. /// Initialises the faction window UI and connects button events to their corresponding public event handlers.
  26. /// </summary>
  27. public FactionWindow()
  28. {
  29. RobustXamlLoader.Load(this);
  30. // Wire up button presses to invoke the public events
  31. // These lines will only compile AFTER the XAML is fixed and the project is rebuilt
  32. ListFactionsButtonNotInFaction.OnPressed += (args) => OnListFactionsPressed?.Invoke();
  33. ListFactionsButtonInFaction.OnPressed += (args) => OnListFactionsPressed?.Invoke(); // Both list buttons trigger the same event
  34. CreateFactionButton.OnPressed += (args) => OnCreateFactionPressed?.Invoke();
  35. LeaveFactionButton.OnPressed += (args) => OnLeaveFactionPressed?.Invoke();
  36. InvitePlayerButton.OnPressed += (args) => OnInvitePlayerPressed?.Invoke();
  37. // The closing brace for the constructor is here
  38. } // <-- END OF CONSTRUCTOR
  39. /// <summary>
  40. /// Clears the text from the faction name input field if it exists.
  41. /// </summary>
  42. public void ClearFactionNameInput()
  43. {
  44. // This line relies on the XAML generator succeeding
  45. if (FactionNameInput != null)
  46. FactionNameInput.Text = string.Empty;
  47. }
  48. /// <summary>
  49. /// Clears the text from the invite player name input field, if it exists.
  50. /// </summary>
  51. public void ClearInvitePlayerNameInput()
  52. {
  53. // This line relies on the XAML generator succeeding
  54. if (InvitePlayerNameInput != null)
  55. InvitePlayerNameInput.Text = string.Empty;
  56. }
  57. /// <summary>
  58. /// Updates the window's view based on whether the player is in a faction.
  59. /// </summary>
  60. /// <param name="isInFaction">True if the player is in a faction, false otherwise.</param>
  61. /// <summary>
  62. /// Updates the UI to reflect whether the player is currently in a faction, toggling relevant views and displaying the current faction name if applicable.
  63. /// </summary>
  64. /// <param name="isInFaction">Indicates whether the player is in a faction.</param>
  65. /// <param name="factionName">The name of the faction if <paramref name="isInFaction"/> is true; otherwise, ignored.</param>
  66. public void UpdateState(bool isInFaction, string? factionName = null)
  67. {
  68. Sawmill.Debug($"UpdateState called. isInFaction: {isInFaction}, factionName: '{factionName ?? "null"}'");
  69. // These lines rely on the XAML generator succeeding
  70. NotInFactionView.Visible = !isInFaction;
  71. InFactionView.Visible = isInFaction;
  72. Sawmill.Debug($"Post-UpdateState: NotInFactionView.Visible: {NotInFactionView.Visible}, InFactionView.Visible: {InFactionView.Visible}");
  73. if (isInFaction)
  74. {
  75. // This line relies on the XAML generator succeeding
  76. CurrentFactionLabel.Text = $"Current Faction: {factionName ?? "Unknown"}";
  77. Sawmill.Debug($"CurrentFactionLabel text set to: '{CurrentFactionLabel.Text}'");
  78. }
  79. // The FactionListLabel will be updated by the FactionUIController calling HandleListFactionsPressed
  80. // after this UpdateState call, or when the "List Factions" button is pressed.
  81. Sawmill.Debug("UpdateState finished (main view updated). Faction list will be updated separately by controller if needed.");
  82. }
  83. /// <summary>
  84. /// Updates the label displaying the list of factions.
  85. /// </summary>
  86. /// <summary>
  87. /// Updates the faction list display with the provided text data.
  88. /// </summary>
  89. /// <param name="listData">The text to display in the faction list label.</param>
  90. public void UpdateFactionList(string listData)
  91. {
  92. // This line relies on the XAML generator succeeding
  93. FactionListLabel.Text = listData;
  94. // If using RichTextLabel:
  95. // FactionListLabel.SetMarkup(listData);
  96. }
  97. } // <-- END OF CLASS