Files
AppleHillsProduction/Assets/Scripts/UI/CardSystem/CardAlbumOpener.cs
2025-11-09 21:41:39 +00:00

92 lines
2.8 KiB
C#

using UI.Core;
using UnityEngine;
using UnityEngine.UI;
namespace UI.CardSystem
{
/// <summary>
/// Opens the card album view when the button is pressed.
/// Attach this to a top-level GameObject in the scene.
/// </summary>
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);
}
Debug.Log("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);
}
}
}