Fix tab navigation on card select less wonky

This commit is contained in:
Michal Pikulski
2025-11-10 12:29:17 +01:00
parent a6e3413499
commit e369660a8f
5 changed files with 135 additions and 4 deletions

View File

@@ -95,6 +95,7 @@ namespace AppleHills.Data.CardSystem
public enum CardZone
{
NotApplicable,
AppleHills,
Quarry,
CementFactory,

View File

@@ -24,7 +24,9 @@ namespace UI.CardSystem
[SerializeField] private BookCurlPro.BookPro book;
[Header("Zone Navigation")]
[SerializeField] private BookTabButton[] zoneTabs; // All zone tab buttons
[SerializeField] private Transform tabContainer; // Container holding all BookTabButton children
private BookTabButton[] zoneTabs; // Discovered zone tab buttons
[Header("Album Card Reveal")]
[SerializeField] private SlotContainer bottomRightSlots;
@@ -46,12 +48,15 @@ namespace UI.CardSystem
{
base.OnManagedAwake();
// Discover zone tabs from container
DiscoverZoneTabs();
// Make sure we have a CanvasGroup for transitions
if (canvasGroup == null)
canvasGroup = GetComponent<CanvasGroup>();
if (canvasGroup == null)
canvasGroup = gameObject.AddComponent<CanvasGroup>();
// Hide backdrop initially
if (cardEnlargedBackdrop != null)
{
@@ -83,6 +88,36 @@ namespace UI.CardSystem
gameObject.SetActive(false);
}
/// <summary>
/// Discover all BookTabButton components from the tab container
/// </summary>
private void DiscoverZoneTabs()
{
if (tabContainer == null)
{
Debug.LogError("[AlbumViewPage] Tab container is not assigned! Cannot discover zone tabs.");
zoneTabs = new BookTabButton[0];
return;
}
// Get all BookTabButton components from children
zoneTabs = tabContainer.GetComponentsInChildren<BookTabButton>(includeInactive: false);
if (zoneTabs == null || zoneTabs.Length == 0)
{
Debug.LogWarning($"[AlbumViewPage] No BookTabButton components found in tab container '{tabContainer.name}'!");
zoneTabs = new BookTabButton[0];
}
else
{
Debug.Log($"[AlbumViewPage] Discovered {zoneTabs.Length} zone tabs from container '{tabContainer.name}'");
foreach (var tab in zoneTabs)
{
Debug.Log($" - Tab: {tab.name}, Zone: {tab.Zone}, TargetPage: {tab.TargetPage}");
}
}
}
private void SetupBoosterButtonListeners()
{
if (boosterPackButtons == null) return;
@@ -427,6 +462,7 @@ namespace UI.CardSystem
private void OnCardRevealed(AlbumCardPlacementDraggable cardPlacement, CardData cardData)
{
Debug.Log($"[AlbumViewPage] Card revealed: {cardData.Name} (Zone: {cardData.Zone}, CopiesOwned: {cardData.CopiesOwned})");
Debug.Log($"[PAGE-NAV-DEBUG] OnCardRevealed - Card: {cardData.Name}, CardZone: {cardData.Zone}");
// IMMEDIATELY move card from pending to inventory upon reveal
if (CardSystemManager.Instance != null)
@@ -441,15 +477,19 @@ namespace UI.CardSystem
// Check if we're currently viewing the correct zone for this card
CardZone currentZone = GetCurrentZone();
Debug.Log($"[PAGE-NAV-DEBUG] Zone comparison - CurrentZone: {currentZone}, CardZone: {cardData.Zone}, Match: {currentZone == cardData.Zone}");
if (currentZone != cardData.Zone)
{
// Card is from a different zone - navigate to its zone
Debug.Log($"[AlbumViewPage] Card zone ({cardData.Zone}) doesn't match current zone ({currentZone}). Navigating to card's zone...");
Debug.Log($"[PAGE-NAV-DEBUG] ZONE MISMATCH - Calling NavigateToZone({cardData.Zone})");
NavigateToZone(cardData.Zone);
}
else
{
Debug.Log($"[AlbumViewPage] Card zone ({cardData.Zone}) matches current zone - no navigation needed.");
Debug.Log($"[PAGE-NAV-DEBUG] Zones match - skipping navigation");
}
// Shuffle remaining cards to front and spawn next unique card
@@ -547,22 +587,31 @@ namespace UI.CardSystem
/// </summary>
public CardZone GetCurrentZone()
{
Debug.Log($"[PAGE-NAV-DEBUG] GetCurrentZone() called");
if (book == null || zoneTabs == null || zoneTabs.Length == 0)
{
Debug.LogWarning($"[PAGE-NAV-DEBUG] GetCurrentZone - Missing references! book: {(book != null)}, zoneTabs: {(zoneTabs != null)}, zoneTabs.Length: {(zoneTabs != null ? zoneTabs.Length : 0)}");
return CardZone.AppleHills; // Default
}
int currentPage = book.CurrentPaper;
Debug.Log($"[PAGE-NAV-DEBUG] Current book page: {currentPage}");
// Find tab with matching target page
foreach (var tab in zoneTabs)
{
Debug.Log($"[PAGE-NAV-DEBUG] Checking tab - Zone: {tab.Zone}, TargetPage: {tab.TargetPage}");
if (tab.TargetPage == currentPage)
{
Debug.Log($"[PAGE-NAV-DEBUG] Found matching tab! Zone: {tab.Zone}");
return tab.Zone;
}
}
// Fallback to first zone
return zoneTabs[0].Zone;
Debug.LogWarning($"[PAGE-NAV-DEBUG] No tab matched current page {currentPage}, falling back to first zone: {CardZone.NotApplicable}");
return CardZone.NotApplicable;
}
/// <summary>
@@ -570,16 +619,27 @@ namespace UI.CardSystem
/// </summary>
public BookTabButton GetTabForZone(CardZone zone)
{
Debug.Log($"[PAGE-NAV-DEBUG] GetTabForZone({zone}) called");
if (zoneTabs == null)
{
Debug.LogError($"[PAGE-NAV-DEBUG] zoneTabs is NULL! Cannot find tab for zone {zone}");
return null;
}
Debug.Log($"[PAGE-NAV-DEBUG] Searching through {zoneTabs.Length} tabs for zone {zone}");
foreach (var tab in zoneTabs)
{
Debug.Log($"[PAGE-NAV-DEBUG] Checking tab - Zone: {tab.Zone}, TargetPage: {tab.TargetPage}, Match: {tab.Zone == zone}");
if (tab.Zone == zone)
{
Debug.Log($"[PAGE-NAV-DEBUG] FOUND matching tab for zone {zone}! TargetPage: {tab.TargetPage}");
return tab;
}
}
Debug.LogError($"[PAGE-NAV-DEBUG] NO TAB FOUND for zone {zone}! Navigation will fail.");
return null;
}
@@ -588,11 +648,18 @@ namespace UI.CardSystem
/// </summary>
public void NavigateToZone(CardZone zone)
{
Debug.Log($"[PAGE-NAV-DEBUG] NavigateToZone({zone}) called");
BookTabButton tab = GetTabForZone(zone);
if (tab != null)
{
Debug.Log($"[PAGE-NAV-DEBUG] Tab found! Calling ActivateTab() on {tab.name}");
tab.ActivateTab();
}
else
{
Debug.LogError($"[PAGE-NAV-DEBUG] NAVIGATION FAILED - No tab found for zone {zone}!");
}
}
/// <summary>

View File

@@ -67,12 +67,17 @@ namespace UI.CardSystem
private void OnButtonClicked()
{
Debug.Log($"[PAGE-NAV-DEBUG] BookTabButton.OnButtonClicked() - Tab: {gameObject.name}, Zone: {zone}, TargetPage: {targetPage}");
if (book == null)
{
Debug.LogWarning($"[BookTabButton] No BookPro reference assigned on {gameObject.name}");
Debug.LogError($"[PAGE-NAV-DEBUG] BOOK REFERENCE IS NULL! Cannot flip page.");
return;
}
Debug.Log($"[PAGE-NAV-DEBUG] Book reference valid. Current book page: {book.CurrentPaper}");
// Notify all tabs that this one was clicked
OnTabClicked?.Invoke(this);
@@ -80,11 +85,18 @@ namespace UI.CardSystem
BookCurlPro.AutoFlip autoFlip = book.GetComponent<BookCurlPro.AutoFlip>();
if (autoFlip == null)
{
Debug.Log($"[PAGE-NAV-DEBUG] AutoFlip component not found, adding new component");
autoFlip = book.gameObject.AddComponent<BookCurlPro.AutoFlip>();
}
else
{
Debug.Log($"[PAGE-NAV-DEBUG] AutoFlip component found, enabled: {autoFlip.enabled}");
}
autoFlip.enabled = true;
Debug.Log($"[PAGE-NAV-DEBUG] Calling autoFlip.StartFlipping({targetPage})");
autoFlip.StartFlipping(targetPage);
Debug.Log($"[PAGE-NAV-DEBUG] Page flip initiated to page {targetPage}");
}
private void OnAnyTabClicked(BookTabButton clickedTab)
@@ -116,6 +128,7 @@ namespace UI.CardSystem
// Public method to programmatically trigger this tab
public void ActivateTab()
{
Debug.Log($"[PAGE-NAV-DEBUG] ActivateTab() called on {gameObject.name} (Zone: {zone}, TargetPage: {targetPage})");
OnButtonClicked();
}

View File

@@ -63,15 +63,24 @@ namespace UI.CardSystem
/// </summary>
public void RevealCard()
{
if (_isRevealed) return;
Debug.Log($"[PAGE-NAV-DEBUG] RevealCard() called - _isRevealed: {_isRevealed}");
if (_isRevealed)
{
Debug.LogWarning($"[PAGE-NAV-DEBUG] Card already revealed, skipping reveal");
return;
}
_isRevealed = true;
Debug.Log($"[PAGE-NAV-DEBUG] Setting _isRevealed = true, card zone: {(_cardData != null ? _cardData.Zone.ToString() : "NULL")}");
if (flippableCard != null)
{
flippableCard.FlipToReveal();
}
Debug.Log($"[PAGE-NAV-DEBUG] Invoking OnCardRevealed event (subscribers: {(OnCardRevealed != null ? OnCardRevealed.GetInvocationList().Length : 0)})");
OnCardRevealed?.Invoke(this, _cardData);
}
@@ -199,9 +208,14 @@ namespace UI.CardSystem
// Cancel hold timer if running
if (_holdRevealCoroutine != null)
{
Debug.LogWarning($"[PAGE-NAV-DEBUG] OnPointerUpHook - CANCELLING HoldRevealTimer coroutine! Card was released before reveal completed.");
StopCoroutine(_holdRevealCoroutine);
_holdRevealCoroutine = null;
}
else
{
Debug.Log($"[PAGE-NAV-DEBUG] OnPointerUpHook - No hold timer to cancel (either completed or never started)");
}
// Handle tap (not dragged)
if (!_wasDragged)
@@ -243,15 +257,23 @@ namespace UI.CardSystem
/// </summary>
private IEnumerator HoldRevealTimer()
{
Debug.Log($"[PAGE-NAV-DEBUG] HoldRevealTimer started, waiting {holdRevealDelay}s...");
yield return new WaitForSeconds(holdRevealDelay);
Debug.Log($"[PAGE-NAV-DEBUG] HoldRevealTimer completed - _isRevealed: {_isRevealed}, _isHolding: {_isHolding}");
// If still holding after delay, reveal the card
if (!_isRevealed && _isHolding)
{
Debug.Log($"[PAGE-NAV-DEBUG] Hold timer conditions met - calling RevealCard() for zone: {(_cardData != null ? _cardData.Zone.ToString() : "NULL")}");
RevealCard();
_isDragRevealing = true;
Debug.Log("[AlbumCardDraggable] Card revealed via hold");
}
else
{
Debug.LogWarning($"[PAGE-NAV-DEBUG] Hold timer completed but conditions NOT met - _isRevealed: {_isRevealed}, _isHolding: {_isHolding}. Card will NOT reveal!");
}
_holdRevealCoroutine = null;
}