Files
AppleHillsProduction/Assets/Scripts/UI/CardSystem/CardMenuPage.cs
2025-10-27 15:21:23 +01:00

205 lines
6.5 KiB
C#

using Core;
using Data.CardSystem;
using Pixelplacement;
using UI.Core;
using UnityEngine;
using UnityEngine.UI;
namespace UI.CardSystem
{
/// <summary>
/// UI page for the main menu of the card system.
/// Shows options to open boosters, view album, etc.
/// </summary>
public class CardMenuPage : UIPage
{
[Header("Menu Options")]
[SerializeField] private Button openBoosterButton;
[SerializeField] private Button viewAlbumButton;
[SerializeField] private Button changeClothesButton;
[SerializeField] private Button backButton; // Added back button field
[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<CardAlbumUI>();
_cardManager = CardSystemManager.Instance;
// Make sure we have a CanvasGroup
if (canvasGroup == null)
canvasGroup = GetComponent<CanvasGroup>();
if (canvasGroup == null)
canvasGroup = gameObject.AddComponent<CanvasGroup>();
// 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;
}
if (backButton != null) // Set up back button listener
{
backButton.onClick.AddListener(OnBackButtonClicked);
}
}
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);
}
if (backButton != null) // Clean up back button listener
{
backButton.onClick.RemoveListener(OnBackButtonClicked);
}
}
/// <summary>
/// Public method to refresh UI state when returning to this page
/// </summary>
public void RefreshUI()
{
UpdateUI();
}
/// <summary>
/// Updates the UI elements based on current state
/// </summary>
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;
}
}
/// <summary>
/// Handles click on the Open Booster button
/// </summary>
private void OnOpenBoosterClicked()
{
if (_cardAlbumUI != null)
{
_cardAlbumUI.OpenBoosterPack();
}
}
/// <summary>
/// Handles click on the View Album button
/// </summary>
private void OnViewAlbumClicked()
{
if (_cardAlbumUI != null)
{
_cardAlbumUI.OpenAlbumView();
}
}
/// <summary>
/// Handles click on the Change Clothes button (coming soon)
/// </summary>
private void OnChangeClothesClicked()
{
Logging.Debug("[CardMenuPage] Change Clothes feature coming soon!");
// No implementation yet - "Coming soon" feature
}
/// <summary>
/// Handles click on the Back button
/// </summary>
private void OnBackButtonClicked()
{
// Use the UIPageController to pop this page
// This will hide the card menu and return to the game
if (UIPageController.Instance != null)
{
UIPageController.Instance.PopPage();
Logging.Debug("[CardMenuPage] Exiting card menu back to game");
}
}
/// <summary>
/// Override for transition in animation using Pixelplacement.Tween
/// </summary>
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();
}
}
/// <summary>
/// Override for transition out animation using Pixelplacement.Tween
/// </summary>
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();
}
}
}
}