using System.Collections.Generic; using System.Linq; using AppleHills.Data.CardSystem; using Bootstrap; using Data.CardSystem; using Pixelplacement; using UI.Core; using UI.DragAndDrop.Core; using UnityEngine; using UnityEngine.UI; namespace UI.CardSystem { /// /// UI page for viewing the player's card collection in an album. /// Manages booster pack button visibility and opening flow. /// public class AlbumViewPage : UIPage { [Header("UI References")] [SerializeField] private CanvasGroup canvasGroup; [SerializeField] private Button exitButton; [SerializeField] private BookCurlPro.BookPro book; [Header("Zone Navigation")] [SerializeField] private BookTabButton[] zoneTabs; // All zone tab buttons [Header("Album Card Reveal")] [SerializeField] private SlotContainer bottomRightSlots; [SerializeField] private GameObject albumCardPlacementPrefab; // The wrapper prefab with flip/drag (AlbumPlacementCard) [Header("Card Enlarge System")] [SerializeField] private GameObject cardEnlargedBackdrop; // Backdrop to block interactions [SerializeField] private Transform cardEnlargedContainer; // Container for enlarged cards (sits above backdrop) [Header("Booster Pack UI")] [SerializeField] private GameObject[] boosterPackButtons; [SerializeField] private BoosterOpeningPage boosterOpeningPage; private Input.InputMode _previousInputMode; private List _activeCards = new List(); private const int MAX_VISIBLE_CARDS = 3; private void Awake() { // Make sure we have a CanvasGroup for transitions if (canvasGroup == null) canvasGroup = GetComponent(); if (canvasGroup == null) canvasGroup = gameObject.AddComponent(); // Hide backdrop initially if (cardEnlargedBackdrop != null) { cardEnlargedBackdrop.SetActive(false); } // Set up exit button if (exitButton != null) { exitButton.onClick.AddListener(OnExitButtonClicked); } // Set up booster pack button listeners SetupBoosterButtonListeners(); // Register for post-boot initialization BootCompletionService.RegisterInitAction(InitializePostBoot); // UI pages should start disabled gameObject.SetActive(false); } private void InitializePostBoot() { // Subscribe to CardSystemManager events if (CardSystemManager.Instance != null) { CardSystemManager.Instance.OnBoosterCountChanged += OnBoosterCountChanged; // NOTE: OnPendingCardAdded is subscribed in TransitionIn, not here // This prevents spawning cards when page is not active // Update initial button visibility int initialCount = CardSystemManager.Instance.GetBoosterPackCount(); UpdateBoosterButtons(initialCount); } } private void SetupBoosterButtonListeners() { if (boosterPackButtons == null) return; for (int i = 0; i < boosterPackButtons.Length; i++) { if (boosterPackButtons[i] == null) continue; Button button = boosterPackButtons[i].GetComponent