Update pages to follow new card flow
This commit is contained in:
@@ -137,12 +137,7 @@ 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)
|
||||
@@ -154,6 +149,12 @@ namespace UI.CardSystem
|
||||
|
||||
internal override void OnManagedDestroy()
|
||||
{
|
||||
// Unsubscribe from book events
|
||||
if (book != null)
|
||||
{
|
||||
book.OnFlip.RemoveListener(OnPageFlipped);
|
||||
}
|
||||
|
||||
// Unsubscribe from CardSystemManager
|
||||
if (CardSystemManager.Instance != null)
|
||||
{
|
||||
@@ -182,8 +183,8 @@ namespace UI.CardSystem
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up active cards
|
||||
CleanupActiveCards();
|
||||
// Clean up pending corner cards
|
||||
CleanupPendingCornerCards();
|
||||
}
|
||||
|
||||
private void OnExitButtonClicked()
|
||||
@@ -271,7 +272,7 @@ namespace UI.CardSystem
|
||||
if (IsInAlbumProper())
|
||||
{
|
||||
Logging.Debug("[AlbumViewPage] Opening directly to album page - spawning cards immediately");
|
||||
SpawnPendingCards();
|
||||
SpawnPendingCornerCards();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -290,7 +291,7 @@ namespace UI.CardSystem
|
||||
}
|
||||
|
||||
// Clean up active pending cards to prevent duplicates on next opening
|
||||
CleanupActiveCards();
|
||||
CleanupPendingCornerCards();
|
||||
|
||||
// Don't restore input mode here - only restore when actually exiting (in OnExitButtonClicked)
|
||||
base.TransitionOut();
|
||||
@@ -383,17 +384,17 @@ namespace UI.CardSystem
|
||||
private void OnPageFlipped()
|
||||
{
|
||||
bool isInAlbum = IsInAlbumProper();
|
||||
if (isInAlbum && _activeCards.Count == 0)
|
||||
if (isInAlbum && _pendingCornerCards.Count == 0)
|
||||
{
|
||||
// Entering album proper and no cards spawned yet - spawn them with animation
|
||||
Logging.Debug("[AlbumViewPage] Entering album proper - spawning pending cards with animation");
|
||||
SpawnPendingCards();
|
||||
SpawnPendingCornerCards();
|
||||
}
|
||||
else if (!isInAlbum && _activeCards.Count > 0)
|
||||
else if (!isInAlbum && _pendingCornerCards.Count > 0)
|
||||
{
|
||||
// Returning to menu page - cleanup cards
|
||||
Logging.Debug("[AlbumViewPage] Returning to menu page - cleaning up pending cards");
|
||||
CleanupActiveCards();
|
||||
CleanupPendingCornerCards();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -696,6 +697,7 @@ namespace UI.CardSystem
|
||||
{
|
||||
card.SetupForAlbumPending();
|
||||
card.AssignToSlot(slot, true);
|
||||
card.Context.OnDragStarted += OnCardDragStarted;
|
||||
_pendingCornerCards.Add(card);
|
||||
}
|
||||
else
|
||||
@@ -709,28 +711,45 @@ namespace UI.CardSystem
|
||||
{
|
||||
foreach (var c in _pendingCornerCards)
|
||||
{
|
||||
if (c != null) Destroy(c.gameObject);
|
||||
if (c != null)
|
||||
{
|
||||
if (c.Context != null)
|
||||
{
|
||||
c.Context.OnDragStarted -= OnCardDragStarted;
|
||||
}
|
||||
Destroy(c.gameObject);
|
||||
}
|
||||
}
|
||||
_pendingCornerCards.Clear();
|
||||
}
|
||||
|
||||
public void HandlePendingCardDragStart(StateMachine.Card cornerCard)
|
||||
private void OnCardDragStarted(StateMachine.CardContext context)
|
||||
{
|
||||
if (context == null) return;
|
||||
|
||||
// Only handle if in PendingFaceDownState
|
||||
var card = context.GetComponent<StateMachine.Card>();
|
||||
if (card == null) return;
|
||||
|
||||
string stateName = card.GetCurrentStateName();
|
||||
if (stateName != "PendingFaceDownState") return;
|
||||
|
||||
// Select smart pending card data
|
||||
var selected = SelectSmartPendingCard();
|
||||
if (selected == null)
|
||||
{
|
||||
return; // no pending data
|
||||
}
|
||||
cornerCard.Context.SetupCard(selected);
|
||||
context.SetupCard(selected);
|
||||
|
||||
// Navigate album to page
|
||||
int targetPage = FindPageForCard(selected);
|
||||
if (targetPage >= 0)
|
||||
{
|
||||
NavigateToAlbumPage(targetPage);
|
||||
}
|
||||
// Begin flip state
|
||||
cornerCard.ChangeState("FlippingPendingState");
|
||||
|
||||
// State will handle transition to FlippingPendingState
|
||||
}
|
||||
|
||||
private CardData SelectSmartPendingCard()
|
||||
@@ -749,19 +768,88 @@ namespace UI.CardSystem
|
||||
|
||||
private List<string> GetDefinitionsOnCurrentPage()
|
||||
{
|
||||
// Placeholder: gather from slots on current page
|
||||
return new List<string>();
|
||||
var result = new List<string>();
|
||||
if (book == null) return result;
|
||||
|
||||
int currentPage = book.CurrentPaper;
|
||||
|
||||
// Find all AlbumCardSlot in scene
|
||||
var allSlots = FindObjectsByType<AlbumCardSlot>(FindObjectsSortMode.None);
|
||||
|
||||
foreach (var slot in allSlots)
|
||||
{
|
||||
if (IsSlotOnPage(slot.transform, currentPage))
|
||||
{
|
||||
if (slot.TargetCardDefinition != null && !string.IsNullOrEmpty(slot.TargetCardDefinition.Id))
|
||||
{
|
||||
result.Add(slot.TargetCardDefinition.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private bool IsSlotOnPage(Transform slotTransform, int pageIndex)
|
||||
{
|
||||
if (book == null || book.papers == null || pageIndex < 0 || pageIndex >= book.papers.Length)
|
||||
return false;
|
||||
|
||||
var paper = book.papers[pageIndex];
|
||||
if (paper == null) return false;
|
||||
|
||||
// Check if slotTransform parent hierarchy contains paper.Front or paper.Back
|
||||
Transform current = slotTransform;
|
||||
while (current != null)
|
||||
{
|
||||
if ((paper.Front != null && current.gameObject == paper.Front) ||
|
||||
(paper.Back != null && current.gameObject == paper.Back))
|
||||
return true;
|
||||
current = current.parent;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private int FindPageForCard(CardData data)
|
||||
{
|
||||
// Placeholder: map definition to page index
|
||||
if (data == null || book == null || book.papers == null) return -1;
|
||||
|
||||
// Find all AlbumCardSlot in scene
|
||||
var allSlots = FindObjectsByType<AlbumCardSlot>(FindObjectsSortMode.None);
|
||||
|
||||
foreach (var slot in allSlots)
|
||||
{
|
||||
if (slot.TargetCardDefinition != null && slot.TargetCardDefinition.Id == data.DefinitionId)
|
||||
{
|
||||
// Found matching slot, now find which page it's on
|
||||
for (int i = 0; i < book.papers.Length; i++)
|
||||
{
|
||||
if (IsSlotOnPage(slot.transform, i))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void NavigateToAlbumPage(int pageIndex)
|
||||
{
|
||||
// Placeholder: call book/page flip controller
|
||||
if (book == null || pageIndex < 0) return;
|
||||
|
||||
// Get or add AutoFlip component
|
||||
BookCurlPro.AutoFlip autoFlip = book.GetComponent<BookCurlPro.AutoFlip>();
|
||||
if (autoFlip == null)
|
||||
{
|
||||
autoFlip = book.gameObject.AddComponent<BookCurlPro.AutoFlip>();
|
||||
}
|
||||
|
||||
// Start flipping to target page
|
||||
autoFlip.enabled = true;
|
||||
autoFlip.StartFlipping(pageIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user