Files
AppleHillsProduction/Assets/Scripts/UI/CardSystem/AlbumViewPage.cs

97 lines
3.0 KiB
C#
Raw Normal View History

using Pixelplacement;
using UI.Core;
using UnityEngine;
using UnityEngine.UI;
namespace UI.CardSystem
{
/// <summary>
2025-10-20 08:32:57 +02:00
/// UI page for viewing the player's card collection in an album.
/// </summary>
public class AlbumViewPage : UIPage
{
2025-10-15 09:22:13 +02:00
[SerializeField] private CanvasGroup canvasGroup;
[SerializeField] private Button exitButton;
[SerializeField] private BookCurlPro.BookPro book;
private void Awake()
{
2025-10-15 09:22:13 +02:00
// 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);
}
2025-10-15 09:22:13 +02:00
// UI pages should start disabled
gameObject.SetActive(false);
}
private void OnDestroy()
{
if (exitButton != null)
2025-10-15 09:22:13 +02:00
{
exitButton.onClick.RemoveListener(OnExitButtonClicked);
2025-10-15 09:22:13 +02:00
}
}
2025-10-20 13:45:56 +02:00
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)
2025-10-15 09:22:13 +02:00
{
autoFlip = book.gameObject.AddComponent<BookCurlPro.AutoFlip>();
2025-10-15 09:22:13 +02:00
}
autoFlip.enabled = true;
autoFlip.StartFlipping(1);
}
else
{
// Already on page 0 or no book reference, exit
if (UIPageController.Instance != null)
2025-10-15 09:22:13 +02:00
{
UIPageController.Instance.PopPage();
2025-10-15 09:22:13 +02:00
}
}
2025-10-15 09:22:13 +02:00
}
protected override void DoTransitionIn(System.Action onComplete)
{
2025-10-20 13:45:56 +02:00
// Simple fade in animation
2025-10-15 09:22:13 +02:00
if (canvasGroup != null)
{
2025-10-15 09:22:13 +02:00
canvasGroup.alpha = 0f;
2025-10-27 15:21:23 +01:00
Tween.Value(0f, 1f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete, obeyTimescale: false);
}
else
{
2025-10-20 13:45:56 +02:00
// Fallback if no CanvasGroup
onComplete?.Invoke();
}
}
protected override void DoTransitionOut(System.Action onComplete)
{
2025-10-20 13:45:56 +02:00
// Simple fade out animation
2025-10-15 09:22:13 +02:00
if (canvasGroup != null)
{
2025-10-27 15:21:23 +01:00
Tween.Value(canvasGroup.alpha, 0f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete, obeyTimescale: false);
}
else
{
2025-10-20 13:45:56 +02:00
// Fallback if no CanvasGroup
onComplete?.Invoke();
2025-10-15 09:22:13 +02:00
}
}
}
}