Fix tab navigation on card select less wonky
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user