Only show cards when in actual album

This commit is contained in:
Michal Pikulski
2025-11-10 12:41:28 +01:00
parent e369660a8f
commit 7c09db641a

View File

@@ -72,6 +72,17 @@ namespace UI.CardSystem
// Set up booster pack button listeners
SetupBoosterButtonListeners();
// Subscribe to book page flip events
if (book != null)
{
book.OnFlip.AddListener(OnPageFlipped);
Debug.Log("[AlbumViewPage] Subscribed to book.OnFlip event");
}
else
{
Debug.LogWarning("[AlbumViewPage] Book reference is null, cannot subscribe to OnFlip event!");
}
// Subscribe to CardSystemManager events (managers are guaranteed to be initialized)
if (CardSystemManager.Instance != null)
{
@@ -125,6 +136,12 @@ namespace UI.CardSystem
for (int i = 0; i < boosterPackButtons.Length; i++)
{
if (boosterPackButtons[i] == null) continue;
// Unsubscribe from book events
if (book != null)
{
book.OnFlip.RemoveListener(OnPageFlipped);
}
Button button = boosterPackButtons[i].GetComponent<Button>();
if (button != null)
@@ -252,8 +269,16 @@ namespace UI.CardSystem
CardSystemManager.Instance.OnPendingCardAdded += OnPendingCardAdded;
}
// Spawn pending cards when opening album
// Only spawn pending cards if we're already on an album page (not the menu)
if (IsInAlbumProper())
{
Debug.Log("[AlbumViewPage] Opening directly to album page - spawning cards immediately");
SpawnPendingCards();
}
else
{
Debug.Log("[AlbumViewPage] Opening to menu page - cards will spawn when entering album");
}
base.TransitionIn();
}
@@ -342,6 +367,50 @@ namespace UI.CardSystem
}
}
/// <summary>
/// Check if we're currently viewing the album proper (not the menu page)
/// </summary>
private bool IsInAlbumProper()
{
if (book == null)
{
Debug.LogWarning("[AlbumViewPage] Book reference is null in IsInAlbumProper check");
return false;
}
// Page 1 is the menu/cover, page 2+ are album pages with card slots
bool inAlbum = book.CurrentPaper > 1;
Debug.Log($"[PAGE-NAV-DEBUG] IsInAlbumProper check - CurrentPage: {book.CurrentPaper}, InAlbum: {inAlbum}");
return inAlbum;
}
/// <summary>
/// Called when book page flips - show/hide pending cards based on whether we're in the album proper
/// </summary>
private void OnPageFlipped()
{
bool isInAlbum = IsInAlbumProper();
Debug.Log($"[PAGE-NAV-DEBUG] OnPageFlipped - CurrentPage: {book.CurrentPaper}, IsInAlbum: {isInAlbum}, CardsCurrentlySpawned: {_activeCards.Count}");
if (isInAlbum && _activeCards.Count == 0)
{
// Entering album proper and no cards spawned yet - spawn them with animation
Debug.Log("[AlbumViewPage] Entering album proper - spawning pending cards with animation");
SpawnPendingCards();
}
else if (!isInAlbum && _activeCards.Count > 0)
{
// Returning to menu page - cleanup cards
Debug.Log("[AlbumViewPage] Returning to menu page - cleaning up pending cards");
CleanupActiveCards();
}
else
{
Debug.Log($"[AlbumViewPage] Page flipped but no card state change needed (already in correct state)");
}
}
#region Album Card Reveal System
/// <summary>