using Core; using UI.Core; using UnityEngine; using UnityEngine.UI; namespace UI.CardSystem { /// /// Opens the card album view when the button is pressed. /// Attach this to a top-level GameObject in the scene. /// public class CardAlbumOpener : MonoBehaviour { [Header("References")] [SerializeField] private Button openAlbumButton; [SerializeField] private AlbumViewPage albumViewPage; [SerializeField] private BoosterOpeningPage boosterOpeningPage; private void Awake() { if (openAlbumButton != null) { openAlbumButton.onClick.AddListener(OnOpenAlbumClicked); } } private void Start() { if (UIPageController.Instance != null) { UIPageController.Instance.OnPageChanged += OnPageChanged; } } private void OnDisable() { if (UIPageController.Instance != null) { UIPageController.Instance.OnPageChanged -= OnPageChanged; } } private void OnDestroy() { if (openAlbumButton != null) { openAlbumButton.onClick.RemoveListener(OnOpenAlbumClicked); } Logging.Debug("ALBUM: CardAlbumDestroyed"); } private void OnOpenAlbumClicked() { if (UIPageController.Instance == null) return; // Check if we're currently on the booster opening page if (UIPageController.Instance.CurrentPage == boosterOpeningPage) { // We're in booster opening page, pop back to album main page UIPageController.Instance.PopPage(); } else if (UIPageController.Instance.CurrentPage != albumViewPage) { // We're not in the album at all, open it if (openAlbumButton != null) { openAlbumButton.gameObject.SetActive(false); } if (albumViewPage != null) { UIPageController.Instance.PushPage(albumViewPage); } } } private void OnPageChanged(UIPage currentPage) { if (openAlbumButton == null) return; // Show the button when: // 1. We're on the booster opening page (acts as "back to album" button) // 2. We're NOT on the album main page (acts as "open album" button) // Hide the button only when we're on the album main page bool shouldShowButton = currentPage == boosterOpeningPage || currentPage != albumViewPage; openAlbumButton.gameObject.SetActive(shouldShowButton); } } }