Merge a card refresh #59
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f4ec75013bc276429c2f4fa52d165e0
|
||||
guid: bcbebd216e6c867409206d33b4395b5b
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53996921ed2094948aa317efe4ca6630
|
||||
guid: 7e3c8a4745009804b9a620e3ae15070f
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
|
||||
@@ -216,6 +216,13 @@ namespace Editor.CardSystem
|
||||
|
||||
EditorGUILayout.Space(5);
|
||||
|
||||
if (GUILayout.Button("Populate Pending (6 Unique Cards)", GUILayout.Height(30)))
|
||||
{
|
||||
PopulatePendingCards();
|
||||
}
|
||||
|
||||
EditorGUILayout.Space(5);
|
||||
|
||||
// Danger Zone
|
||||
EditorGUILayout.Space(10);
|
||||
EditorGUILayout.LabelField("Danger Zone", EditorStyles.miniBoldLabel);
|
||||
@@ -304,6 +311,53 @@ namespace Editor.CardSystem
|
||||
}
|
||||
}
|
||||
|
||||
private void PopulatePendingCards()
|
||||
{
|
||||
if (CardSystemManager.Instance != null)
|
||||
{
|
||||
List<CardDefinition> allDefinitions = CardSystemManager.Instance.GetAllCardDefinitions();
|
||||
|
||||
if (allDefinitions.Count == 0)
|
||||
{
|
||||
lastActionMessage = "Error: No card definitions available";
|
||||
Logging.Warning($"[CardSystemTesterWindow] {lastActionMessage}");
|
||||
Repaint();
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure we have enough definitions to pick 6 unique cards
|
||||
int cardsToAdd = Mathf.Min(6, allDefinitions.Count);
|
||||
|
||||
// Shuffle definitions to get random unique cards
|
||||
List<CardDefinition> shuffledDefs = new List<CardDefinition>(allDefinitions);
|
||||
for (int i = 0; i < shuffledDefs.Count; i++)
|
||||
{
|
||||
int randomIndex = Random.Range(i, shuffledDefs.Count);
|
||||
(shuffledDefs[i], shuffledDefs[randomIndex]) = (shuffledDefs[randomIndex], shuffledDefs[i]);
|
||||
}
|
||||
|
||||
// Add first 6 unique cards to pending
|
||||
// AddCardToInventoryDelayed automatically routes NEW cards to pending queue
|
||||
int cardsAdded = 0;
|
||||
for (int i = 0; i < cardsToAdd; i++)
|
||||
{
|
||||
CardData newCard = shuffledDefs[i].CreateCardData();
|
||||
CardSystemManager.Instance.AddCardToInventoryDelayed(newCard);
|
||||
cardsAdded++;
|
||||
}
|
||||
|
||||
lastActionMessage = $"Added {cardsAdded} unique cards to pending reveal queue";
|
||||
Logging.Debug($"[CardSystemTesterWindow] {lastActionMessage}");
|
||||
RefreshDebugInfo();
|
||||
}
|
||||
else
|
||||
{
|
||||
lastActionMessage = "Error: CardSystemManager instance not found!";
|
||||
Debug.LogError("[CardSystemTesterWindow] " + lastActionMessage);
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearAllCards()
|
||||
{
|
||||
if (CardSystemManager.Instance != null)
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -163,6 +163,25 @@ namespace UI.CardSystem.StateMachine
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update card data without re-capturing original transform values.
|
||||
/// Use this when assigning data to an already-initialized card (e.g., pending cards on drag).
|
||||
/// This prevents changing OriginalScale when the card is already correctly sized.
|
||||
/// </summary>
|
||||
public void UpdateCardData(CardData data)
|
||||
{
|
||||
cardData = data;
|
||||
_hasCompletedReveal = false; // Reset completion flag
|
||||
|
||||
// Don't re-capture OriginalScale/Position/Rotation
|
||||
// This preserves the transform values captured during initial setup
|
||||
|
||||
if (cardDisplay != null)
|
||||
{
|
||||
cardDisplay.SetupCard(data);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the card display component
|
||||
/// </summary>
|
||||
|
||||
@@ -32,6 +32,9 @@ namespace UI.CardSystem.StateMachine.States
|
||||
_targetSlot = null;
|
||||
_dragEndedDuringFlip = false;
|
||||
|
||||
// Reset scale to normal (in case transitioning from scaled state)
|
||||
_context.RootTransform.localScale = Vector3.one;
|
||||
|
||||
// Show card back, hide card front
|
||||
if (cardBackVisual != null)
|
||||
{
|
||||
@@ -70,7 +73,9 @@ namespace UI.CardSystem.StateMachine.States
|
||||
}
|
||||
|
||||
// Step 3: Apply card data to context
|
||||
context.SetupCard(cardData);
|
||||
// Use UpdateCardData instead of SetupCard to preserve OriginalScale
|
||||
// (card was already initialized with correct scale in SpawnCardInSlot)
|
||||
context.UpdateCardData(cardData);
|
||||
Logging.Debug($"[CardPendingFaceDownState] Assigned card data: {cardData.Name} ({cardData.Zone})");
|
||||
|
||||
// Step 4: Ask AlbumViewPage for target slot
|
||||
|
||||
64516
card_diff.txt
64516
card_diff.txt
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user