| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- using Robust.Client.AutoGenerated;
- using Robust.Client.UserInterface.CustomControls;
- using Robust.Client.UserInterface.XAML;
- using Robust.Client.UserInterface.Controls; // Required for ButtonEventArgs
- using System; // Required for Action
- // Remove the duplicate/unused using directive if FactionUIController isn't directly used here
- using Robust.Shared.Log; // Required for ISawmill
- // using Content.Client.UserInterface.Systems.Faction;
- namespace Content.Client.UserInterface.Systems.Faction.Windows;
- [GenerateTypedNameReferences]
- public sealed partial class FactionWindow : DefaultWindow
- {
- // For logging within the window itself
- private static readonly ISawmill Sawmill = Logger.GetSawmill("faction.window");
- // Events for the controller to subscribe to
- public event Action? OnListFactionsPressed;
- public event Action? OnCreateFactionPressed;
- public event Action? OnLeaveFactionPressed;
- public event Action? OnInvitePlayerPressed;
- // This property relies on the XAML generator succeeding
- public string FactionNameInputText => FactionNameInput?.Text ?? string.Empty;
- // Property for the new invite player name input
- public string InvitePlayerNameInputText => InvitePlayerNameInput?.Text ?? string.Empty;
- /// <summary>
- /// Initialises the faction window UI and connects button events to their corresponding public event handlers.
- /// </summary>
- public FactionWindow()
- {
- RobustXamlLoader.Load(this);
- // Wire up button presses to invoke the public events
- // These lines will only compile AFTER the XAML is fixed and the project is rebuilt
- ListFactionsButtonNotInFaction.OnPressed += (args) => OnListFactionsPressed?.Invoke();
- ListFactionsButtonInFaction.OnPressed += (args) => OnListFactionsPressed?.Invoke(); // Both list buttons trigger the same event
- CreateFactionButton.OnPressed += (args) => OnCreateFactionPressed?.Invoke();
- LeaveFactionButton.OnPressed += (args) => OnLeaveFactionPressed?.Invoke();
- InvitePlayerButton.OnPressed += (args) => OnInvitePlayerPressed?.Invoke();
- // The closing brace for the constructor is here
- } // <-- END OF CONSTRUCTOR
- /// <summary>
- /// Clears the text from the faction name input field if it exists.
- /// </summary>
- public void ClearFactionNameInput()
- {
- // This line relies on the XAML generator succeeding
- if (FactionNameInput != null)
- FactionNameInput.Text = string.Empty;
- }
- /// <summary>
- /// Clears the text from the invite player name input field, if it exists.
- /// </summary>
- public void ClearInvitePlayerNameInput()
- {
- // This line relies on the XAML generator succeeding
- if (InvitePlayerNameInput != null)
- InvitePlayerNameInput.Text = string.Empty;
- }
- /// <summary>
- /// Updates the window's view based on whether the player is in a faction.
- /// </summary>
- /// <param name="isInFaction">True if the player is in a faction, false otherwise.</param>
- /// <summary>
- /// Updates the UI to reflect whether the player is currently in a faction, toggling relevant views and displaying the current faction name if applicable.
- /// </summary>
- /// <param name="isInFaction">Indicates whether the player is in a faction.</param>
- /// <param name="factionName">The name of the faction if <paramref name="isInFaction"/> is true; otherwise, ignored.</param>
- public void UpdateState(bool isInFaction, string? factionName = null)
- {
- Sawmill.Debug($"UpdateState called. isInFaction: {isInFaction}, factionName: '{factionName ?? "null"}'");
- // These lines rely on the XAML generator succeeding
- NotInFactionView.Visible = !isInFaction;
- InFactionView.Visible = isInFaction;
- Sawmill.Debug($"Post-UpdateState: NotInFactionView.Visible: {NotInFactionView.Visible}, InFactionView.Visible: {InFactionView.Visible}");
- if (isInFaction)
- {
- // This line relies on the XAML generator succeeding
- CurrentFactionLabel.Text = $"Current Faction: {factionName ?? "Unknown"}";
- Sawmill.Debug($"CurrentFactionLabel text set to: '{CurrentFactionLabel.Text}'");
- }
- // The FactionListLabel will be updated by the FactionUIController calling HandleListFactionsPressed
- // after this UpdateState call, or when the "List Factions" button is pressed.
- Sawmill.Debug("UpdateState finished (main view updated). Faction list will be updated separately by controller if needed.");
- }
- /// <summary>
- /// Updates the label displaying the list of factions.
- /// </summary>
- /// <summary>
- /// Updates the faction list display with the provided text data.
- /// </summary>
- /// <param name="listData">The text to display in the faction list label.</param>
- public void UpdateFactionList(string listData)
- {
- // This line relies on the XAML generator succeeding
- FactionListLabel.Text = listData;
- // If using RichTextLabel:
- // FactionListLabel.SetMarkup(listData);
- }
- } // <-- END OF CLASS
|