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;
///
/// Initialises the faction window UI and connects button events to their corresponding public event handlers.
///
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
///
/// Clears the text from the faction name input field if it exists.
///
public void ClearFactionNameInput()
{
// This line relies on the XAML generator succeeding
if (FactionNameInput != null)
FactionNameInput.Text = string.Empty;
}
///
/// Clears the text from the invite player name input field, if it exists.
///
public void ClearInvitePlayerNameInput()
{
// This line relies on the XAML generator succeeding
if (InvitePlayerNameInput != null)
InvitePlayerNameInput.Text = string.Empty;
}
///
/// Updates the window's view based on whether the player is in a faction.
///
/// True if the player is in a faction, false otherwise.
///
/// Updates the UI to reflect whether the player is currently in a faction, toggling relevant views and displaying the current faction name if applicable.
///
/// Indicates whether the player is in a faction.
/// The name of the faction if is true; otherwise, ignored.
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.");
}
///
/// Updates the label displaying the list of factions.
///
///
/// Updates the faction list display with the provided text data.
///
/// The text to display in the faction list label.
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