From e369660a8f1d31448590b7ea7dd12a285e400b76 Mon Sep 17 00:00:00 2001 From: Michal Pikulski Date: Mon, 10 Nov 2025 12:29:17 +0100 Subject: [PATCH 1/2] Fix tab navigation on card select less wonky --- .../UI/CardsSystem/ScrapBookMenu.prefab | 28 +++++++ Assets/Scripts/Data/CardSystem/CardData.cs | 1 + Assets/Scripts/UI/CardSystem/AlbumViewPage.cs | 73 ++++++++++++++++++- Assets/Scripts/UI/CardSystem/BookTabButton.cs | 13 ++++ .../DragDrop/AlbumCardPlacementDraggable.cs | 24 +++++- 5 files changed, 135 insertions(+), 4 deletions(-) diff --git a/Assets/Prefabs/UI/CardsSystem/ScrapBookMenu.prefab b/Assets/Prefabs/UI/CardsSystem/ScrapBookMenu.prefab index bd6e82c1..090db16d 100644 --- a/Assets/Prefabs/UI/CardsSystem/ScrapBookMenu.prefab +++ b/Assets/Prefabs/UI/CardsSystem/ScrapBookMenu.prefab @@ -728,10 +728,18 @@ PrefabInstance: propertyPath: m_SizeDelta.x value: 0 objectReference: {fileID: 0} + - target: {fileID: 2162084082982493373, guid: 88a05fdd940194543ade1cc2bcdada5f, type: 3} + propertyPath: tabContainer + value: + objectReference: {fileID: 7104076737882304566} - target: {fileID: 2162084082982493373, guid: 88a05fdd940194543ade1cc2bcdada5f, type: 3} propertyPath: boosterOpeningPage value: objectReference: {fileID: 304904072851265091} + - target: {fileID: 2162084082982493373, guid: 88a05fdd940194543ade1cc2bcdada5f, type: 3} + propertyPath: zoneTabs.Array.size + value: 6 + objectReference: {fileID: 0} - target: {fileID: 2162084082982493373, guid: 88a05fdd940194543ade1cc2bcdada5f, type: 3} propertyPath: cardEnlargedBackdrop value: @@ -740,6 +748,10 @@ PrefabInstance: propertyPath: cardEnlargedContainer value: objectReference: {fileID: 8702856743180718180} + - target: {fileID: 2162084082982493373, guid: 88a05fdd940194543ade1cc2bcdada5f, type: 3} + propertyPath: 'zoneTabs.Array.data[5]' + value: + objectReference: {fileID: 5733094729750047914} - target: {fileID: 2222053324174596529, guid: 88a05fdd940194543ade1cc2bcdada5f, type: 3} propertyPath: m_AnchorMax.x value: 0 @@ -1705,8 +1717,24 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 88a05fdd940194543ade1cc2bcdada5f, type: 3} +--- !u!114 &5733094729750047914 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 185814890104990467, guid: 88a05fdd940194543ade1cc2bcdada5f, type: 3} + m_PrefabInstance: {fileID: 5549612182461073321} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: ff50caabb55742bc8d24a6ddffeda815, type: 3} + m_Name: + m_EditorClassIdentifier: AppleHillsScripts::UI.CardSystem.BookTabButton --- !u!224 &5906828909529466605 stripped RectTransform: m_CorrespondingSourceObject: {fileID: 2088943967680250180, guid: 88a05fdd940194543ade1cc2bcdada5f, type: 3} m_PrefabInstance: {fileID: 5549612182461073321} m_PrefabAsset: {fileID: 0} +--- !u!224 &7104076737882304566 stripped +RectTransform: + m_CorrespondingSourceObject: {fileID: 3428064805021480863, guid: 88a05fdd940194543ade1cc2bcdada5f, type: 3} + m_PrefabInstance: {fileID: 5549612182461073321} + m_PrefabAsset: {fileID: 0} diff --git a/Assets/Scripts/Data/CardSystem/CardData.cs b/Assets/Scripts/Data/CardSystem/CardData.cs index b15e3139..8dc15f10 100644 --- a/Assets/Scripts/Data/CardSystem/CardData.cs +++ b/Assets/Scripts/Data/CardSystem/CardData.cs @@ -95,6 +95,7 @@ namespace AppleHills.Data.CardSystem public enum CardZone { + NotApplicable, AppleHills, Quarry, CementFactory, diff --git a/Assets/Scripts/UI/CardSystem/AlbumViewPage.cs b/Assets/Scripts/UI/CardSystem/AlbumViewPage.cs index e5a73580..8b4796a2 100644 --- a/Assets/Scripts/UI/CardSystem/AlbumViewPage.cs +++ b/Assets/Scripts/UI/CardSystem/AlbumViewPage.cs @@ -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(); if (canvasGroup == null) canvasGroup = gameObject.AddComponent(); - + // Hide backdrop initially if (cardEnlargedBackdrop != null) { @@ -83,6 +88,36 @@ namespace UI.CardSystem gameObject.SetActive(false); } + /// + /// Discover all BookTabButton components from the tab container + /// + 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(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 /// 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; } /// @@ -570,16 +619,27 @@ namespace UI.CardSystem /// 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 /// 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}!"); + } } /// diff --git a/Assets/Scripts/UI/CardSystem/BookTabButton.cs b/Assets/Scripts/UI/CardSystem/BookTabButton.cs index 5f627401..4650ddfa 100644 --- a/Assets/Scripts/UI/CardSystem/BookTabButton.cs +++ b/Assets/Scripts/UI/CardSystem/BookTabButton.cs @@ -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(); if (autoFlip == null) { + Debug.Log($"[PAGE-NAV-DEBUG] AutoFlip component not found, adding new component"); autoFlip = book.gameObject.AddComponent(); } + 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(); } diff --git a/Assets/Scripts/UI/CardSystem/DragDrop/AlbumCardPlacementDraggable.cs b/Assets/Scripts/UI/CardSystem/DragDrop/AlbumCardPlacementDraggable.cs index 3ca75873..6550e542 100644 --- a/Assets/Scripts/UI/CardSystem/DragDrop/AlbumCardPlacementDraggable.cs +++ b/Assets/Scripts/UI/CardSystem/DragDrop/AlbumCardPlacementDraggable.cs @@ -63,15 +63,24 @@ namespace UI.CardSystem /// 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 /// 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; } From 7c09db641acd7e6770bebcb8526773bee285bab1 Mon Sep 17 00:00:00 2001 From: Michal Pikulski Date: Mon, 10 Nov 2025 12:41:28 +0100 Subject: [PATCH 2/2] Only show cards when in actual album --- Assets/Scripts/UI/CardSystem/AlbumViewPage.cs | 75 ++++++++++++++++++- 1 file changed, 72 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/UI/CardSystem/AlbumViewPage.cs b/Assets/Scripts/UI/CardSystem/AlbumViewPage.cs index 8b4796a2..cd5d2b1b 100644 --- a/Assets/Scripts/UI/CardSystem/AlbumViewPage.cs +++ b/Assets/Scripts/UI/CardSystem/AlbumViewPage.cs @@ -56,7 +56,7 @@ namespace UI.CardSystem canvasGroup = GetComponent(); if (canvasGroup == null) canvasGroup = gameObject.AddComponent(); - + // Hide backdrop initially if (cardEnlargedBackdrop != null) { @@ -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