Add backbone for card creation and implement Camera minigame mechanics
This commit is contained in:
177
Assets/Scripts/UI/CardSystem/CardMenuPage.cs
Normal file
177
Assets/Scripts/UI/CardSystem/CardMenuPage.cs
Normal file
@@ -0,0 +1,177 @@
|
||||
using System.Collections.Generic;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using Pixelplacement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AppleHills.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;
|
||||
|
||||
[Header("UI Elements")]
|
||||
[SerializeField] private Text boosterCountText;
|
||||
[SerializeField] private GameObject noBoostersMessage;
|
||||
[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;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <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
|
||||
if (boosterCountText != null)
|
||||
{
|
||||
boosterCountText.text = $"Boosters: {boosterCount}";
|
||||
}
|
||||
|
||||
// Enable/disable open booster button based on availability
|
||||
if (openBoosterButton != null)
|
||||
{
|
||||
openBoosterButton.interactable = boosterCount > 0;
|
||||
}
|
||||
|
||||
// Show/hide no boosters message
|
||||
if (noBoostersMessage != null)
|
||||
{
|
||||
noBoostersMessage.SetActive(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()
|
||||
{
|
||||
Debug.Log("[CardMenuPage] Change Clothes feature coming soon!");
|
||||
// No implementation yet - "Coming soon" feature
|
||||
}
|
||||
|
||||
/// <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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback if no CanvasGroup
|
||||
onComplete?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user