Working bottom-corner card display

This commit is contained in:
Michal Pikulski
2025-11-17 23:38:34 +01:00
parent b5364a2bbc
commit e18f1b9963
7 changed files with 49467 additions and 15232 deletions

View File

@@ -489,42 +489,106 @@ namespace UI.CardSystem
}
/// <summary>
/// Rebuild corner card display from scratch.
/// Rebuild corner card display incrementally.
/// Flow: 1) Shuffle remaining cards to front slots (0→1→2)
/// 2) Spawn new card in last slot if needed
/// Called on initial spawn and after card is removed.
/// </summary>
private void RebuildCornerCards()
{
if (cardPrefab == null || bottomRightSlots == null) return;
// Step 1: Clear all existing cards from slots
CleanupPendingCornerCards();
// Step 2: Establish total amount and amount to display
// Step 1: Determine how many cards should be displayed
var uniquePending = GetUniquePendingCards();
int totalPendingCards = uniquePending.Count;
int cardsToDisplay = Mathf.Min(totalPendingCards, MaxPendingCorner);
if (cardsToDisplay == 0)
int currentCardCount = _pendingCornerCards.Count;
Logging.Debug($"[AlbumViewPage] RebuildCornerCards: current={currentCardCount}, target={cardsToDisplay}");
// Step 2: Remove excess cards if we have too many
while (_pendingCornerCards.Count > cardsToDisplay)
{
Logging.Debug("[AlbumViewPage] No pending cards to display in corner");
return;
int lastIndex = _pendingCornerCards.Count - 1;
var cardToRemove = _pendingCornerCards[lastIndex];
if (cardToRemove != null)
{
if (cardToRemove.Context != null)
{
cardToRemove.Context.OnDragStarted -= OnCardDragStarted;
}
Destroy(cardToRemove.gameObject);
}
_pendingCornerCards.RemoveAt(lastIndex);
Logging.Debug($"[AlbumViewPage] Removed excess card, now have {_pendingCornerCards.Count}");
}
Logging.Debug($"[AlbumViewPage] Rebuilding corner: displaying {cardsToDisplay} of {totalPendingCards} pending cards");
// Step 3: Shuffle remaining cards to occupy first slots (0, 1, 2)
ShuffleCardsToFrontSlots();
// Step 3: Spawn cards, starting from slot index 0 -> 1 -> 2
for (int slotIndex = 0; slotIndex < cardsToDisplay; slotIndex++)
// Step 4: Spawn new cards in remaining slots if needed
while (_pendingCornerCards.Count < cardsToDisplay)
{
// Step 3.1: Get slot with this index
int slotIndex = _pendingCornerCards.Count; // Next available slot
var slot = FindSlotByIndex(slotIndex);
if (slot == null)
{
Logging.Warning($"[AlbumViewPage] Slot {slotIndex} not found, stopping spawn");
break;
}
// Step 3.2 & 3.3: Spawn card in slot (matching transform, in PendingFaceDownState)
SpawnCardInSlot(slot);
Logging.Debug($"[AlbumViewPage] Added new card in slot {slotIndex}, now have {_pendingCornerCards.Count}");
}
if (cardsToDisplay == 0)
{
Logging.Debug("[AlbumViewPage] No pending cards to display in corner");
}
}
/// <summary>
/// Shuffle remaining cards to occupy the first available slots (0 → 1 → 2).
/// Example: If we have 2 cards in slots 0 and 2, move the card from slot 2 to slot 1.
/// </summary>
private void ShuffleCardsToFrontSlots()
{
if (_pendingCornerCards.Count == 0) return;
Logging.Debug($"[AlbumViewPage] Shuffling {_pendingCornerCards.Count} cards to front slots");
// Reassign each card to the first N slots (0, 1, 2...)
for (int i = 0; i < _pendingCornerCards.Count; i++)
{
var card = _pendingCornerCards[i];
var targetSlot = FindSlotByIndex(i);
if (targetSlot == null)
{
Logging.Warning($"[AlbumViewPage] Could not find slot with index {i} during shuffle");
continue;
}
// Check if card is already in the correct slot
if (card.CurrentSlot == targetSlot)
{
// Already in correct slot, skip
continue;
}
// Vacate current slot if occupied
if (card.CurrentSlot != null)
{
card.CurrentSlot.Vacate();
}
// Assign to target slot with animation
card.AssignToSlot(targetSlot, true); // true = animate
Logging.Debug($"[AlbumViewPage] Shuffled card {i} to slot {targetSlot.SlotIndex}");
}
}
@@ -547,12 +611,13 @@ namespace UI.CardSystem
return;
}
// Setup card for pending state (transitions to PendingFaceDownState)
card.SetupForAlbumPending();
// Assign to slot (handles transform matching)
// IMPORTANT: Assign to slot FIRST (establishes correct transform)
card.AssignToSlot(slot, false); // false = instant, no animation
// THEN setup card for pending state (transitions to PendingFaceDownState)
// This ensures OriginalScale is captured AFTER slot assignment
card.SetupForAlbumPending();
// Subscribe to drag events for reorganization
card.Context.OnDragStarted += OnCardDragStarted;