using System.Collections.Generic;
using AppleHills.Data.CardSystem;
using Core;
using Data.CardSystem;
using Pixelplacement;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace AppleHills.UI.CardSystem
{
///
/// UI page for the main menu of the card system.
/// Shows options to open boosters, view album, etc.
///
public class CardMenuPage : UIPage
{
[Header("Menu Options")]
[SerializeField] private Button openBoosterButton;
[SerializeField] private Button viewAlbumButton;
[SerializeField] private Button changeClothesButton;
[Header("UI Elements")]
[SerializeField] private BoosterNotificationDot boosterNotificationDot; // Changed to BoosterNotificationDot
[SerializeField] private CanvasGroup canvasGroup;
private CardAlbumUI _cardAlbumUI;
private CardSystemManager _cardManager;
private void Awake()
{
// Get references
_cardAlbumUI = FindAnyObjectByType();
_cardManager = CardSystemManager.Instance;
// Make sure we have a CanvasGroup
if (canvasGroup == null)
canvasGroup = GetComponent();
if (canvasGroup == null)
canvasGroup = gameObject.AddComponent();
// Set up button listeners
if (openBoosterButton != null)
{
openBoosterButton.onClick.AddListener(OnOpenBoosterClicked);
}
if (viewAlbumButton != null)
{
viewAlbumButton.onClick.AddListener(OnViewAlbumClicked);
}
if (changeClothesButton != null)
{
changeClothesButton.onClick.AddListener(OnChangeClothesClicked);
// Disable "Coming Soon" feature
changeClothesButton.interactable = false;
}
}
private void OnEnable()
{
UpdateUI();
}
private void OnDestroy()
{
// Clean up button listeners
if (openBoosterButton != null)
{
openBoosterButton.onClick.RemoveListener(OnOpenBoosterClicked);
}
if (viewAlbumButton != null)
{
viewAlbumButton.onClick.RemoveListener(OnViewAlbumClicked);
}
if (changeClothesButton != null)
{
changeClothesButton.onClick.RemoveListener(OnChangeClothesClicked);
}
}
///
/// Public method to refresh UI state when returning to this page
///
public void RefreshUI()
{
UpdateUI();
}
///
/// Updates the UI elements based on current state
///
private void UpdateUI()
{
if (_cardManager == null) return;
int boosterCount = _cardManager.GetBoosterPackCount();
// Update booster count text using the notification dot
if (boosterNotificationDot != null)
{
boosterNotificationDot.SetCount(boosterCount);
}
// Enable/disable open booster button based on availability
if (openBoosterButton != null)
{
openBoosterButton.interactable = boosterCount > 0;
}
}
///
/// Handles click on the Open Booster button
///
private void OnOpenBoosterClicked()
{
if (_cardAlbumUI != null)
{
_cardAlbumUI.OpenBoosterPack();
}
}
///
/// Handles click on the View Album button
///
private void OnViewAlbumClicked()
{
if (_cardAlbumUI != null)
{
_cardAlbumUI.OpenAlbumView();
}
}
///
/// Handles click on the Change Clothes button (coming soon)
///
private void OnChangeClothesClicked()
{
Logging.Debug("[CardMenuPage] Change Clothes feature coming soon!");
// No implementation yet - "Coming soon" feature
}
///
/// Override for transition in animation using Pixelplacement.Tween
///
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);
}
else
{
// Fallback if no CanvasGroup
onComplete?.Invoke();
}
}
///
/// Override for transition out animation using Pixelplacement.Tween
///
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);
}
else
{
// Fallback if no CanvasGroup
onComplete?.Invoke();
}
}
}
}