194 lines
6.5 KiB
C#
194 lines
6.5 KiB
C#
using Bootstrap;
|
|
using Data.CardSystem;
|
|
using Pixelplacement;
|
|
using UI.Core;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace UI.CardSystem
|
|
{
|
|
/// <summary>
|
|
/// UI page for viewing the player's card collection in an album.
|
|
/// Manages booster pack button visibility and opening flow.
|
|
/// </summary>
|
|
public class AlbumViewPage : UIPage
|
|
{
|
|
[Header("UI References")]
|
|
[SerializeField] private CanvasGroup canvasGroup;
|
|
[SerializeField] private Button exitButton;
|
|
[SerializeField] private BookCurlPro.BookPro book;
|
|
|
|
[Header("Booster Pack UI")]
|
|
[SerializeField] private GameObject[] boosterPackButtons;
|
|
[SerializeField] private BoosterOpeningPage boosterOpeningPage;
|
|
|
|
private void Awake()
|
|
{
|
|
// Make sure we have a CanvasGroup for transitions
|
|
if (canvasGroup == null)
|
|
canvasGroup = GetComponent<CanvasGroup>();
|
|
if (canvasGroup == null)
|
|
canvasGroup = gameObject.AddComponent<CanvasGroup>();
|
|
|
|
// 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;
|
|
|
|
// 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<Button>();
|
|
if (button != null)
|
|
{
|
|
button.onClick.AddListener(OnBoosterButtonClicked);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
// Unsubscribe from CardSystemManager
|
|
if (CardSystemManager.Instance != null)
|
|
{
|
|
CardSystemManager.Instance.OnBoosterCountChanged -= OnBoosterCountChanged;
|
|
}
|
|
|
|
// Clean up exit button
|
|
if (exitButton != null)
|
|
{
|
|
exitButton.onClick.RemoveListener(OnExitButtonClicked);
|
|
}
|
|
|
|
// Clean up booster button listeners
|
|
if (boosterPackButtons != null)
|
|
{
|
|
foreach (var buttonObj in boosterPackButtons)
|
|
{
|
|
if (buttonObj == null) continue;
|
|
|
|
Button button = buttonObj.GetComponent<Button>();
|
|
if (button != null)
|
|
{
|
|
button.onClick.RemoveListener(OnBoosterButtonClicked);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnExitButtonClicked()
|
|
{
|
|
if (book != null && book.CurrentPaper != 1)
|
|
{
|
|
// Not on page 0, flip to page 0 first
|
|
BookCurlPro.AutoFlip autoFlip = book.GetComponent<BookCurlPro.AutoFlip>();
|
|
if (autoFlip == null)
|
|
{
|
|
autoFlip = book.gameObject.AddComponent<BookCurlPro.AutoFlip>();
|
|
}
|
|
|
|
autoFlip.enabled = true;
|
|
autoFlip.StartFlipping(1);
|
|
}
|
|
else
|
|
{
|
|
// Already on page 0 or no book reference, exit
|
|
if (UIPageController.Instance != null)
|
|
{
|
|
UIPageController.Instance.PopPage();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnBoosterCountChanged(int newCount)
|
|
{
|
|
UpdateBoosterButtons(newCount);
|
|
}
|
|
|
|
private void UpdateBoosterButtons(int boosterCount)
|
|
{
|
|
if (boosterPackButtons == null || boosterPackButtons.Length == 0) return;
|
|
|
|
int visibleCount = Mathf.Min(boosterCount, boosterPackButtons.Length);
|
|
|
|
for (int i = 0; i < boosterPackButtons.Length; i++)
|
|
{
|
|
if (boosterPackButtons[i] != null)
|
|
{
|
|
boosterPackButtons[i].SetActive(i < visibleCount);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnBoosterButtonClicked()
|
|
{
|
|
if (boosterOpeningPage != null && UIPageController.Instance != null)
|
|
{
|
|
// Pass current booster count to the opening page
|
|
int boosterCount = CardSystemManager.Instance?.GetBoosterPackCount() ?? 0;
|
|
boosterOpeningPage.SetAvailableBoosterCount(boosterCount);
|
|
|
|
UIPageController.Instance.PushPage(boosterOpeningPage);
|
|
}
|
|
}
|
|
|
|
protected override void DoTransitionIn(System.Action onComplete)
|
|
{
|
|
// Simple fade in animation
|
|
if (canvasGroup != null)
|
|
{
|
|
canvasGroup.alpha = 0f;
|
|
Tween.Value(0f, 1f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete, obeyTimescale: false);
|
|
}
|
|
else
|
|
{
|
|
// Fallback if no CanvasGroup
|
|
onComplete?.Invoke();
|
|
}
|
|
}
|
|
|
|
protected override void DoTransitionOut(System.Action onComplete)
|
|
{
|
|
// Simple fade out animation
|
|
if (canvasGroup != null)
|
|
{
|
|
Tween.Value(canvasGroup.alpha, 0f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete, obeyTimescale: false);
|
|
}
|
|
else
|
|
{
|
|
// Fallback if no CanvasGroup
|
|
onComplete?.Invoke();
|
|
}
|
|
}
|
|
}
|
|
}
|