using Core; using UnityEngine; using UnityEngine.UI; using UI.Core; using Minigames.FortFight.Core; using Minigames.FortFight.Data; using Pixelplacement; namespace Minigames.FortFight.UI { /// /// UI page for selecting single-player or two-player mode /// public class ModeSelectionPage : UIPage { [Header("Mode Selection Buttons")] [SerializeField] private Button singlePlayerButton; [SerializeField] private Button twoPlayerButton; [Header("Optional Visual Elements")] [SerializeField] private GameObject titleText; [SerializeField] private CanvasGroup canvasGroup; #region Initialization internal override void OnManagedAwake() { base.OnManagedAwake(); // Validate button references if (singlePlayerButton == null) { Logging.Error("[ModeSelectionPage] Single player button not assigned!"); } else { singlePlayerButton.onClick.AddListener(OnSinglePlayerSelected); } if (twoPlayerButton == null) { Logging.Error("[ModeSelectionPage] Two player button not assigned!"); } else { twoPlayerButton.onClick.AddListener(OnTwoPlayerSelected); } // Set up canvas group if available if (canvasGroup == null) { canvasGroup = GetComponent(); } } #endregion #region Button Callbacks /// /// Called when single player button is clicked /// private void OnSinglePlayerSelected() { Logging.Debug("[ModeSelectionPage] Single player mode selected"); if (FortFightGameManager.Instance != null) { FortFightGameManager.Instance.SelectGameMode(FortFightGameMode.SinglePlayer); } else { Logging.Error("[ModeSelectionPage] FortFightGameManager instance not found!"); } } /// /// Called when two player button is clicked /// private void OnTwoPlayerSelected() { Logging.Debug("[ModeSelectionPage] Two player mode selected"); if (FortFightGameManager.Instance != null) { FortFightGameManager.Instance.SelectGameMode(FortFightGameMode.TwoPlayer); } else { Logging.Error("[ModeSelectionPage] FortFightGameManager instance not found!"); } } #endregion #region Transitions protected override void DoTransitionIn(System.Action onComplete) { // Simple fade in if canvas group is available if (canvasGroup != null) { canvasGroup.alpha = 0f; Tween.CanvasGroupAlpha(canvasGroup, 1f, transitionDuration, 0f, Tween.EaseOut, completeCallback: () => onComplete?.Invoke()); } else { onComplete?.Invoke(); } } protected override void DoTransitionOut(System.Action onComplete) { // Simple fade out if canvas group is available if (canvasGroup != null) { Tween.CanvasGroupAlpha(canvasGroup, 0f, transitionDuration, 0f, Tween.EaseIn, completeCallback: () => onComplete?.Invoke()); } else { onComplete?.Invoke(); } } #endregion #region Cleanup internal override void OnManagedDestroy() { base.OnManagedDestroy(); // Unsubscribe from button events if (singlePlayerButton != null) { singlePlayerButton.onClick.RemoveListener(OnSinglePlayerSelected); } if (twoPlayerButton != null) { twoPlayerButton.onClick.RemoveListener(OnTwoPlayerSelected); } } #endregion } }