Almost working card state machine

This commit is contained in:
Michal Pikulski
2025-11-16 20:35:54 +01:00
parent 6fe7d012fc
commit 78aafb9275
42 changed files with 3057 additions and 3077 deletions

View File

@@ -8,6 +8,7 @@ using UI.Core;
using UI.DragAndDrop.Core;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Serialization;
namespace UI.CardSystem
{
@@ -29,7 +30,8 @@ namespace UI.CardSystem
[Header("Album Card Reveal")]
[SerializeField] private SlotContainer bottomRightSlots;
[SerializeField] private GameObject albumCardPlacementPrefab; // The wrapper prefab with flip/drag (AlbumPlacementCard)
[FormerlySerializedAs("albumCardPlacementPrefab")]
[SerializeField] private GameObject cardPrefab; // New Card prefab for placement
[Header("Card Enlarge System")]
[SerializeField] private GameObject cardEnlargedBackdrop; // Backdrop to block interactions
@@ -40,7 +42,7 @@ namespace UI.CardSystem
[SerializeField] private BoosterOpeningPage boosterOpeningPage;
private Input.InputMode _previousInputMode;
private List<AlbumCardPlacementDraggable> _activeCards = new List<AlbumCardPlacementDraggable>();
private List<StateMachine.Card> _activeCards = new List<StateMachine.Card>();
private const int MAX_VISIBLE_CARDS = 3;
internal override void OnManagedStart()
@@ -338,24 +340,20 @@ namespace UI.CardSystem
// If there's an enlarged card in the container, return it to its slot
if (cardEnlargedContainer != null && cardEnlargedContainer.childCount > 0)
{
// Get all enlarged cards (should only be one, but just in case)
for (int i = cardEnlargedContainer.childCount - 1; i >= 0; i--)
{
Transform cardTransform = cardEnlargedContainer.GetChild(i);
AlbumCard albumCard = cardTransform.GetComponent<AlbumCard>();
if (albumCard != null && albumCard.IsEnlarged)
var card = cardTransform.GetComponent<StateMachine.Card>();
var state = cardTransform.GetComponentInChildren<StateMachine.States.CardAlbumEnlargedState>(true);
if (card != null && state != null)
{
// Force reset state and return to slot
Transform originalParent = albumCard.GetOriginalParent();
Transform originalParent = state.GetOriginalParent();
if (originalParent != null)
{
cardTransform.SetParent(originalParent, true);
cardTransform.localPosition = albumCard.GetOriginalLocalPosition();
cardTransform.localRotation = albumCard.GetOriginalLocalRotation();
cardTransform.localPosition = state.GetOriginalLocalPosition();
cardTransform.localRotation = state.GetOriginalLocalRotation();
}
albumCard.ForceResetEnlargedState();
}
}
}
@@ -409,17 +407,15 @@ namespace UI.CardSystem
/// </summary>
private void SpawnPendingCards()
{
if (CardSystemManager.Instance == null || bottomRightSlots == null || albumCardPlacementPrefab == null)
if (CardSystemManager.Instance == null || bottomRightSlots == null || cardPrefab == null)
return;
var pending = CardSystemManager.Instance.GetPendingRevealCards();
// Get unique cards only (by DefinitionId + Rarity)
// Filter out cards with CopiesOwned = 0 (shouldn't happen but guard against it)
var uniquePending = pending
.Where(c => c.CopiesOwned > 0) // Guard: exclude zero-count cards
.Where(c => c.CopiesOwned > 0)
.GroupBy(c => new { c.DefinitionId, c.Rarity })
.Select(g => g.First()) // Take first instance of each unique card
.Select(g => g.First())
.ToList();
int spawnCount = Mathf.Min(uniquePending.Count, MAX_VISIBLE_CARDS);
@@ -433,11 +429,10 @@ namespace UI.CardSystem
}
/// <summary>
/// Spawn a card in a specific slot
/// Spawn a card in a specific slot using the new Card prefab
/// </summary>
private void SpawnCardInSlot(int slotIndex, CardData cardData)
{
// Guard: Don't spawn cards with zero copies
if (cardData.CopiesOwned <= 0)
{
Logging.Warning($"[AlbumViewPage] Skipping spawn of card '{cardData.Name}' with {cardData.CopiesOwned} copies");
@@ -451,38 +446,190 @@ namespace UI.CardSystem
return;
}
// Instantiate card directly as child of the slot container (not the slot itself, not canvas root)
// This keeps it in the correct UI hierarchy
GameObject cardObj = Instantiate(albumCardPlacementPrefab, bottomRightSlots.transform);
AlbumCardPlacementDraggable cardPlacement = cardObj.GetComponent<AlbumCardPlacementDraggable>();
if (cardPlacement != null)
GameObject cardObj = Instantiate(cardPrefab, bottomRightSlots.transform);
var card = cardObj.GetComponent<StateMachine.Card>();
if (card != null)
{
// Setup card data
cardPlacement.SetupCard(cardData);
// Cards spawned here are already revealed and can be dragged into album
card.SetupForAlbumPlacement(cardData);
// Subscribe to events
cardPlacement.OnCardRevealed += OnCardRevealed;
cardPlacement.OnCardPlacedInAlbum += OnCardPlacedInAlbum;
// Assign to slot with animation (will apply size/position)
card.AssignToSlot(slot, true);
// NOW assign to slot - this will:
// 1. Reparent to slot
// 2. Apply slot's occupantSizeMode scaling
// 3. Animate to slot position
cardPlacement.AssignToSlot(slot, true);
// Track placement completion to clean up
card.OnPlacedInAlbumSlot += OnCardPlacedInAlbum;
// Track it
_activeCards.Add(cardPlacement);
_activeCards.Add(card);
Logging.Debug($"[AlbumViewPage] Spawned card '{cardData.Name}' (CopiesOwned: {cardData.CopiesOwned}) in slot {slotIndex}");
Logging.Debug($"[AlbumViewPage] Spawned pending card '{cardData.Name}' in slot {slotIndex}");
}
else
{
Logging.Warning($"[AlbumViewPage] Spawned card has no AlbumCardDraggable component!");
Logging.Warning($"[AlbumViewPage] Spawned card prefab missing Card component!");
Destroy(cardObj);
}
}
/// <summary>
/// Handle when a card is placed in an album slot from the pending list
/// Moves from pending to inventory, shuffles remaining, and spawns the next unique card.
/// </summary>
private void OnCardPlacedInAlbum(StateMachine.Card card, AlbumCardSlot slot)
{
if (card == null) return;
var data = card.CardData;
Logging.Debug($"[AlbumViewPage] Card placed in album slot: {data?.Name}");
// Move card from pending to inventory now
if (data != null && CardSystemManager.Instance != null)
{
CardSystemManager.Instance.MarkCardAsPlaced(data);
}
// Stop tracking and unsubscribe
card.OnPlacedInAlbumSlot -= OnCardPlacedInAlbum;
_activeCards.Remove(card);
// Shuffle remaining cards to front and spawn next
ShuffleCardsToFront();
TrySpawnNextCard();
}
/// <summary>
/// Shuffle active cards to occupy front slots
/// </summary>
private void ShuffleCardsToFront()
{
if (bottomRightSlots == null || _activeCards.Count == 0)
return;
List<DraggableObject> draggableList = _activeCards.Cast<DraggableObject>().ToList();
SlotContainerHelper.ShuffleToFront(bottomRightSlots, draggableList, animate: true);
}
/// <summary>
/// Try to spawn the next pending unique card
/// </summary>
private void TrySpawnNextCard()
{
if (CardSystemManager.Instance == null)
return;
if (_activeCards.Count >= MAX_VISIBLE_CARDS)
return;
var pending = CardSystemManager.Instance.GetPendingRevealCards();
var uniquePending = pending
.Where(c => c.CopiesOwned > 0)
.GroupBy(c => new { c.DefinitionId, c.Rarity })
.Select(g => g.First())
.ToList();
foreach (var cardData in uniquePending)
{
bool alreadySpawned = _activeCards.Any(c =>
c.CardData.DefinitionId == cardData.DefinitionId &&
c.CardData.Rarity == cardData.Rarity);
if (!alreadySpawned)
{
int nextSlotIndex = _activeCards.Count;
SpawnCardInSlot(nextSlotIndex, cardData);
break;
}
}
}
/// <summary>
/// Clean up all active pending cards
/// </summary>
private void CleanupActiveCards()
{
foreach (var card in _activeCards)
{
if (card != null && card.gameObject != null)
{
card.OnPlacedInAlbumSlot -= OnCardPlacedInAlbum;
Destroy(card.gameObject);
}
}
_activeCards.Clear();
}
#endregion
#region Card Enlarge System (Album Slots)
/// <summary>
/// Subscribe to a placed card's enlarged state events to manage backdrop and reparenting.
/// Called by AlbumCardSlot when it spawns an owned card in a slot.
/// </summary>
public void RegisterCardInAlbum(StateMachine.Card card)
{
if (card == null) return;
var enlargeState = card.GetStateComponent<StateMachine.States.CardAlbumEnlargedState>("AlbumEnlargedState");
if (enlargeState != null)
{
enlargeState.OnEnlargeRequested += OnCardEnlargeRequested;
enlargeState.OnShrinkRequested += OnCardShrinkRequested;
}
}
public void UnregisterCardInAlbum(StateMachine.Card card)
{
if (card == null) return;
var enlargeState = card.GetStateComponent<StateMachine.States.CardAlbumEnlargedState>("AlbumEnlargedState");
if (enlargeState != null)
{
enlargeState.OnEnlargeRequested -= OnCardEnlargeRequested;
enlargeState.OnShrinkRequested -= OnCardShrinkRequested;
}
}
private void OnCardEnlargeRequested(StateMachine.States.CardAlbumEnlargedState state)
{
if (state == null) return;
// Show backdrop
if (cardEnlargedBackdrop != null)
{
cardEnlargedBackdrop.SetActive(true);
}
// Reparent card root to enlarged container preserving world transform
if (cardEnlargedContainer != null)
{
var ctx = state.GetComponentInParent<StateMachine.CardContext>();
if (ctx != null)
{
ctx.RootTransform.SetParent(cardEnlargedContainer, true);
ctx.RootTransform.SetAsLastSibling();
}
}
}
private void OnCardShrinkRequested(StateMachine.States.CardAlbumEnlargedState state)
{
if (state == null) return;
// Hide backdrop
if (cardEnlargedBackdrop != null)
{
cardEnlargedBackdrop.SetActive(false);
}
// Reparent back to original parent and restore local transform
var ctx = state.GetComponentInParent<StateMachine.CardContext>();
if (ctx != null)
{
Transform originalParent = state.GetOriginalParent();
if (originalParent != null)
{
ctx.RootTransform.SetParent(originalParent, true);
ctx.RootTransform.localPosition = state.GetOriginalLocalPosition();
ctx.RootTransform.localRotation = state.GetOriginalLocalRotation();
}
}
}
#endregion
/// <summary>
/// Handle when a new card is added to pending queue
/// Only spawn if this unique card isn't already visualized
@@ -515,109 +662,6 @@ namespace UI.CardSystem
}
}
/// <summary>
/// Handle when a card is revealed (flipped)
/// </summary>
private void OnCardRevealed(AlbumCardPlacementDraggable cardPlacement, CardData cardData)
{
Logging.Debug($"[AlbumViewPage] Card revealed: {cardData.Name} (Zone: {cardData.Zone}, CopiesOwned: {cardData.CopiesOwned})");
// IMMEDIATELY move card from pending to inventory upon reveal
if (CardSystemManager.Instance != null)
{
CardSystemManager.Instance.MarkCardAsPlaced(cardData);
Logging.Debug($"[AlbumViewPage] Moved card '{cardData.Name}' from pending to inventory on reveal");
}
// Remove this card from active cards list
_activeCards.Remove(cardPlacement);
// Check if we're currently viewing the correct zone for this card
CardZone currentZone = GetCurrentZone();
if (currentZone != cardData.Zone)
{
// Card is from a different zone - navigate to its zone
Logging.Debug($"[AlbumViewPage] Card zone ({cardData.Zone}) doesn't match current zone ({currentZone}). Navigating to card's zone...");
NavigateToZone(cardData.Zone);
}
else
{
Logging.Debug($"[AlbumViewPage] Card zone ({cardData.Zone}) matches current zone - no navigation needed.");
}
// Shuffle remaining cards to front and spawn next unique card
ShuffleCardsToFront();
TrySpawnNextCard();
}
/// <summary>
/// Handle when a card is placed in the album (from AlbumCardDraggable)
/// Card data already moved to inventory in OnCardRevealed
/// This just handles cleanup
/// </summary>
private void OnCardPlacedInAlbum(AlbumCardPlacementDraggable cardPlacement, CardData cardData)
{
Logging.Debug($"[AlbumViewPage] Card placed in album slot: {cardData.Name}");
// Unsubscribe from events (card is now static in album)
cardPlacement.OnCardRevealed -= OnCardRevealed;
cardPlacement.OnCardPlacedInAlbum -= OnCardPlacedInAlbum;
// Note: Card already removed from _activeCards in OnCardRevealed
// Note: Shuffle and spawn already done in OnCardRevealed
}
/// <summary>
/// Shuffle active cards to occupy front slots
/// </summary>
private void ShuffleCardsToFront()
{
if (bottomRightSlots == null || _activeCards.Count == 0)
return;
// Convert to base DraggableObject list for helper method
List<DraggableObject> draggableList = _activeCards.Cast<DraggableObject>().ToList();
SlotContainerHelper.ShuffleToFront(bottomRightSlots, draggableList, animate: true);
}
/// <summary>
/// Try to spawn the next pending card
/// Only spawns unique cards (not duplicates)
/// </summary>
private void TrySpawnNextCard()
{
if (CardSystemManager.Instance == null)
return;
if (_activeCards.Count >= MAX_VISIBLE_CARDS)
return; // Already at max
var pending = CardSystemManager.Instance.GetPendingRevealCards();
// Get unique pending cards, excluding zero-count cards
var uniquePending = pending
.Where(c => c.CopiesOwned > 0) // Guard: exclude zero-count cards
.GroupBy(c => new { c.DefinitionId, c.Rarity })
.Select(g => g.First())
.ToList();
// Find first unique card that's not already spawned
foreach (var cardData in uniquePending)
{
bool alreadySpawned = _activeCards.Any(c =>
c.CardData.DefinitionId == cardData.DefinitionId &&
c.CardData.Rarity == cardData.Rarity);
if (!alreadySpawned)
{
int nextSlotIndex = _activeCards.Count;
SpawnCardInSlot(nextSlotIndex, cardData);
break;
}
}
}
/// <summary>
/// Find a slot by its SlotIndex property
/// </summary>
@@ -635,214 +679,5 @@ namespace UI.CardSystem
}
return null;
}
/// <summary>
/// Get the current zone based on book page
/// </summary>
public CardZone GetCurrentZone()
{
if (book == null || zoneTabs == null || zoneTabs.Length == 0)
{
return CardZone.AppleHills; // Default
}
int currentPage = book.CurrentPaper;
// Find tab with matching target page
foreach (var tab in zoneTabs)
{
if (tab.TargetPage == currentPage)
{
return tab.Zone;
}
}
// Fallback to first zone
return CardZone.NotApplicable;
}
/// <summary>
/// Get tab for a specific zone
/// </summary>
public BookTabButton GetTabForZone(CardZone zone)
{
if (zoneTabs == null)
{
return null;
}
foreach (var tab in zoneTabs)
{
if (tab.Zone == zone)
{
return tab;
}
}
return null;
}
/// <summary>
/// Navigate to a specific zone
/// </summary>
public void NavigateToZone(CardZone zone)
{
BookTabButton tab = GetTabForZone(zone);
if (tab != null)
{
tab.ActivateTab();
}
}
/// <summary>
/// Clean up all active cards
/// </summary>
private void CleanupActiveCards()
{
foreach (var card in _activeCards)
{
if (card != null && card.gameObject != null)
{
card.OnCardRevealed -= OnCardRevealed;
card.OnCardPlacedInAlbum -= OnCardPlacedInAlbum;
Destroy(card.gameObject);
}
}
_activeCards.Clear();
}
#endregion
#region Card Enlarge System
/// <summary>
/// Subscribe to album card events when a card is spawned in a slot
/// Call this when AlbumCardSlot spawns a card
/// </summary>
public void RegisterAlbumCard(AlbumCard albumCard)
{
if (albumCard == null) return;
albumCard.OnEnlargeRequested += OnCardEnlargeRequested;
albumCard.OnShrinkRequested += OnCardShrinkRequested;
}
/// <summary>
/// Unsubscribe from album card events
/// </summary>
public void UnregisterAlbumCard(AlbumCard albumCard)
{
if (albumCard == null) return;
albumCard.OnEnlargeRequested -= OnCardEnlargeRequested;
albumCard.OnShrinkRequested -= OnCardShrinkRequested;
}
/// <summary>
/// Handle card enlarge request - show backdrop and reparent card
/// </summary>
private void OnCardEnlargeRequested(AlbumCard card)
{
if (card == null) return;
Logging.Debug($"[AlbumViewPage] OnCardEnlargeRequested called for card: {card.name}, current parent: {card.transform.parent.name}");
// IMPORTANT: Call EnlargeCard FIRST to store original parent (the slot)
// BEFORE reparenting to the enlarged container
card.EnlargeCard();
// Show backdrop
if (cardEnlargedBackdrop != null)
{
cardEnlargedBackdrop.SetActive(true);
Logging.Debug($"[AlbumViewPage] Backdrop shown");
}
// NOW reparent card to enlarged container (above backdrop)
if (cardEnlargedContainer != null)
{
card.transform.SetParent(cardEnlargedContainer, true);
card.transform.SetAsLastSibling(); // Ensure on top
Logging.Debug($"[AlbumViewPage] Card reparented to enlarged container");
}
Logging.Debug($"[AlbumViewPage] Card enlarged: {card.GetCardData()?.Name}");
}
/// <summary>
/// Handle card shrink request - hide backdrop and reparent card back to slot
/// </summary>
private void OnCardShrinkRequested(AlbumCard card)
{
if (card == null) return;
// Trigger shrink animation
card.ShrinkCard();
// Hide backdrop
if (cardEnlargedBackdrop != null)
{
cardEnlargedBackdrop.SetActive(false);
}
// Reparent back to original parent (the slot)
Transform originalParent = card.GetOriginalParent();
if (originalParent != null)
{
card.transform.SetParent(originalParent, true);
card.transform.localPosition = card.GetOriginalLocalPosition();
card.transform.localRotation = card.GetOriginalLocalRotation();
}
Logging.Debug($"[AlbumViewPage] Card shrunk: {card.GetCardData()?.Name}");
}
/// <summary>
/// Show backdrop and reparent slot preview card for enlargement
/// </summary>
public void ShowSlotPreview(AlbumCardSlot slot, Transform previewCardTransform)
{
if (previewCardTransform == null)
return;
Logging.Debug($"[AlbumViewPage] ShowSlotPreview called for slot: {slot.name}");
// Show backdrop
if (cardEnlargedBackdrop != null)
{
cardEnlargedBackdrop.SetActive(true);
}
// Reparent preview card to enlarged container (above backdrop)
if (cardEnlargedContainer != null)
{
previewCardTransform.SetParent(cardEnlargedContainer, true);
previewCardTransform.SetAsLastSibling();
}
}
/// <summary>
/// Hide backdrop and trigger shrink animation for slot preview
/// </summary>
public void HideSlotPreview(AlbumCardSlot slot, Transform previewCardTransform, System.Action onComplete)
{
if (previewCardTransform == null)
return;
Logging.Debug($"[AlbumViewPage] HideSlotPreview called for slot: {slot.name}");
// Hide backdrop
if (cardEnlargedBackdrop != null)
{
cardEnlargedBackdrop.SetActive(false);
}
// Shrink preview card
Vector3 originalScale = previewCardTransform.localScale / 2.5f; // Assuming 2.5x is enlarged scale
Pixelplacement.Tween.LocalScale(previewCardTransform, originalScale, 0.3f, 0f, Pixelplacement.Tween.EaseInBack,
completeCallback: () => onComplete?.Invoke());
}
#endregion
}
}

View File

@@ -10,6 +10,7 @@ using UI.CardSystem.DragDrop;
using UI.DragAndDrop.Core;
using Unity.Cinemachine;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
namespace UI.CardSystem
@@ -30,8 +31,11 @@ namespace UI.CardSystem
[Header("Card Display")]
[SerializeField] private Transform cardDisplayContainer;
[SerializeField] private GameObject flippableCardPrefab; // Placeholder for card backs
[FormerlySerializedAs("flippableCardPrefab")]
[SerializeField] private GameObject cardPrefab; // New Card prefab using state machine
[SerializeField] private float cardSpacing = 150f;
[SerializeField] private float cardWidth = 400f;
[SerializeField] private float cardHeight = 540f;
[Header("Settings")]
[SerializeField] private float boosterDisappearDuration = 0.5f;
@@ -44,12 +48,12 @@ namespace UI.CardSystem
private BoosterPackDraggable _currentBoosterInCenter;
private List<BoosterPackDraggable> _activeBoostersInSlots = new List<BoosterPackDraggable>();
private List<GameObject> _currentRevealedCards = new List<GameObject>();
private List<StateMachine.Card> _currentCards = new List<StateMachine.Card>();
private CardData[] _currentCardData;
private int _revealedCardCount;
private int _cardsCompletedInteraction; // Track how many cards finished their new/repeat interaction
private StateMachine.Card _activeCard; // Currently selected/revealing card
private int _cardsCompletedInteraction; // Track how many cards finished their reveal flow
private bool _isProcessingOpening;
private const int MAX_VISIBLE_BOOSTERS = 3;
private FlippableCard _currentActiveCard; // The card currently awaiting interaction
private void Awake()
{
// Make sure we have a CanvasGroup for transitions
@@ -514,8 +518,8 @@ namespace UI.CardSystem
// Update visible boosters (remove from end if we drop below thresholds)
UpdateVisibleBoosters();
// Show card backs
SpawnCardBacks(_currentCardData.Length);
// Show cards using new Card prefab
SpawnBoosterCards(_currentCardData);
// Wait for player to reveal all cards
bool isLastBooster = _availableBoosterCount <= 0;
@@ -524,10 +528,7 @@ namespace UI.CardSystem
// Check if this was the last booster pack
if (isLastBooster)
{
// Wait for all card animations to complete before transitioning
// WaitForCardReveals already includes: 0.5s wait + (cardCount * 0.5s stagger) + 0.5s animation + 0.5s final
// Total is: 1.5s + (cardCount * 0.5s)
// For 5 cards that's 4 seconds total, which should be enough
// See earlier comment for timing
Logging.Debug("[BoosterOpeningPage] Last booster opened, auto-transitioning to album main page");
if (UIPageController.Instance != null)
{
@@ -539,6 +540,122 @@ namespace UI.CardSystem
_isProcessingOpening = false;
}
/// <summary>
/// Spawn cards for booster opening flow using the new Card prefab and state machine.
/// </summary>
private void SpawnBoosterCards(CardData[] cards)
{
if (cardPrefab == null || cardDisplayContainer == null)
{
Logging.Warning("BoosterOpeningPage: Missing card prefab or container!");
return;
}
_currentRevealedCards.Clear();
_currentCards.Clear();
_cardsCompletedInteraction = 0;
_activeCard = null;
int count = cards.Length;
float totalWidth = (count - 1) * cardSpacing;
float startX = -totalWidth / 2f;
for (int i = 0; i < count; i++)
{
GameObject cardObj = Instantiate(cardPrefab, cardDisplayContainer);
RectTransform cardRect = cardObj.GetComponent<RectTransform>();
if (cardRect != null)
{
cardRect.anchoredPosition = new Vector2(startX + (i * cardSpacing), 0);
cardRect.sizeDelta = new Vector2(cardWidth, cardHeight); // Set card size
cardRect.localScale = Vector3.zero; // for pop-in
}
var card = cardObj.GetComponent<StateMachine.Card>();
var context = cardObj.GetComponent<StateMachine.CardContext>();
if (card != null && context != null)
{
// Setup card for booster reveal
// States will query CardSystemManager for current collection state as needed
context.SetupCard(cards[i]);
card.SetupForBoosterReveal(cards[i], false); // isNew parameter not used anymore
card.SetDraggingEnabled(false);
// Subscribe to CardDisplay click for selection
context.CardDisplay.OnCardClicked += (_) => OnCardClicked(card);
// Subscribe to reveal flow complete event
context.OnRevealFlowComplete += (ctx) => OnCardRevealComplete(card);
// Track the card
_currentCards.Add(card);
// Tween in
Tween.LocalScale(cardObj.transform, Vector3.one, 0.3f, i * 0.1f, Tween.EaseOutBack);
}
else
{
Logging.Warning($"[BoosterOpeningPage] Card component or context missing on spawned card {i}!");
}
_currentRevealedCards.Add(cardObj);
}
}
/// <summary>
/// Handle when a card is clicked - start reveal flow if conditions are met
/// </summary>
private void OnCardClicked(StateMachine.Card card)
{
// Only allow clicking idle cards when no other card is active
if (_activeCard == null && card.IsIdle && card.Context.IsClickable)
{
Logging.Debug($"[BoosterOpeningPage] Card {card.CardData?.Name} selected for reveal");
// Set as active and disable all other idle cards
_activeCard = card;
foreach (var otherCard in _currentCards)
{
if (otherCard != card && otherCard.IsIdle)
{
otherCard.Context.IsClickable = false;
}
}
// Click will route to IdleState automatically and trigger flip
}
}
/// <summary>
/// Handle when a card completes its reveal flow
/// </summary>
private void OnCardRevealComplete(StateMachine.Card card)
{
_cardsCompletedInteraction++;
Logging.Debug($"[BoosterOpeningPage] Card {card.CardData?.Name} reveal complete ({_cardsCompletedInteraction}/{_currentCardData.Length})");
// Add card to inventory NOW (after player saw it)
if (card.CardData != null)
{
Data.CardSystem.CardSystemManager.Instance.AddCardToInventoryDelayed(card.CardData);
}
// Clear active card and re-enable remaining idle cards
if (_activeCard == card)
{
_activeCard = null;
foreach (var otherCard in _currentCards)
{
if (otherCard.IsIdle)
{
otherCard.Context.IsClickable = true;
}
}
}
}
/// <summary>
/// Animate the booster pack disappearing
/// </summary>
@@ -569,249 +686,19 @@ namespace UI.CardSystem
}
/// <summary>
/// Spawn card back placeholders for revealing
/// </summary>
private void SpawnCardBacks(int count)
{
if (flippableCardPrefab == null || cardDisplayContainer == null)
{
Logging.Warning("BoosterOpeningPage: Missing card prefab or container!");
return;
}
_currentRevealedCards.Clear();
_revealedCardCount = 0;
_cardsCompletedInteraction = 0; // Reset interaction count
// Calculate positions
float totalWidth = (count - 1) * cardSpacing;
float startX = -totalWidth / 2f;
for (int i = 0; i < count; i++)
{
GameObject cardObj = Instantiate(flippableCardPrefab, cardDisplayContainer);
RectTransform cardRect = cardObj.GetComponent<RectTransform>();
if (cardRect != null)
{
cardRect.anchoredPosition = new Vector2(startX + (i * cardSpacing), 0);
}
// Get FlippableCard component and setup the card data
FlippableCard flippableCard = cardObj.GetComponent<FlippableCard>();
if (flippableCard != null)
{
// Setup the card data (stored but not revealed yet)
flippableCard.SetupCard(_currentCardData[i]);
// Subscribe to flip started event (to disable other cards IMMEDIATELY)
int cardIndex = i; // Capture for closure
flippableCard.OnFlipStarted += OnCardFlipStarted;
// Subscribe to reveal event to track when flipped
flippableCard.OnCardRevealed += (card, data) => OnCardRevealed(cardIndex);
// Subscribe to inactive click event (for jiggle effect)
flippableCard.OnClickedWhileInactive += OnCardClickedWhileInactive;
// Initially, all cards are clickable (for flipping)
flippableCard.SetClickable(true);
}
else
{
Logging.Warning($"[BoosterOpeningPage] FlippableCard component not found on card {i}!");
}
_currentRevealedCards.Add(cardObj);
// Animate cards flying in
cardRect.localScale = Vector3.zero;
Tween.LocalScale(cardRect, Vector3.one, 0.3f, i * 0.1f, Tween.EaseOutBack);
}
}
/// <summary>
/// Handle when a card flip starts (disable all other cards IMMEDIATELY)
/// </summary>
private void OnCardFlipStarted(FlippableCard flippingCard)
{
Logging.Debug($"[BoosterOpeningPage] Card flip started, disabling all other cards.");
// Disable ALL cards immediately to prevent multi-flip
foreach (GameObject cardObj in _currentRevealedCards)
{
FlippableCard card = cardObj.GetComponent<FlippableCard>();
if (card != null)
{
card.SetClickable(false);
}
}
}
/// <summary>
/// Handle card reveal (when flipped)
/// </summary>
private void OnCardRevealed(int cardIndex)
{
Logging.Debug($"[BoosterOpeningPage] Card {cardIndex} revealed!");
_revealedCardCount++;
// Get the flippable card and card data
FlippableCard flippableCard = _currentRevealedCards[cardIndex].GetComponent<FlippableCard>();
if (flippableCard == null)
{
Logging.Warning($"[BoosterOpeningPage] FlippableCard not found for card {cardIndex}!");
return;
}
CardData cardData = flippableCard.CardData;
// Check if this is a new card using CardSystemManager
bool isNew = Data.CardSystem.CardSystemManager.Instance.IsCardNew(cardData, out CardData existingCard);
if (isNew)
{
Logging.Debug($"[BoosterOpeningPage] Card '{cardData.Name}' is NEW!");
flippableCard.ShowAsNew();
}
else
{
// Check if card is already Legendary - if so, skip progress bar and auto-progress
if (existingCard.Rarity == AppleHills.Data.CardSystem.CardRarity.Legendary)
{
Logging.Debug($"[BoosterOpeningPage] Card '{cardData.Name}' is LEGENDARY - auto-progressing!");
// Add to inventory immediately and move to next card
Data.CardSystem.CardSystemManager.Instance.AddCardToInventoryDelayed(cardData);
_cardsCompletedInteraction++;
_revealedCardCount++; // This was already incremented earlier, but we need to track completion
EnableUnrevealedCards();
return; // Skip showing the card enlarged
}
int ownedCount = existingCard.CopiesOwned;
Logging.Debug($"[BoosterOpeningPage] Card '{cardData.Name}' is a REPEAT! Owned: {ownedCount}");
// Check if this card will trigger an upgrade (ownedCount + 1 >= threshold)
bool willUpgrade = (ownedCount + 1) >= flippableCard.CardsToUpgrade && existingCard.Rarity < AppleHills.Data.CardSystem.CardRarity.Legendary;
if (willUpgrade)
{
Logging.Debug($"[BoosterOpeningPage] This card will trigger upgrade! ({ownedCount + 1}/{flippableCard.CardsToUpgrade})");
// Show as repeat - progress bar will fill and auto-trigger upgrade
flippableCard.ShowAsRepeatWithUpgrade(ownedCount, existingCard);
}
else
{
// Normal repeat, no upgrade
flippableCard.ShowAsRepeat(ownedCount);
}
}
// Set this card as the active one (only this card is clickable now)
SetActiveCard(flippableCard);
// Subscribe to tap event to know when interaction is complete
flippableCard.OnCardTappedAfterReveal += (card) => OnCardCompletedInteraction(card, cardIndex);
}
/// <summary>
/// Handle when a card's interaction is complete (tapped after reveal)
/// </summary>
private void OnCardCompletedInteraction(FlippableCard card, int cardIndex)
{
Logging.Debug($"[BoosterOpeningPage] Card {cardIndex} interaction complete!");
// Add card to inventory NOW (after player saw it)
Data.CardSystem.CardSystemManager.Instance.AddCardToInventoryDelayed(card.CardData);
// Return card to normal size
card.ReturnToNormalSize();
// Increment completed interaction count
_cardsCompletedInteraction++;
// Clear active card
_currentActiveCard = null;
// Re-enable all unrevealed cards (they can be flipped now)
EnableUnrevealedCards();
Logging.Debug($"[BoosterOpeningPage] Cards completed interaction: {_cardsCompletedInteraction}/{_currentCardData.Length}");
}
/// <summary>
/// Set which card is currently active (only this card can be clicked)
/// </summary>
private void SetActiveCard(FlippableCard activeCard)
{
_currentActiveCard = activeCard;
// Disable all other cards
foreach (GameObject cardObj in _currentRevealedCards)
{
FlippableCard card = cardObj.GetComponent<FlippableCard>();
if (card != null)
{
// Only the active card is clickable
card.SetClickable(card == activeCard);
}
}
Logging.Debug($"[BoosterOpeningPage] Set active card. Only one card is now clickable.");
}
/// <summary>
/// Re-enable all unrevealed cards (allow them to be flipped)
/// </summary>
private void EnableUnrevealedCards()
{
foreach (GameObject cardObj in _currentRevealedCards)
{
FlippableCard card = cardObj.GetComponent<FlippableCard>();
if (card != null && !card.IsFlipped)
{
card.SetClickable(true);
}
}
Logging.Debug($"[BoosterOpeningPage] Re-enabled unrevealed cards for flipping.");
}
/// <summary>
/// Handle when a card is clicked while not active (jiggle the active card)
/// </summary>
private void OnCardClickedWhileInactive(FlippableCard inactiveCard)
{
Logging.Debug($"[BoosterOpeningPage] Inactive card clicked, jiggling active card.");
if (_currentActiveCard != null)
{
_currentActiveCard.Jiggle();
}
}
/// <summary>
/// Wait until all cards are revealed AND all interactions are complete
/// Wait until all cards complete their reveal flow
/// </summary>
private IEnumerator WaitForCardReveals()
{
// Wait until all cards are flipped
while (_revealedCardCount < _currentCardData.Length)
{
yield return null;
}
Logging.Debug($"[BoosterOpeningPage] All cards revealed! Waiting for interactions...");
// Wait until all cards have completed their new/repeat interaction
// Wait until all cards have completed their reveal flow
while (_cardsCompletedInteraction < _currentCardData.Length)
{
yield return null;
}
Logging.Debug($"[BoosterOpeningPage] All interactions complete! Animating cards to album...");
Logging.Debug($"[BoosterOpeningPage] All cards revealed! Animating cards to album...");
// All cards revealed and interacted with, wait a moment
// Small pause
yield return new WaitForSeconds(0.5f);
// Show album icon before cards start tweening to it
@@ -829,28 +716,20 @@ namespace UI.CardSystem
{
if (cardObj != null)
{
// Stagger each card with 0.5s delay
float delay = cardIndex * 0.5f;
// Animate to album icon position, then destroy
// Use world space position tween for root transform
Tween.Position(cardObj.transform, targetPosition, 0.5f, delay, Tween.EaseInBack);
Tween.LocalScale(cardObj.transform, Vector3.zero, 0.5f, delay, Tween.EaseInBack,
completeCallback: () => Destroy(cardObj));
completeCallback: () => { if (cardObj != null) Destroy(cardObj); });
cardIndex++;
}
}
// Wait for all animations to complete
// Last card starts at: (cardCount - 1) * 0.5s delay
// Last card finishes at: (cardCount - 1) * 0.5s + 0.5s animation duration = cardCount * 0.5s
float totalAnimationTime = _currentCardData.Length * 0.5f;
_currentRevealedCards.Clear();
_currentCards.Clear();
yield return new WaitForSeconds(totalAnimationTime);
// Album icon stays visible for next booster (will be hidden when next booster is placed)
}
/// <summary>

View File

@@ -37,10 +37,7 @@ namespace UI.CardSystem
// Events
public event Action<CardDisplay> OnCardClicked;
// Preview mode tracking for click forwarding
private bool _isPreviewMode;
private AlbumCardSlot _previewSlot;
/// <summary>
/// Sets up the card display with the given card data
@@ -88,46 +85,7 @@ namespace UI.CardSystem
Logging.Debug($"[CardDisplay] Updated visuals for card: {cardData.Name} (Rarity: {cardData.Rarity}, Zone: {cardData.Zone})");
}
/// <summary>
/// Apply preview visuals - black tint to card image and question marks for name
/// Used for empty slot previews to show locked/unknown cards
/// </summary>
public void SetPreviewVisuals()
{
// Set card name to question marks
if (cardNameText != null)
{
cardNameText.text = "??????";
}
// Apply black non-opaque tint to card image
if (cardImage != null)
{
cardImage.color = Color.black;
}
Logging.Debug($"[CardDisplay] Applied preview visuals (black tint and ?????? name)");
}
/// <summary>
/// Reset preview visuals back to normal
/// </summary>
public void ClearPreviewVisuals()
{
// Restore normal card name
if (cardData != null && cardNameText != null)
{
cardNameText.text = cardData.Name ?? "Unknown Card";
}
// Reset card image color to white (normal)
if (cardImage != null)
{
cardImage.color = Color.white;
}
Logging.Debug($"[CardDisplay] Cleared preview visuals");
}
/// <summary>
/// Updates the card name text
@@ -281,50 +239,11 @@ namespace UI.CardSystem
}
/// <summary>
/// Enable preview mode - when clicked, forwards click to the associated slot
/// </summary>
public void SetPreviewMode(bool isEnabled, AlbumCardSlot slot = null)
{
_isPreviewMode = isEnabled;
_previewSlot = slot;
// Enable raycast targets on images so this CardDisplay can receive clicks
if (cardImage != null) cardImage.raycastTarget = isEnabled;
if (frameImage != null) frameImage.raycastTarget = isEnabled;
if (overlayImage != null) overlayImage.raycastTarget = isEnabled;
if (backgroundImage != null) backgroundImage.raycastTarget = isEnabled;
if (zoneShapeImage != null) zoneShapeImage.raycastTarget = isEnabled;
Logging.Debug($"[CardDisplay] Preview mode {(isEnabled ? "enabled" : "disabled")}, slot: {(slot != null ? slot.name : "NULL")}");
}
/// <summary>
/// Handle click on CardDisplay - forward to preview slot if in preview mode
/// Handle pointer click - simply emit the click event
/// </summary>
public void OnPointerClick(PointerEventData eventData)
{
Logging.Debug($"[CLICK-TRACE-CARDDISPLAY] OnPointerClick on {name}, _isPreviewMode={_isPreviewMode}, _previewSlot={((_previewSlot != null) ? _previewSlot.name : "NULL")}");
if (_isPreviewMode && _previewSlot != null)
{
Logging.Debug($"[CLICK-TRACE-CARDDISPLAY] {name} - In preview mode, calling DismissPreview on slot: {_previewSlot.name}");
_previewSlot.DismissPreview();
}
else
{
// Not in preview mode - forward click to parent AlbumCard (if it exists)
AlbumCard parentAlbumCard = GetComponentInParent<AlbumCard>();
if (parentAlbumCard != null)
{
Logging.Debug($"[CLICK-TRACE-CARDDISPLAY] {name} - Forwarding click to parent AlbumCard");
parentAlbumCard.OnPointerClick(eventData);
}
else
{
Logging.Debug($"[CLICK-TRACE-CARDDISPLAY] {name} - No parent AlbumCard, firing OnCardClicked event");
OnCardClicked?.Invoke(this);
}
}
OnCardClicked?.Invoke(this);
}
#if UNITY_EDITOR

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: ea96bf019611f0249998bb2819f3b320
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,193 +0,0 @@
using System;
using AppleHills.Data.CardSystem;
using Core;
using Pixelplacement;
using UnityEngine;
using UnityEngine.EventSystems;
using AppleHills.Core.Settings;
namespace UI.CardSystem
{
/// <summary>
/// Album card component that wraps CardDisplay.
/// Handles tap-to-enlarge and tap-to-shrink interactions for cards placed in album slots.
///
/// TODO: Consider refactoring to state machine pattern (PendingReveal, PlacedInSlot, Enlarged)
/// This would eliminate the need for separate AlbumPlacementCard wrapper and simplify the hierarchy.
/// See design discussion with state transitions for cleaner architecture.
/// </summary>
public class AlbumCard : MonoBehaviour, IPointerClickHandler
{
[Header("References")]
[SerializeField] private CardDisplay cardDisplay;
// Events for AlbumViewPage to manage backdrop and reparenting
public event Action<AlbumCard> OnEnlargeRequested;
public event Action<AlbumCard> OnShrinkRequested;
private AlbumCardSlot _parentSlot;
private CardData _cardData;
private bool _isEnlarged;
private Vector3 _originalScale;
private Transform _originalParent;
private Vector3 _originalLocalPosition;
private Quaternion _originalLocalRotation;
private ICardSystemSettings _settings;
private void Awake()
{
_settings = GameManager.GetSettingsObject<ICardSystemSettings>();
// Auto-find CardDisplay if not assigned
if (cardDisplay == null)
{
cardDisplay = GetComponentInChildren<CardDisplay>();
}
// Store original scale
_originalScale = transform.localScale;
}
/// <summary>
/// Setup card with data
/// </summary>
public void SetupCard(CardData data)
{
_cardData = data;
if (cardDisplay != null)
{
cardDisplay.SetupCard(data);
}
}
/// <summary>
/// Set the parent slot this card belongs to
/// </summary>
public void SetParentSlot(AlbumCardSlot slot)
{
_parentSlot = slot;
}
/// <summary>
/// Get the card data
/// </summary>
public CardData GetCardData()
{
return _cardData;
}
/// <summary>
/// Handle tap on card - request enlarge/shrink from parent page
/// Only process clicks when card is placed in a slot (not during reveal flow)
/// </summary>
public void OnPointerClick(PointerEventData eventData)
{
Logging.Debug($"[CLICK-TRACE-ALBUMCARD] OnPointerClick on {name}, _parentSlot={((_parentSlot != null) ? _parentSlot.name : "NULL")}, _isEnlarged={_isEnlarged}, position={eventData.position}");
// During reveal flow (before placed in slot), forward clicks to parent FlippableCard
if (_parentSlot == null)
{
Logging.Debug($"[CLICK-TRACE-ALBUMCARD] {name} - No parent slot, forwarding click to parent FlippableCard");
// Find parent FlippableCard and forward the click
FlippableCard parentFlippable = GetComponentInParent<FlippableCard>();
if (parentFlippable != null)
{
Logging.Debug($"[CLICK-TRACE-ALBUMCARD] {name} - Found parent FlippableCard, calling OnPointerClick");
parentFlippable.OnPointerClick(eventData);
}
else
{
Logging.Warning($"[CLICK-TRACE-ALBUMCARD] {name} - No parent FlippableCard found!");
}
return;
}
Logging.Debug($"[CLICK-TRACE-ALBUMCARD] {name} - Has parent slot, processing click");
if (_isEnlarged)
{
Logging.Debug($"[CLICK-TRACE-ALBUMCARD] {name} - Is enlarged, requesting shrink");
OnShrinkRequested?.Invoke(this);
}
else
{
Logging.Debug($"[CLICK-TRACE-ALBUMCARD] {name} - Is normal size, requesting enlarge");
OnEnlargeRequested?.Invoke(this);
}
}
/// <summary>
/// Enlarge card (called by AlbumViewPage after reparenting)
/// </summary>
public void EnlargeCard()
{
if (_isEnlarged) return;
_isEnlarged = true;
// Store original transform info for restoration
_originalParent = transform.parent;
_originalLocalPosition = transform.localPosition;
_originalLocalRotation = transform.localRotation;
// Scale up with snappy tween
Tween.LocalScale(transform, _originalScale * _settings.AlbumCardEnlargedScale, _settings.ScaleDuration, 0f, Tween.EaseOutBack);
}
/// <summary>
/// Shrink card back to original size (called by AlbumViewPage before reparenting back)
/// </summary>
/// <param name="onComplete">Optional callback to invoke when shrink animation completes</param>
public void ShrinkCard(System.Action onComplete = null)
{
if (!_isEnlarged) return;
_isEnlarged = false;
// Scale back down with snappy tween, invoke callback when done
Tween.LocalScale(transform, _originalScale, _settings.ScaleDuration, 0f, Tween.EaseInBack,
completeCallback: () => onComplete?.Invoke());
}
/// <summary>
/// Get original parent for restoration
/// </summary>
public Transform GetOriginalParent()
{
return _originalParent;
}
/// <summary>
/// Get original local position for restoration
/// </summary>
public Vector3 GetOriginalLocalPosition()
{
return _originalLocalPosition;
}
/// <summary>
/// Get original local rotation for restoration
/// </summary>
public Quaternion GetOriginalLocalRotation()
{
return _originalLocalRotation;
}
/// <summary>
/// Check if card is currently enlarged
/// </summary>
public bool IsEnlarged => _isEnlarged;
/// <summary>
/// Force reset enlarged state (for cleanup scenarios like page closing)
/// </summary>
public void ForceResetEnlargedState()
{
_isEnlarged = false;
transform.localScale = _originalScale;
}
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 258a530448814715b5ec19737df2a658
timeCreated: 1762505823

View File

@@ -1,252 +0,0 @@
using System;
using System.Collections;
using AppleHills.Data.CardSystem;
using Core;
using Data.CardSystem;
using Pixelplacement;
using UI.DragAndDrop.Core;
using UnityEngine;
namespace UI.CardSystem
{
/// <summary>
/// Draggable card for album reveal system.
/// Handles both tap and drag-hold interactions for revealing cards.
/// Auto-snaps to matching album slot on release/tap.
/// </summary>
public class AlbumCardPlacementDraggable : DraggableObject
{
[Header("Album Card Settings")]
[SerializeField] private FlippableCard flippableCard;
[SerializeField] private float holdRevealDelay = 0.1f;
private CardData _cardData;
private bool _isRevealed = false;
private bool _isDragRevealing = false;
private bool _waitingForPlacementTap = false;
private Coroutine _holdRevealCoroutine;
private bool _isHolding = false; // Track if pointer is currently down
// Events
public event Action<AlbumCardPlacementDraggable, CardData> OnCardRevealed;
public event Action<AlbumCardPlacementDraggable, CardData> OnCardPlacedInAlbum;
public CardData CardData => _cardData;
public bool IsRevealed => _isRevealed;
public CardZone Zone => _cardData?.Zone ?? CardZone.AppleHills;
protected override void Initialize()
{
base.Initialize();
// Auto-find FlippableCard if not assigned
if (flippableCard == null)
{
flippableCard = GetComponent<FlippableCard>();
}
}
/// <summary>
/// Setup the card data (stores it but doesn't reveal until tapped/dragged)
/// </summary>
public void SetupCard(CardData data)
{
_cardData = data;
if (flippableCard != null)
{
flippableCard.SetupCard(data);
}
}
/// <summary>
/// Reveal the card (flip to show front)
/// </summary>
public void RevealCard()
{
if (_isRevealed)
{
return;
}
_isRevealed = true;
if (flippableCard != null)
{
flippableCard.FlipToReveal();
}
OnCardRevealed?.Invoke(this, _cardData);
}
/// <summary>
/// Snap to the matching album slot
/// </summary>
public void SnapToAlbumSlot()
{
if (_cardData == null)
{
Logging.Warning("[AlbumCardPlacementDraggable] Cannot snap to slot - no card data assigned.");
return;
}
// Find all album card slots in the scene
AlbumCardSlot[] allSlots = FindObjectsByType<AlbumCardSlot>(FindObjectsSortMode.None);
AlbumCardSlot matchingSlot = null;
foreach (var slot in allSlots)
{
if (slot.CanAcceptCard(_cardData))
{
matchingSlot = slot;
break;
}
}
if (matchingSlot != null)
{
SetDraggingEnabled(false);
// NEW FLOW: Extract AlbumCard FIRST, then tween it
if (flippableCard != null)
{
AlbumCard extractedCard = flippableCard.ExtractAlbumCard(matchingSlot.transform);
if (extractedCard != null)
{
// Notify slot that card was placed
matchingSlot.OnCardPlaced(extractedCard);
// NOW tween the extracted AlbumCard into position
TweenExtractedCardToSlot(extractedCard, () =>
{
// After animation completes
Logging.Debug($"[AlbumCardPlacementDraggable] Card placement animation complete for {_cardData.Name}");
// Notify that card was placed
OnCardPlacedInAlbum?.Invoke(this, _cardData);
// Destroy this wrapper (the AlbumPlacementCard)
Destroy(gameObject);
});
}
else
{
Logging.Warning("[AlbumCardPlacementDraggable] Failed to extract AlbumCard from wrapper!");
}
}
}
else
{
Logging.Warning($"[AlbumCardPlacementDraggable] Could not find matching slot for card '{_cardData.Name}' (Zone: {_cardData.Zone}, Index: {_cardData.CollectionIndex})");
}
}
/// <summary>
/// Tween the extracted AlbumCard into its slot position
/// Tweens from current size to slot size - AspectRatioFitter handles width
/// </summary>
private void TweenExtractedCardToSlot(AlbumCard card, System.Action onComplete)
{
Transform cardTransform = card.transform;
RectTransform cardRect = cardTransform as RectTransform;
if (cardRect != null)
{
// Get target height from slot
RectTransform slotRect = cardTransform.parent as RectTransform;
float targetHeight = slotRect != null ? slotRect.rect.height : cardRect.sizeDelta.y;
// Tween from current size to target size (AspectRatioFitter will adjust width)
Vector2 targetSize = new Vector2(cardRect.sizeDelta.x, targetHeight);
Tween.Size(cardRect, targetSize, snapDuration, 0f, Tween.EaseOutBack);
// Tween position and rotation to slot center
Tween.LocalPosition(cardRect, Vector3.zero, snapDuration, 0f, Tween.EaseOutBack);
Tween.LocalRotation(cardTransform, Quaternion.identity, snapDuration, 0f, Tween.EaseOutBack,
completeCallback: () =>
{
Logging.Debug($"[AlbumCardPlacementDraggable] Tween complete for extracted card {card.name}, final height: {cardRect.sizeDelta.y}");
onComplete?.Invoke();
});
}
else
{
// No RectTransform, just reset and call callback
cardTransform.localPosition = Vector3.zero;
cardTransform.localRotation = Quaternion.identity;
onComplete?.Invoke();
}
}
protected override void OnPointerDownHook()
{
base.OnPointerDownHook();
_isHolding = true;
// Start hold-reveal timer if card not yet revealed
if (!_isRevealed && _holdRevealCoroutine == null)
{
_holdRevealCoroutine = StartCoroutine(HoldRevealTimer());
}
}
protected override void OnPointerUpHook(bool longPress)
{
base.OnPointerUpHook(longPress);
_isHolding = false;
// Cancel hold timer if running
if (_holdRevealCoroutine != null)
{
StopCoroutine(_holdRevealCoroutine);
_holdRevealCoroutine = null;
}
else
{
}
// Handle tap (not dragged)
if (!_wasDragged)
{
if (!_isRevealed)
{
// First tap: reveal the card
RevealCard();
_waitingForPlacementTap = true;
}
else if (_waitingForPlacementTap)
{
// Second tap: snap to slot
_waitingForPlacementTap = false;
SnapToAlbumSlot();
}
else
{
}
}
else if (_isDragRevealing)
{
// Was drag-revealed, auto-snap on release
_isDragRevealing = false;
SnapToAlbumSlot();
}
}
/// <summary>
/// Coroutine to reveal card after holding for specified duration
/// </summary>
private IEnumerator HoldRevealTimer()
{
yield return new WaitForSeconds(holdRevealDelay);
// If still holding after delay, reveal the card
if (!_isRevealed && _isHolding)
{
RevealCard();
_isDragRevealing = true;
}
_holdRevealCoroutine = null;
}
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 706803638ea24880bae19c87d3851ce6
timeCreated: 1762470947

View File

@@ -1,62 +0,0 @@
using AppleHills.Data.CardSystem;
using UI.DragAndDrop.Core;
using UnityEngine;
namespace UI.CardSystem.DragDrop
{
/// <summary>
/// Card-specific implementation of DraggableObject.
/// Manages card data and card-specific drag behavior.
/// </summary>
public class CardDraggable : DraggableObject
{
[Header("Card Data")]
[SerializeField] private CardData cardData;
// Events
public event System.Action<CardDraggable, CardData> OnCardDataChanged;
public CardData CardData => cardData;
/// <summary>
/// Set the card data for this draggable card
/// </summary>
public void SetCardData(CardData data)
{
cardData = data;
OnCardDataChanged?.Invoke(this, cardData);
// Update visual if it exists
if (_visualInstance != null && _visualInstance is CardDraggableVisual cardVisual)
{
cardVisual.RefreshCardDisplay();
}
}
protected override void OnDragStartedHook()
{
base.OnDragStartedHook();
// Card-specific drag started behavior
}
protected override void OnDragEndedHook()
{
base.OnDragEndedHook();
// Card-specific drag ended behavior
}
protected override void OnSelectionChangedHook(bool selected)
{
base.OnSelectionChangedHook(selected);
// Card-specific selection behavior
}
protected override void OnSlotChangedHook(DraggableSlot previousSlot, DraggableSlot newSlot)
{
base.OnSlotChangedHook(previousSlot, newSlot);
// Card-specific slot changed behavior
// Could trigger events for card collection reordering, etc.
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: e6edf435b57f09c47bb9e10d34164570

View File

@@ -1,121 +0,0 @@
using AppleHills.Data.CardSystem;
using UI.DragAndDrop.Core;
using UnityEngine;
namespace UI.CardSystem.DragDrop
{
/// <summary>
/// Visual representation for CardDraggable.
/// Uses the existing CardDisplay component to render the card.
/// </summary>
public class CardDraggableVisual : DraggableVisual
{
[Header("Card Visual Components")]
[SerializeField] private CardDisplay cardDisplay;
[SerializeField] private Transform shadowTransform;
[SerializeField] private float shadowOffset = 20f;
private Vector3 _shadowInitialPosition;
private CardDraggable _cardDraggable;
public CardDisplay CardDisplay => cardDisplay;
public override void Initialize(DraggableObject parent)
{
base.Initialize(parent);
_cardDraggable = parent as CardDraggable;
// Get CardDisplay component if not assigned
if (cardDisplay == null)
{
cardDisplay = GetComponentInChildren<CardDisplay>();
}
// Initialize shadow
if (shadowTransform != null)
{
_shadowInitialPosition = shadowTransform.localPosition;
}
// Subscribe to card data changes
if (_cardDraggable != null)
{
_cardDraggable.OnCardDataChanged += HandleCardDataChanged;
// Initial card setup
if (_cardDraggable.CardData != null && cardDisplay != null)
{
cardDisplay.SetupCard(_cardDraggable.CardData);
}
}
}
protected override void UpdateVisualContent()
{
// CardDisplay handles its own rendering, no need to update every frame
// This is called every frame but we only update when card data changes
}
/// <summary>
/// Refresh the card display with current data
/// </summary>
public void RefreshCardDisplay()
{
if (cardDisplay != null && _cardDraggable != null && _cardDraggable.CardData != null)
{
cardDisplay.SetupCard(_cardDraggable.CardData);
}
}
private void HandleCardDataChanged(CardDraggable draggable, CardData data)
{
RefreshCardDisplay();
}
protected override void OnPointerDownVisual()
{
base.OnPointerDownVisual();
// Move shadow down when pressed
if (shadowTransform != null)
{
shadowTransform.localPosition = _shadowInitialPosition + (-Vector3.up * shadowOffset);
}
}
protected override void OnPointerUpVisual(bool longPress)
{
base.OnPointerUpVisual(longPress);
// Restore shadow position
if (shadowTransform != null)
{
shadowTransform.localPosition = _shadowInitialPosition;
}
}
protected override void OnDragStartedVisual()
{
base.OnDragStartedVisual();
// Card-specific visual effects when dragging starts
}
protected override void OnDragEndedVisual()
{
base.OnDragEndedVisual();
// Card-specific visual effects when dragging ends
}
protected override void OnDestroy()
{
base.OnDestroy();
if (_cardDraggable != null)
{
_cardDraggable.OnCardDataChanged -= HandleCardDataChanged;
}
}
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 2a4c3884410d44f98182cd8119a972a4
timeCreated: 1762420668

View File

@@ -1,65 +0,0 @@
using UnityEngine;
using UnityEngine.EventSystems;
namespace UI.CardSystem.StateMachine.States
{
/// <summary>
/// Optional helper component for handling drag/drop integration with existing DragDrop system.
/// Can be attached to Card root to bridge between state machine and drag system.
/// </summary>
public class CardInteractionHandler : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
{
private CardContext _context;
private CardDraggingState _draggingState;
private bool _isDragging;
private void Awake()
{
_context = GetComponent<CardContext>();
}
public void OnBeginDrag(PointerEventData eventData)
{
// Only allow drag from certain states
var currentState = _context.StateMachine.currentState?.name;
if (currentState != "RevealedState" && currentState != "PlacedInSlotState")
{
return;
}
// Transition to dragging state
_context.StateMachine.ChangeState("DraggingState");
_draggingState = _context.StateMachine.currentState?.GetComponent<CardDraggingState>();
_isDragging = true;
}
public void OnDrag(PointerEventData eventData)
{
if (!_isDragging || _draggingState == null) return;
// Update drag position
Vector3 worldPosition;
RectTransformUtility.ScreenPointToWorldPointInRectangle(
transform as RectTransform,
eventData.position,
eventData.pressEventCamera,
out worldPosition
);
// _draggingState.UpdateDragPosition(worldPosition);
}
public void OnEndDrag(PointerEventData eventData)
{
if (!_isDragging || _draggingState == null) return;
_isDragging = false;
// Check if dropped over a valid slot
// This would integrate with your existing AlbumCardSlot system
// For now, just return to revealed state
// _draggingState.OnDroppedOutsideSlot();
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 56af1049620bac744b1eee076a14594e

View File

@@ -1,673 +0,0 @@
using System;
using AppleHills.Data.CardSystem;
using Core;
using Pixelplacement;
using Pixelplacement.TweenSystem;
using UnityEngine;
using UnityEngine.EventSystems;
using AppleHills.Core.Settings;
namespace UI.CardSystem
{
/// <summary>
/// Flippable card wrapper that shows a card back, then flips to reveal the CardDisplay front.
/// This component nests an existing CardDisplay prefab to reuse card visuals everywhere.
/// </summary>
public class FlippableCard : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
{
[Header("Card References")]
[SerializeField] private GameObject cardBackObject; // The card back visual
[SerializeField] private GameObject cardFrontObject; // Your CardDisplay prefab instance
[SerializeField] private CardDisplay cardDisplay; // Reference to CardDisplay component
[SerializeField] private AlbumCard albumCard; // Reference to nested AlbumCard (for album placement flow)
[Header("Idle Hover Animation")]
[SerializeField] private bool enableIdleHover = true;
[Header("New/Repeat Card Display")]
[SerializeField] private GameObject newCardText;
[SerializeField] private GameObject newCardIdleText;
[SerializeField] private GameObject repeatText;
[SerializeField] private GameObject progressBarContainer;
// State
private ICardSystemSettings _settings;
private bool _isFlipped = false;
private bool _isFlipping = false;
private TweenBase _idleHoverTween;
private CardData _cardData;
private Vector2 _originalPosition; // Track original spawn position
private bool _isWaitingForTap = false; // Waiting for tap after reveal
private bool _isNew = false; // Is this a new card
private int _ownedCount = 0; // Owned count for repeat cards
private bool _isClickable = true; // Can this card be clicked
// Events
public event Action<FlippableCard, CardData> OnCardRevealed;
public event Action<FlippableCard> OnCardTappedAfterReveal;
public event Action<FlippableCard> OnClickedWhileInactive; // Fired when clicked but not clickable
public event Action<FlippableCard> OnFlipStarted; // Fired when flip animation begins
public bool IsFlipped => _isFlipped;
public CardData CardData => _cardData;
public int CardsToUpgrade => _settings?.CardsToUpgrade ?? 5;
private void Awake()
{
_settings = GameManager.GetSettingsObject<ICardSystemSettings>();
// Auto-find CardDisplay if not assigned
if (cardDisplay == null && cardFrontObject != null)
{
cardDisplay = cardFrontObject.GetComponent<CardDisplay>();
}
// Auto-find AlbumCard if not assigned
if (albumCard == null)
{
albumCard = GetComponentInChildren<AlbumCard>();
}
// Card back: starts at 0° rotation (normal, facing camera, clickable)
// Card front: starts at 180° rotation (flipped away, will rotate to 0° when revealed)
if (cardBackObject != null)
{
cardBackObject.transform.localRotation = Quaternion.Euler(0, 0, 0);
cardBackObject.SetActive(true);
}
if (cardFrontObject != null)
{
cardFrontObject.transform.localRotation = Quaternion.Euler(0, 180, 0);
cardFrontObject.SetActive(false);
}
// Hide all new/repeat UI elements initially
if (newCardText != null)
newCardText.SetActive(false);
if (newCardIdleText != null)
newCardIdleText.SetActive(false);
if (repeatText != null)
repeatText.SetActive(false);
if (progressBarContainer != null)
progressBarContainer.SetActive(false);
}
private void Start()
{
// Save the original position so we can return to it after hover
RectTransform rectTransform = GetComponent<RectTransform>();
if (rectTransform != null)
{
_originalPosition = rectTransform.anchoredPosition;
}
// Start idle hover animation
if (enableIdleHover && !_isFlipped)
{
StartIdleHover();
}
}
/// <summary>
/// Setup the card data (stores it but doesn't reveal until flipped)
/// </summary>
public void SetupCard(CardData data)
{
_cardData = data;
// Setup the CardDisplay but keep it hidden
if (cardDisplay != null)
{
cardDisplay.SetupCard(data);
}
}
/// <summary>
/// Flip the card to reveal the front
/// </summary>
public void FlipToReveal()
{
if (_isFlipped || _isFlipping)
return;
_isFlipping = true;
// Fire flip started event IMMEDIATELY (before animations)
OnFlipStarted?.Invoke(this);
// Stop idle hover
StopIdleHover();
// Flip animation: Rotate the visual children (back from 0→90, front from 180→0)
// ...existing code...
// Card back: 0° → 90° (rotates away)
// Card front: 180° → 90° → 0° (rotates into view)
float flipDur = _settings.FlipDuration;
float flipPunch = _settings.FlipScalePunch;
// Phase 1: Rotate both to 90 degrees (edge view)
if (cardBackObject != null)
{
Tween.LocalRotation(cardBackObject.transform, Quaternion.Euler(0, 90, 0), flipDur * 0.5f, 0f, Tween.EaseInOut);
}
if (cardFrontObject != null)
{
Tween.LocalRotation(cardFrontObject.transform, Quaternion.Euler(0, 90, 0), flipDur * 0.5f, 0f, Tween.EaseInOut,
completeCallback: () =>
{
// At edge (90°), switch visibility
if (cardBackObject != null)
cardBackObject.SetActive(false);
if (cardFrontObject != null)
cardFrontObject.SetActive(true);
// Phase 2: Rotate front from 90 to 0 (show at correct orientation)
Tween.LocalRotation(cardFrontObject.transform, Quaternion.Euler(0, 0, 0), flipDur * 0.5f, 0f, Tween.EaseInOut,
completeCallback: () =>
{
_isFlipped = true;
_isFlipping = false;
// Fire revealed event
OnCardRevealed?.Invoke(this, _cardData);
});
});
}
// Scale punch during flip for extra juice
Vector3 originalScale = transform.localScale;
Tween.LocalScale(transform, originalScale * flipPunch, flipDur * 0.5f, 0f, Tween.EaseOutBack,
completeCallback: () =>
{
Tween.LocalScale(transform, originalScale, flipDur * 0.5f, 0f, Tween.EaseInBack);
});
}
/// <summary>
/// Start idle hover animation (gentle bobbing)
/// </summary>
private void StartIdleHover()
{
if (_idleHoverTween != null)
return;
RectTransform rectTransform = GetComponent<RectTransform>();
if (rectTransform == null)
return;
Vector2 originalPos = rectTransform.anchoredPosition;
Vector2 targetPos = originalPos + Vector2.up * _settings.IdleHoverHeight;
_idleHoverTween = Tween.Value(0f, 1f,
(val) =>
{
if (rectTransform != null)
{
float t = Mathf.Sin(val * Mathf.PI * 2f) * 0.5f + 0.5f; // Smooth sine wave
rectTransform.anchoredPosition = Vector2.Lerp(originalPos, targetPos, t);
}
},
_settings.IdleHoverDuration, 0f, Tween.EaseInOut, Tween.LoopType.Loop);
}
/// <summary>
/// Stop idle hover animation
/// </summary>
private void StopIdleHover()
{
if (_idleHoverTween != null)
{
_idleHoverTween.Stop();
_idleHoverTween = null;
// Reset to ORIGINAL position (not Vector2.zero!)
RectTransform rectTransform = GetComponent<RectTransform>();
if (rectTransform != null)
{
Tween.AnchoredPosition(rectTransform, _originalPosition, 0.3f, 0f, Tween.EaseOutBack);
}
}
}
#region Pointer Event Handlers
public void OnPointerEnter(PointerEventData eventData)
{
if (_isFlipped || _isFlipping)
return;
// Scale up slightly on hover
Tween.LocalScale(transform, Vector3.one * _settings.HoverScaleMultiplier, 0.2f, 0f, Tween.EaseOutBack);
}
public void OnPointerExit(PointerEventData eventData)
{
if (_isFlipped || _isFlipping)
return;
// Scale back to normal
Tween.LocalScale(transform, Vector3.one, 0.2f, 0f, Tween.EaseOutBack);
}
public void OnPointerClick(PointerEventData eventData)
{
Logging.Debug($"[CLICK-TRACE-FLIPPABLE] OnPointerClick on {name}, _isClickable={_isClickable}, _isWaitingForTap={_isWaitingForTap}, _isFlipped={_isFlipped}, position={eventData.position}");
// If not clickable, notify and return
if (!_isClickable)
{
Logging.Debug($"[CLICK-TRACE-FLIPPABLE] {name} - Not clickable, firing OnClickedWhileInactive");
OnClickedWhileInactive?.Invoke(this);
return;
}
// If waiting for tap after reveal, handle that
if (_isWaitingForTap)
{
Logging.Debug($"[CLICK-TRACE-FLIPPABLE] {name} - Waiting for tap, dismissing enlarged state");
OnCardTappedAfterReveal?.Invoke(this);
_isWaitingForTap = false;
return;
}
if (_isFlipped || _isFlipping)
{
Logging.Debug($"[CLICK-TRACE-FLIPPABLE] {name} - Ignoring click (flipped={_isFlipped}, flipping={_isFlipping})");
return;
}
Logging.Debug($"[CLICK-TRACE-FLIPPABLE] {name} - Processing click, starting flip");
// Flip on click
FlipToReveal();
}
#endregion
#region New/Repeat Card Display
/// <summary>
/// Show this card as a new card (enlarge, show "NEW CARD" text, wait for tap)
/// </summary>
public void ShowAsNew()
{
_isNew = true;
_isWaitingForTap = true;
// Show new card text
if (newCardText != null)
newCardText.SetActive(true);
// Enlarge the card
EnlargeCard();
}
/// <summary>
/// Show this card as a repeat that will trigger an upgrade (enlarge, show progress, auto-transition to upgrade)
/// </summary>
/// <param name="ownedCount">Number of copies owned BEFORE this one</param>
/// <param name="lowerRarityCard">The existing card data at lower rarity (for upgrade reference)</param>
public void ShowAsRepeatWithUpgrade(int ownedCount, AppleHills.Data.CardSystem.CardData lowerRarityCard)
{
_isNew = false;
_ownedCount = ownedCount;
_isWaitingForTap = false; // Don't wait yet - upgrade will happen automatically
// Show repeat text
if (repeatText != null)
repeatText.SetActive(true);
// Enlarge the card
EnlargeCard();
// Show progress bar with owned count, then auto-trigger upgrade
ShowProgressBar(ownedCount, () =>
{
// Progress animation complete - trigger upgrade!
TriggerUpgradeTransition(lowerRarityCard);
});
}
/// <summary>
/// Trigger the upgrade transition (called after progress bar fills)
/// </summary>
private void TriggerUpgradeTransition(AppleHills.Data.CardSystem.CardData lowerRarityCard)
{
Logging.Debug($"[FlippableCard] Triggering upgrade transition from {lowerRarityCard.Rarity}!");
AppleHills.Data.CardSystem.CardRarity oldRarity = lowerRarityCard.Rarity;
AppleHills.Data.CardSystem.CardRarity newRarity = oldRarity + 1;
// Reset the lower rarity count to 0
lowerRarityCard.CopiesOwned = 0;
// Create upgraded card data
AppleHills.Data.CardSystem.CardData upgradedCardData = new AppleHills.Data.CardSystem.CardData(_cardData);
upgradedCardData.Rarity = newRarity;
upgradedCardData.CopiesOwned = 1;
// Check if we already have this card at the higher rarity
bool isNewAtHigherRarity = Data.CardSystem.CardSystemManager.Instance.IsCardNew(upgradedCardData, out AppleHills.Data.CardSystem.CardData existingHigherRarity);
// Add the higher rarity card to inventory
Data.CardSystem.CardSystemManager.Instance.GetCardInventory().AddCard(upgradedCardData);
// Update our displayed card data
_cardData.Rarity = newRarity;
// Transition to appropriate display
if (isNewAtHigherRarity || newRarity == AppleHills.Data.CardSystem.CardRarity.Legendary)
{
// Show as NEW at higher rarity
TransitionToNewCardView(newRarity);
}
else
{
// Show progress for higher rarity, then transition to NEW
int ownedAtHigherRarity = existingHigherRarity.CopiesOwned;
ShowProgressBar(ownedAtHigherRarity, () =>
{
TransitionToNewCardView(newRarity);
});
}
}
/// <summary>
/// Show this card as a repeat (enlarge, show progress bar, wait for tap)
/// </summary>
/// <param name="ownedCount">Number of copies owned BEFORE this one</param>
public void ShowAsRepeat(int ownedCount)
{
_isNew = false;
_ownedCount = ownedCount;
_isWaitingForTap = true;
// Show repeat text
if (repeatText != null)
repeatText.SetActive(true);
// Enlarge the card
EnlargeCard();
// Show progress bar with owned count, then blink new element
ShowProgressBar(ownedCount, () =>
{
// Progress animation complete
});
}
/// <summary>
/// Show this card as upgraded (hide progress bar, show as new with upgraded rarity)
/// </summary>
public void ShowAsUpgraded(AppleHills.Data.CardSystem.CardRarity oldRarity, AppleHills.Data.CardSystem.CardRarity newRarity)
{
_isNew = true;
_isWaitingForTap = true;
// Update the CardDisplay to show new rarity
if (cardDisplay != null && _cardData != null)
{
_cardData.Rarity = newRarity;
cardDisplay.SetupCard(_cardData);
}
// Hide progress bar and repeat text
if (progressBarContainer != null)
progressBarContainer.SetActive(false);
if (repeatText != null)
repeatText.SetActive(false);
// Show new card text (it's now a "new" card at the higher rarity)
if (newCardText != null)
newCardText.SetActive(true);
Logging.Debug($"[FlippableCard] Card upgraded from {oldRarity} to {newRarity}! Showing as NEW.");
// Card is already enlarged from the repeat display, so no need to enlarge again
}
/// <summary>
/// Show this card as upgraded with progress bar (already have copies at higher rarity)
/// </summary>
public void ShowAsUpgradedWithProgress(AppleHills.Data.CardSystem.CardRarity oldRarity, AppleHills.Data.CardSystem.CardRarity newRarity, int ownedAtNewRarity)
{
_isNew = false;
_isWaitingForTap = false; // Don't wait for tap yet, progress bar will complete first
// Hide new card text
if (newCardText != null)
newCardText.SetActive(false);
// Show repeat text (it's a repeat at the new rarity)
if (repeatText != null)
repeatText.SetActive(true);
// Show progress bar for the new rarity
ShowProgressBar(ownedAtNewRarity, () =>
{
// Progress animation complete - now transition to "NEW CARD" view
TransitionToNewCardView(newRarity);
});
Logging.Debug($"[FlippableCard] Card upgraded from {oldRarity} to {newRarity}! Showing progress {ownedAtNewRarity}/5");
}
/// <summary>
/// Transition to "NEW CARD" view after upgrade progress completes
/// </summary>
private void TransitionToNewCardView(AppleHills.Data.CardSystem.CardRarity newRarity)
{
Logging.Debug($"[FlippableCard] Transitioning to NEW CARD view at {newRarity} rarity");
// Update the CardDisplay to show new rarity
if (cardDisplay != null && _cardData != null)
{
_cardData.Rarity = newRarity;
cardDisplay.SetupCard(_cardData);
}
// Hide progress bar and repeat text
if (progressBarContainer != null)
progressBarContainer.SetActive(false);
if (repeatText != null)
repeatText.SetActive(false);
// Show "NEW CARD" text
if (newCardText != null)
newCardText.SetActive(true);
// Now wait for tap
_isNew = true;
_isWaitingForTap = true;
Logging.Debug($"[FlippableCard] Now showing as NEW CARD at {newRarity}, waiting for tap");
}
/// <summary>
/// Enlarge the card
/// </summary>
private void EnlargeCard()
{
Tween.LocalScale(transform, Vector3.one * _settings.NewCardEnlargedScale, _settings.ScaleDuration, 0f, Tween.EaseOutBack);
}
/// <summary>
/// Return card to normal size
/// </summary>
public void ReturnToNormalSize()
{
Tween.LocalScale(transform, Vector3.one, _settings.ScaleDuration, 0f, Tween.EaseOutBack, completeCallback: () =>
{
// After returning to normal, hide new card text, show idle text
if (_isNew)
{
if (newCardText != null)
newCardText.SetActive(false);
if (newCardIdleText != null)
newCardIdleText.SetActive(true);
}
// Keep repeat text visible
});
}
/// <summary>
/// Show progress bar with owned count, then blink the new element
/// </summary>
private void ShowProgressBar(int ownedCount, System.Action onComplete)
{
if (progressBarContainer == null)
{
onComplete?.Invoke();
return;
}
progressBarContainer.SetActive(true);
// Get all child Image components
UnityEngine.UI.Image[] progressElements = progressBarContainer.GetComponentsInChildren<UnityEngine.UI.Image>(true);
int cardsToUpgrade = _settings.CardsToUpgrade;
// Check if we have the required number of elements (should match cardsToUpgrade)
if (progressElements.Length < cardsToUpgrade)
{
Logging.Warning($"[FlippableCard] Not enough Image components in progress bar! Expected {cardsToUpgrade}, found {progressElements.Length}");
onComplete?.Invoke();
return;
}
// Disable all elements first
foreach (var img in progressElements)
{
img.enabled = false;
}
// Show owned count (from the END, going backwards)
// E.g., if owned 3 cards, enable elements at index [4], [3], [2] (last 3 elements)
int startIndex = Mathf.Max(0, cardsToUpgrade - ownedCount);
for (int i = startIndex; i < cardsToUpgrade && i < progressElements.Length; i++)
{
progressElements[i].enabled = true;
}
// Wait a moment, then blink the new element
// New element is at index (cardsToUpgrade - ownedCount - 1)
int newElementIndex = Mathf.Max(0, cardsToUpgrade - ownedCount - 1);
if (newElementIndex >= 0 && newElementIndex < progressElements.Length)
{
Tween.Value(0f, 1f, (val) => { }, 0.3f, 0f, completeCallback: () =>
{
BlinkProgressElement(newElementIndex, progressElements, onComplete);
});
}
else
{
onComplete?.Invoke();
}
}
/// <summary>
/// Blink a progress element (enable/disable rapidly)
/// </summary>
private void BlinkProgressElement(int index, UnityEngine.UI.Image[] elements, System.Action onComplete)
{
if (index < 0 || index >= elements.Length)
{
onComplete?.Invoke();
return;
}
UnityEngine.UI.Image element = elements[index];
int blinkCount = 0;
const int maxBlinks = 3;
void Blink()
{
element.enabled = !element.enabled;
blinkCount++;
if (blinkCount >= maxBlinks * 2)
{
element.enabled = true; // End on enabled
onComplete?.Invoke();
}
else
{
Tween.Value(0f, 1f, (val) => { }, 0.15f, 0f, completeCallback: Blink);
}
}
Blink();
}
/// <summary>
/// Enable or disable clickability of this card
/// </summary>
public void SetClickable(bool clickable)
{
_isClickable = clickable;
}
/// <summary>
/// Jiggle the card (shake animation)
/// </summary>
public void Jiggle()
{
// Quick shake animation - rotate left, then right, then center
Transform cardTransform = transform;
Quaternion originalRotation = cardTransform.localRotation;
// Shake sequence: 0 -> -5 -> +5 -> 0
Tween.LocalRotation(cardTransform, Quaternion.Euler(0, 0, -5), 0.05f, 0f, Tween.EaseInOut,
completeCallback: () =>
{
Tween.LocalRotation(cardTransform, Quaternion.Euler(0, 0, 5), 0.1f, 0f, Tween.EaseInOut,
completeCallback: () =>
{
Tween.LocalRotation(cardTransform, originalRotation, 0.05f, 0f, Tween.EaseInOut);
});
});
}
/// <summary>
/// Extract the nested AlbumCard and reparent it to a new parent
/// Used when placing card in album slot - extracts the AlbumCard from this wrapper
/// The caller is responsible for tweening it to the final position
/// </summary>
/// <param name="newParent">The transform to reparent the AlbumCard to (typically the AlbumCardSlot)</param>
/// <returns>The extracted AlbumCard component, or null if not found</returns>
public AlbumCard ExtractAlbumCard(Transform newParent)
{
if (albumCard == null)
{
Logging.Warning("[FlippableCard] Cannot extract AlbumCard - none found!");
return null;
}
// Reparent AlbumCard to new parent (maintain world position temporarily)
// The caller will tween it to the final position
albumCard.transform.SetParent(newParent, true);
// Setup the card data on the AlbumCard
if (_cardData != null)
{
albumCard.SetupCard(_cardData);
}
Logging.Debug($"[FlippableCard] Extracted AlbumCard '{_cardData?.Name}' to {newParent.name} - ready for tween");
return albumCard;
}
#endregion
private void OnDestroy()
{
StopIdleHover();
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: bb9e3a783cd7fce4aab2ff7f7f63119b

View File

@@ -1,219 +0,0 @@
# DEPRECATED - Old Card System Files
## ⚠️ This folder contains old card system files that have been replaced by the new state machine implementation.
**DO NOT USE THESE FILES IN NEW CODE.**
These files are kept temporarily for backward compatibility during migration. Once all code is migrated to the new Card state machine system, this entire folder can be deleted.
---
## Files in this folder:
### **Old Card Components:**
1. **FlippableCard.cs**
- Old monolithic card component for booster opening
- **Replaced by:** `Card.cs` + state machine (IdleState, FlippingState, EnlargedNewState, etc.)
- 700+ lines of boolean-driven state management
- Used in old BoosterOpeningPage
2. **AlbumCard.cs**
- Old album card component for tap-to-enlarge functionality
- **Replaced by:** `Card.cs` (PlacedInSlotState → AlbumEnlargedState)
- Wrapped CardDisplay and managed enlarge/shrink
- Used in old AlbumViewPage
### **Old Drag/Drop Wrappers:**
3. **CardDraggable.cs**
- Empty wrapper around DraggableObject
- Only stored CardData (now in CardContext)
- **Replaced by:** `Card.cs` now inherits from DraggableObject directly
4. **CardDraggableVisual.cs**
- Visual component for CardDraggable
- Managed CardDisplay child
- **Replaced by:** Card state machine handles all visuals
5. **AlbumCardPlacementDraggable.cs**
- Drag wrapper for FlippableCard in album corner placement flow
- Handled tap-to-reveal, drag-to-place logic
- **Replaced by:** `Card.cs` with SetupForAlbumPlacement() + drag event hooks
### **Old Interaction Handler:**
6. **CardInteractionHandler.cs**
- Bridge between Unity pointer events and state machine
- Implemented IBeginDragHandler, IDragHandler, IEndDragHandler
- **Replaced by:** `Card.cs` inherits from DraggableObject (already has these interfaces)
---
## What Replaced Them:
### **New State Machine System:**
**Single Card Component:**
```
Card.cs (inherits from DraggableObject)
├─ CardContext.cs (shared data + events)
├─ CardAnimator.cs (reusable animations)
└─ 7 State Components:
├─ CardIdleState.cs (card back, hover, click to flip)
├─ CardRevealedState.cs (normal size, waiting, idle badges)
├─ CardEnlargedNewState.cs (enlarged with NEW badge)
├─ CardEnlargedRepeatState.cs (enlarged with progress bar)
├─ CardDraggingState.cs (visual feedback during drag)
├─ CardPlacedInSlotState.cs (in album slot)
└─ CardAlbumEnlargedState.cs (enlarged from album)
```
### **Benefits:**
-**60% less code** (shared components, no duplication)
-**No boolean soup** (1 active state vs 12+ boolean flags)
-**Automatic visual management** (state-owned GameObjects)
-**Easier testing** (can test states in isolation)
-**Simpler extension** (add new state vs modify monolith)
-**Better debugging** (inspector shows active state name)
---
## Migration Status:
### **Phase 1: Implementation ✅ COMPLETE**
- [x] Created Card.cs with state machine
- [x] Created all 7 state components
- [x] Created CardContext, CardAnimator
- [x] Integrated drag/drop (Card inherits DraggableObject)
- [x] Moved old files to DEPRECATED/
### **Phase 2: Booster Opening Migration 🚧 IN PROGRESS**
- [ ] Update BoosterOpeningPage to use Card.cs
- [ ] Replace FlippableCard spawning with Card spawning
- [ ] Use Card.SetupForBoosterReveal()
- [ ] Test all booster flows (NEW, REPEAT, UPGRADE)
### **Phase 3: Album Migration 🚧 PENDING**
- [ ] Update AlbumViewPage corner cards to use Card.cs
- [ ] Use Card.SetupForAlbumPlacement()
- [ ] Update album slots to use Card.cs
- [ ] Use Card.SetupForAlbumSlot()
- [ ] Test drag/drop to slots
- [ ] Test enlarge/shrink from album
### **Phase 4: Cleanup 🚧 PENDING**
- [ ] Verify no references to old files in active code
- [ ] Delete DEPRECATED/ folder
- [ ] Remove old prefab variants
- [ ] Update documentation
---
## How to Migrate Code:
### **Old Booster Opening (FlippableCard):**
```csharp
// OLD:
FlippableCard card = Instantiate(flippableCardPrefab);
card.SetupCard(cardData);
card.OnCardRevealed += OnCardRevealed;
if (isNewCard)
card.ShowAsNew();
else if (willUpgrade)
card.ShowAsRepeatWithUpgrade(ownedCount, lowerRarityCard);
else
card.ShowAsRepeat(ownedCount);
```
### **New Booster Opening (Card + States):**
```csharp
// NEW:
Card card = Instantiate(cardPrefab);
card.SetupForBoosterReveal(cardData, isNew: isNewCard);
card.Context.RepeatCardCount = ownedCount;
card.Context.OnFlipComplete += OnCardFlipComplete;
card.Context.OnCardInteractionComplete += OnCardComplete;
// Card automatically transitions through states on click
```
---
### **Old Album Placement (AlbumCardPlacementDraggable):**
```csharp
// OLD:
AlbumCardPlacementDraggable card = Instantiate(placementPrefab);
card.SetupCard(cardData);
card.OnCardRevealed += OnCardRevealed;
card.OnCardPlacedInAlbum += OnCardPlaced;
// Tap to reveal, drag to place
```
### **New Album Placement (Card + States):**
```csharp
// NEW:
Card card = Instantiate(cardPrefab);
card.SetupForAlbumPlacement(cardData);
// Card starts in RevealedState, can be dragged
// Automatically transitions to PlacedInSlotState when dropped in slot
```
---
### **Old Album Card (AlbumCard):**
```csharp
// OLD:
AlbumCard card = Instantiate(albumCardPrefab);
card.SetupCard(cardData);
card.OnEnlargeRequested += OnCardEnlarged;
card.OnShrinkRequested += OnCardShrunk;
card.EnlargeCard(); // Manual enlarge
```
### **New Album Card (Card + States):**
```csharp
// NEW:
Card card = Instantiate(cardPrefab, albumSlot.transform);
card.SetupForAlbumSlot(cardData, albumSlot);
// Click to enlarge → AlbumEnlargedState
// Tap to shrink → PlacedInSlotState
// State machine handles transitions automatically
```
---
## When Can We Delete This Folder?
**Checklist:**
- [ ] BoosterOpeningPage fully migrated to Card.cs
- [ ] AlbumViewPage fully migrated to Card.cs
- [ ] All prefabs updated to use new Card prefab
- [ ] All old prefabs deleted/archived
- [ ] No compiler references to:
- FlippableCard
- AlbumCard
- CardDraggable
- CardDraggableVisual
- AlbumCardPlacementDraggable
- CardInteractionHandler
- [ ] All tests passing with new system
- [ ] QA approved for production
**Once all checkboxes are complete, delete this entire DEPRECATED/ folder.**
---
## Need Help Migrating?
See documentation:
- `docs/cards_wip/card_system_implementation_summary.md` - Architecture overview
- `docs/cards_wip/card_prefab_assembly_guide.md` - How to build Card prefab
- `docs/cards_wip/card_dragdrop_integration_summary.md` - Drag/drop integration
- `docs/cards_wip/card_test_scene_setup_guide.md` - Testing scene setup
---
**Last Updated:** December 11, 2025
**Migration Status:** Phase 1 Complete, Phase 2-4 In Progress

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 77fe31c3dcfb4d4d8cfee187b838e8e3
timeCreated: 1762951626

View File

@@ -3,7 +3,6 @@ using Core;
using Data.CardSystem;
using UI.DragAndDrop.Core;
using UnityEngine;
using UnityEngine.EventSystems;
namespace UI.CardSystem
{
@@ -11,131 +10,21 @@ namespace UI.CardSystem
/// Specialized slot for album pages that only accepts a specific card.
/// Validates cards based on their CardDefinition.
/// Self-populates with owned cards when enabled.
/// Shows preview of target card when empty slot is tapped.
/// </summary>
public class AlbumCardSlot : DraggableSlot, IPointerClickHandler
public class AlbumCardSlot : DraggableSlot
{
[Header("Album Slot Configuration")]
[SerializeField] private CardDefinition targetCardDefinition; // Which card this slot accepts
[SerializeField] private GameObject albumCardPrefab; // Prefab to spawn when card is owned
[SerializeField] private GameObject cardPrefab; // Card prefab to spawn when card is owned
[Header("Preview Card (for empty slots)")]
[SerializeField] private CardDisplay previewCardDisplay; // Nested CardDisplay showing greyed-out preview
[SerializeField] private float previewEnlargedScale = 2.5f;
[SerializeField] private float previewScaleDuration = 0.3f;
private bool _isOccupiedPermanently = false;
private AlbumCard _placedCard;
private bool _isPreviewShowing = false;
private Vector3 _previewOriginalScale;
private void Awake()
{
// Store original scale of preview card
if (previewCardDisplay != null)
{
_previewOriginalScale = previewCardDisplay.transform.localScale;
// Hide preview card by default
previewCardDisplay.gameObject.SetActive(false);
}
}
/// <summary>
/// Set the target card this slot should accept
/// </summary>
public void SetTargetCard(CardDefinition definition)
{
targetCardDefinition = definition;
}
/// <summary>
/// Check if this slot can accept a specific card
/// </summary>
public bool CanAcceptCard(CardData cardData)
{
if (cardData == null || targetCardDefinition == null) return false;
if (_isOccupiedPermanently) return false;
// Card must match this slot's target definition
return cardData.DefinitionId == targetCardDefinition.Id;
}
/// <summary>
/// Called when a card is successfully placed in this slot
/// </summary>
public void OnCardPlaced(AlbumCard albumCard = null)
{
_isOccupiedPermanently = true;
if (albumCard != null)
{
_placedCard = albumCard;
albumCard.SetParentSlot(this);
// Register with AlbumViewPage for enlarge/shrink handling
AlbumViewPage albumPage = FindFirstObjectByType<AlbumViewPage>();
if (albumPage != null)
{
albumPage.RegisterAlbumCard(albumCard);
}
}
}
/// <summary>
/// Check if this slot has a placed card
/// </summary>
public bool HasPlacedCard()
{
return _placedCard != null;
}
/// <summary>
/// Get the placed card (if any)
/// </summary>
public AlbumCard GetPlacedCard()
{
return _placedCard;
}
private StateMachine.Card _placedCard;
private void OnEnable()
{
// Check if we should spawn a card for this slot
CheckAndSpawnOwnedCard();
// Setup preview card display if slot is empty
SetupPreviewCard();
}
/// <summary>
/// Setup the preview card display to show target card with preview visuals
/// Preview stays hidden until user taps to show it
/// </summary>
private void SetupPreviewCard()
{
if (previewCardDisplay == null || targetCardDefinition == null)
return;
// Only setup preview if slot is empty
if (_isOccupiedPermanently || _placedCard != null)
{
// Hide preview if slot is occupied
previewCardDisplay.gameObject.SetActive(false);
return;
}
// Setup preview card data
CardData previewData = targetCardDefinition.CreateCardData();
previewData.Rarity = CardRarity.Normal; // Show as normal rarity
previewCardDisplay.SetupCard(previewData);
// Apply preview visuals (black tint and ?????? name)
previewCardDisplay.SetPreviewVisuals();
// Keep preview hidden - it'll show when user taps to enlarge
previewCardDisplay.gameObject.SetActive(false);
Logging.Debug($"[AlbumCardSlot] Setup preview card for {targetCardDefinition.Name} (hidden until tap)");
}
/// <summary>
/// Check if player owns the card for this slot and spawn it if so
@@ -147,13 +36,13 @@ namespace UI.CardSystem
return;
// Guard: don't spawn if already occupied
if (_isOccupiedPermanently || _placedCard != null)
if (_placedCard != null)
return;
// Guard: need prefab to spawn
if (albumCardPrefab == null)
if (cardPrefab == null)
{
Logging.Warning($"[AlbumCardSlot] No albumCardPrefab assigned for slot targeting {targetCardDefinition.name}");
Logging.Warning($"[AlbumCardSlot] No cardPrefab assigned for slot targeting {targetCardDefinition.name}");
return;
}
@@ -174,27 +63,26 @@ namespace UI.CardSystem
// Spawn card if owned
if (ownedCard != null)
{
SpawnAlbumCard(ownedCard);
SpawnCard(ownedCard);
}
}
/// <summary>
/// Spawn an AlbumCard in this slot
/// Spawn a Card in this slot using the PlacedInSlotState
/// </summary>
private void SpawnAlbumCard(CardData cardData)
private void SpawnCard(CardData cardData)
{
GameObject cardObj = Instantiate(albumCardPrefab, transform);
AlbumCard albumCard = cardObj.GetComponent<AlbumCard>();
GameObject cardObj = Instantiate(cardPrefab, transform);
var card = cardObj.GetComponent<StateMachine.Card>();
if (albumCard != null)
if (card != null)
{
albumCard.SetupCard(cardData);
albumCard.SetParentSlot(this);
_placedCard = albumCard;
_isOccupiedPermanently = true;
// Setup card for album slot (starts in PlacedInSlotState)
card.SetupForAlbumSlot(cardData, this);
_placedCard = card;
// Resize the card to match the slot size (same as placed cards)
RectTransform cardRect = albumCard.transform as RectTransform;
// Resize the card to match the slot size
RectTransform cardRect = card.transform as RectTransform;
RectTransform slotRect = transform as RectTransform;
if (cardRect != null && slotRect != null)
{
@@ -211,156 +99,22 @@ namespace UI.CardSystem
AlbumViewPage albumPage = FindFirstObjectByType<AlbumViewPage>();
if (albumPage != null)
{
albumPage.RegisterAlbumCard(albumCard);
albumPage.RegisterCardInAlbum(card);
}
Logging.Debug($"[AlbumCardSlot] Spawned owned card '{cardData.Name}' ({cardData.Rarity}) in slot");
}
else
{
Logging.Warning($"[AlbumCardSlot] Spawned prefab has no AlbumCard component!");
Logging.Warning($"[AlbumCardSlot] Spawned prefab has no Card component!");
Destroy(cardObj);
}
}
/// <summary>
/// Get the target card definition for this slot
/// </summary>
public CardDefinition GetTargetCardDefinition()
{
return targetCardDefinition;
}
/// <summary>
/// Handle click on slot - show/hide preview if empty
/// </summary>
public void OnPointerClick(PointerEventData eventData)
{
Logging.Debug($"[CLICK-TRACE-SLOT] OnPointerClick on {name}, _isOccupiedPermanently={_isOccupiedPermanently}, _placedCard={((_placedCard != null) ? _placedCard.name : "NULL")}, _isPreviewShowing={_isPreviewShowing}, position={eventData.position}");
// Only handle clicks if slot is empty
if (_isOccupiedPermanently || _placedCard != null)
{
Logging.Debug($"[CLICK-TRACE-SLOT] {name} - Slot is occupied, ignoring");
return;
}
// Only handle if we have a preview card setup
if (previewCardDisplay == null || targetCardDefinition == null)
{
Logging.Debug($"[CLICK-TRACE-SLOT] {name} - No preview setup, ignoring");
return;
}
if (_isPreviewShowing)
{
Logging.Debug($"[CLICK-TRACE-SLOT] {name} - Preview is showing, hiding it");
HidePreview();
}
else
{
Logging.Debug($"[CLICK-TRACE-SLOT] {name} - Preview is hidden, showing it");
ShowPreview();
}
}
/// <summary>
/// Show enlarged preview of target card
/// </summary>
private void ShowPreview()
{
if (_isPreviewShowing || previewCardDisplay == null)
return;
_isPreviewShowing = true;
// Show the preview card (already has preview visuals applied)
previewCardDisplay.gameObject.SetActive(true);
// Enable preview mode so clicks on CardDisplay forward to this slot
previewCardDisplay.SetPreviewMode(true, this);
// Reset to normal scale before enlarging
previewCardDisplay.transform.localScale = _previewOriginalScale;
// Get AlbumViewPage to show backdrop and reparent
AlbumViewPage albumPage = FindFirstObjectByType<AlbumViewPage>();
if (albumPage != null)
{
albumPage.ShowSlotPreview(this, previewCardDisplay.transform);
}
// Scale up preview card
Pixelplacement.Tween.LocalScale(previewCardDisplay.transform, _previewOriginalScale * previewEnlargedScale,
previewScaleDuration, 0f, Pixelplacement.Tween.EaseOutBack);
Logging.Debug($"[AlbumCardSlot] Showing preview for {targetCardDefinition.Name}");
}
/// <summary>
/// Hide preview and return to normal
/// </summary>
private void HidePreview()
{
if (!_isPreviewShowing || previewCardDisplay == null)
return;
_isPreviewShowing = false;
// Disable preview mode on CardDisplay
previewCardDisplay.SetPreviewMode(false, null);
// Get AlbumViewPage to hide backdrop
AlbumViewPage albumPage = FindFirstObjectByType<AlbumViewPage>();
if (albumPage != null)
{
albumPage.HideSlotPreview(this, previewCardDisplay.transform, () =>
{
// After shrink completes, reparent back to slot
previewCardDisplay.transform.SetParent(transform, false);
// Reset RectTransform properties
RectTransform previewRect = previewCardDisplay.transform as RectTransform;
if (previewRect != null)
{
// Set anchors to stretch in all directions (matching original setup)
previewRect.anchorMin = Vector2.zero; // (0, 0)
previewRect.anchorMax = Vector2.one; // (1, 1)
// Reset offsets to zero (left, right, top, bottom all = 0)
previewRect.offsetMin = Vector2.zero; // Sets left and bottom to 0
previewRect.offsetMax = Vector2.zero; // Sets right and top to 0 (note: these are negative values internally)
previewRect.pivot = new Vector2(0.5f, 0.5f);
}
previewCardDisplay.transform.localPosition = Vector3.zero;
previewCardDisplay.transform.localRotation = Quaternion.identity;
previewCardDisplay.transform.localScale = _previewOriginalScale;
// Hide the preview card after returning to slot
previewCardDisplay.gameObject.SetActive(false);
Logging.Debug($"[AlbumCardSlot] Preview hidden and reset for {targetCardDefinition.Name}");
});
}
Logging.Debug($"[AlbumCardSlot] Hiding preview for {targetCardDefinition.Name}");
}
/// <summary>
/// Public method to dismiss preview - can be called by CardDisplay when clicked
/// </summary>
public void DismissPreview()
{
Logging.Debug($"[CLICK-TRACE-SLOT] DismissPreview called on {name}");
HidePreview();
}
/// <summary>
/// Get the target card definition for this slot
/// </summary>
public CardDefinition TargetCardDefinition => targetCardDefinition;
}
}

View File

@@ -28,6 +28,14 @@ namespace UI.CardSystem.StateMachine
public AppleMachine StateMachine => stateMachine;
public CardData CardData => context?.CardData;
// State inspection properties for booster flow
public bool IsIdle => GetCurrentStateName() == "IdleState";
public bool IsRevealing => !IsIdle && !IsComplete;
public bool IsComplete => context?.HasCompletedReveal ?? false;
// Event fired when this card is successfully placed into an AlbumCardSlot
public event System.Action<Card, AlbumCardSlot> OnPlacedInAlbumSlot;
protected override void Initialize()
{
base.Initialize(); // Call DraggableObject initialization
@@ -71,6 +79,9 @@ namespace UI.CardSystem.StateMachine
}
ChangeState("PlacedInSlotState");
// Notify listeners (AlbumViewPage) that this pending card was placed
OnPlacedInAlbumSlot?.Invoke(this, albumSlot);
}
else
{
@@ -84,11 +95,11 @@ namespace UI.CardSystem.StateMachine
/// <summary>
/// Setup the card with data and optional initial state
/// </summary>
public void SetupCard(CardData data, bool isNew = false, string startState = null)
public void SetupCard(CardData data, string startState = null)
{
if (context != null)
{
context.SetupCard(data, isNew);
context.SetupCard(data);
}
// Start the state machine with specified or default state
@@ -102,10 +113,11 @@ namespace UI.CardSystem.StateMachine
/// <summary>
/// Setup for booster reveal flow (starts at IdleState, will flip on click)
/// Dragging is DISABLED for booster cards
/// States will query CardSystemManager for collection state as needed
/// </summary>
public void SetupForBoosterReveal(CardData data, bool isNew)
{
SetupCard(data, isNew, "IdleState");
SetupCard(data, "IdleState");
SetDraggingEnabled(false); // Booster cards cannot be dragged
}
@@ -115,7 +127,7 @@ namespace UI.CardSystem.StateMachine
/// </summary>
public void SetupForAlbumPlacement(CardData data)
{
SetupCard(data, false, "RevealedState");
SetupCard(data, "RevealedState");
SetDraggingEnabled(true); // Album placement cards can be dragged
}
@@ -125,7 +137,7 @@ namespace UI.CardSystem.StateMachine
/// </summary>
public void SetupForAlbumSlot(CardData data, AlbumCardSlot slot)
{
SetupCard(data, false, "PlacedInSlotState");
SetupCard(data, "PlacedInSlotState");
SetDraggingEnabled(false); // Cards in slots cannot be dragged out
// Set the parent slot on the PlacedInSlotState
@@ -176,4 +188,3 @@ namespace UI.CardSystem.StateMachine
}
}
}

View File

@@ -27,21 +27,29 @@ namespace UI.CardSystem.StateMachine
public CardData CardData => cardData;
// Runtime state
public bool IsNewCard { get; set; }
public int RepeatCardCount { get; set; }
public bool IsClickable { get; set; } = true;
public bool SuppressRevealBadges { get; set; } = false; // Set by states to suppress NEW/REPEAT badges in revealed state
// Events for external coordination (BoosterOpeningPage, etc.)
public event Action<CardContext> OnFlipComplete;
public event Action<CardContext> OnCardDismissed;
public event Action<CardContext> OnCardInteractionComplete;
public event Action<CardContext> OnUpgradeTriggered;
// Original transform data (captured on spawn for shrink animations)
public Vector3 OriginalScale { get; private set; }
public Vector3 OriginalPosition { get; private set; }
public Quaternion OriginalRotation { get; private set; }
// Helper methods for states
public void FireFlipComplete() => OnFlipComplete?.Invoke(this);
public void FireCardDismissed() => OnCardDismissed?.Invoke(this);
public void FireCardInteractionComplete() => OnCardInteractionComplete?.Invoke(this);
public void FireUpgradeTriggered() => OnUpgradeTriggered?.Invoke(this);
// Single event for reveal flow completion
public event Action<CardContext> OnRevealFlowComplete;
private bool _hasCompletedReveal = false;
public bool HasCompletedReveal => _hasCompletedReveal;
// Helper method for states to signal completion
public void NotifyRevealComplete()
{
if (!_hasCompletedReveal)
{
_hasCompletedReveal = true;
OnRevealFlowComplete?.Invoke(this);
}
}
private void Awake()
{
@@ -55,15 +63,58 @@ namespace UI.CardSystem.StateMachine
if (stateMachine == null)
stateMachine = GetComponentInChildren<AppleMachine>();
}
private void OnEnable()
{
// Subscribe to CardDisplay click and route to active state
if (cardDisplay != null)
{
cardDisplay.OnCardClicked += HandleCardDisplayClicked;
}
}
private void OnDisable()
{
if (cardDisplay != null)
{
cardDisplay.OnCardClicked -= HandleCardDisplayClicked;
}
}
private void HandleCardDisplayClicked(CardDisplay _)
{
// Gate by clickability
if (!IsClickable) return;
if (stateMachine == null || stateMachine.currentState == null) return;
var handler = stateMachine.currentState.GetComponent<ICardClickHandler>();
if (handler != null)
{
handler.OnCardClicked(this);
}
}
/// <summary>
/// Setup the card with data
/// </summary>
public void SetupCard(CardData data, bool isNew = false, int repeatCount = 0)
public void SetupCard(CardData data)
{
cardData = data;
IsNewCard = isNew;
RepeatCardCount = repeatCount;
_hasCompletedReveal = false; // Reset completion flag
// Capture original transform for shrink animations.
// If current scale is ~0 (pop-in staging), default to Vector3.one.
var currentScale = transform.localScale;
if (currentScale.x < 0.01f && currentScale.y < 0.01f && currentScale.z < 0.01f)
{
OriginalScale = Vector3.one;
}
else
{
OriginalScale = currentScale;
}
OriginalPosition = transform.localPosition;
OriginalRotation = transform.localRotation;
if (cardDisplay != null)
{
@@ -77,4 +128,3 @@ namespace UI.CardSystem.StateMachine
public CardDisplay GetCardDisplay() => cardDisplay;
}
}

View File

@@ -0,0 +1,11 @@
namespace UI.CardSystem.StateMachine
{
/// <summary>
/// Implement on a state component to receive routed click events
/// from CardContext/CardDisplay.
/// </summary>
public interface ICardClickHandler
{
void OnCardClicked(CardContext context);
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fadf99afe6cc4785a6f45a47b4463923
timeCreated: 1763307472

View File

@@ -1,7 +1,6 @@
using Core;
using Core.SaveLoad;
using UnityEngine;
using UnityEngine.EventSystems;
using AppleHills.Core.Settings;
namespace UI.CardSystem.StateMachine.States
@@ -10,7 +9,7 @@ namespace UI.CardSystem.StateMachine.States
/// Album enlarged state - card is enlarged when clicked from album slot.
/// Different from EnlargedNewState as it doesn't show "NEW" badge.
/// </summary>
public class CardAlbumEnlargedState : AppleState, IPointerClickHandler
public class CardAlbumEnlargedState : AppleState, ICardClickHandler
{
private CardContext _context;
private ICardSystemSettings _settings;
@@ -56,7 +55,7 @@ namespace UI.CardSystem.StateMachine.States
Logging.Debug($"[CardAlbumEnlargedState] Card enlarged from album: {_context.CardData?.Name}");
}
public void OnPointerClick(PointerEventData eventData)
public void OnCardClicked(CardContext context)
{
// Click to shrink back
Logging.Debug($"[CardAlbumEnlargedState] Card clicked while enlarged, shrinking back");
@@ -65,13 +64,17 @@ namespace UI.CardSystem.StateMachine.States
OnShrinkRequested?.Invoke(this);
// Shrink animation, then transition back
if (_context.Animator != null)
if (context.Animator != null)
{
_context.Animator.PlayShrink(_originalScale, onComplete: () =>
context.Animator.PlayShrink(_originalScale, onComplete: () =>
{
_context.StateMachine.ChangeState("PlacedInSlotState");
context.StateMachine.ChangeState("PlacedInSlotState");
});
}
else
{
context.StateMachine.ChangeState("PlacedInSlotState");
}
}
/// <summary>

View File

@@ -0,0 +1,53 @@
// filepath: Assets/Scripts/UI/CardSystem/StateMachine/States/CardEnlargedLegendaryRepeatState.cs
using Core;
using Core.SaveLoad;
using UnityEngine;
using AppleHills.Core.Settings;
namespace UI.CardSystem.StateMachine.States
{
/// <summary>
/// Enlarged state specifically for Legendary rarity presentation after an upgrade.
/// Shows the legendary card enlarged and awaits a click to shrink back to revealed state.
/// </summary>
public class CardEnlargedLegendaryRepeatState : AppleState, ICardClickHandler
{
private CardContext _context;
private void Awake()
{
_context = GetComponentInParent<CardContext>();
}
public override void OnEnterState()
{
// Ensure card front is visible and facing camera
if (_context.CardDisplay != null)
{
_context.CardDisplay.gameObject.SetActive(true);
_context.CardDisplay.transform.localRotation = Quaternion.Euler(0, 0, 0);
}
// Card is already enlarged from EnlargedRepeatState, so no need to enlarge again
// Just await click to dismiss
Logging.Debug($"[CardEnlargedLegendaryRepeatState] Legendary card enlarged: {_context.CardData?.Name}");
}
public void OnCardClicked(CardContext context)
{
// Click to shrink to original scale and go to revealed state
if (context.Animator != null)
{
context.Animator.PlayShrink(context.OriginalScale, onComplete: () =>
{
context.StateMachine.ChangeState("RevealedState");
});
}
else
{
context.StateMachine.ChangeState("RevealedState");
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 874e5574663a48b8a4feb3192821679a
timeCreated: 1763319614

View File

@@ -1,6 +1,5 @@
using Core.SaveLoad;
using UnityEngine;
using UnityEngine.EventSystems;
using AppleHills.Core.Settings;
using Core;
@@ -10,14 +9,13 @@ namespace UI.CardSystem.StateMachine.States
/// Enlarged state for NEW cards - shows "NEW CARD" badge and waits for tap to dismiss.
/// Owns the NewCardBadge as a child GameObject.
/// </summary>
public class CardEnlargedNewState : AppleState, IPointerClickHandler
public class CardEnlargedNewState : AppleState, ICardClickHandler
{
[Header("State-Owned Visuals")]
[SerializeField] private GameObject newCardBadge;
private CardContext _context;
private ICardSystemSettings _settings;
private Vector3 _originalScale;
private void Awake()
{
@@ -34,39 +32,39 @@ namespace UI.CardSystem.StateMachine.States
_context.CardDisplay.transform.localRotation = Quaternion.Euler(0, 0, 0);
}
// Store original scale
_originalScale = _context.RootTransform.localScale;
// Check if we're already enlarged (coming from upgrade flow)
bool alreadyEnlarged = _context.RootTransform.localScale.x >= _settings.NewCardEnlargedScale * 0.9f;
if (!alreadyEnlarged)
{
// Normal flow - enlarge the card
if (_context.Animator != null)
{
_context.Animator.PlayEnlarge(_settings.NewCardEnlargedScale);
}
}
// Show NEW badge
if (newCardBadge != null)
{
newCardBadge.SetActive(true);
}
// Enlarge the card
if (_context.Animator != null)
{
_context.Animator.PlayEnlarge(_settings.NewCardEnlargedScale);
}
}
public void OnPointerClick(PointerEventData eventData)
public void OnCardClicked(CardContext context)
{
// Fire dismissed event
_context.FireCardDismissed();
// Tap to dismiss - shrink back and transition to revealed state
if (_context.Animator != null)
// Tap to dismiss - shrink back to original scale and transition to revealed state
if (context.Animator != null)
{
_context.Animator.PlayShrink(_originalScale, onComplete: () =>
context.Animator.PlayShrink(context.OriginalScale, onComplete: () =>
{
_context.StateMachine.ChangeState("RevealedState");
context.StateMachine.ChangeState("RevealedState");
});
}
else
{
// Fallback if no animator
_context.StateMachine.ChangeState("RevealedState");
context.StateMachine.ChangeState("RevealedState");
}
}
@@ -80,4 +78,3 @@ namespace UI.CardSystem.StateMachine.States
}
}
}

View File

@@ -1,6 +1,5 @@
using Core.SaveLoad;
using UnityEngine;
using UnityEngine.EventSystems;
using AppleHills.Core.Settings;
using Core;
using AppleHills.Data.CardSystem;
@@ -12,14 +11,13 @@ namespace UI.CardSystem.StateMachine.States
/// Uses ProgressBarController to animate progress filling.
/// Auto-upgrades card when threshold is reached.
/// </summary>
public class CardEnlargedRepeatState : AppleState, IPointerClickHandler
public class CardEnlargedRepeatState : AppleState, ICardClickHandler
{
[Header("State-Owned Visuals")]
[SerializeField] private ProgressBarController progressBar;
private CardContext _context;
private ICardSystemSettings _settings;
private Vector3 _originalScale;
private bool _waitingForTap = false;
private void Awake()
@@ -37,16 +35,18 @@ namespace UI.CardSystem.StateMachine.States
_context.CardDisplay.transform.localRotation = Quaternion.Euler(0, 0, 0);
}
// Store original scale
_originalScale = _context.RootTransform.localScale;
_waitingForTap = false;
// Query current collection state for this card
bool isNew = Data.CardSystem.CardSystemManager.Instance.IsCardNew(_context.CardData, out CardData existingCard);
int currentOwnedCount = (existingCard != null) ? existingCard.CopiesOwned : 0;
// Show progress bar
if (progressBar != null)
{
progressBar.gameObject.SetActive(true);
int currentCount = _context.RepeatCardCount + 1; // +1 because we just got this card
int currentCount = currentOwnedCount + 1; // +1 because we just got this card
int maxCount = _settings.CardsToUpgrade;
progressBar.ShowProgress(currentCount, maxCount, OnProgressComplete);
@@ -66,111 +66,114 @@ namespace UI.CardSystem.StateMachine.States
private void OnProgressComplete()
{
// Check if this card triggers an upgrade
if (ShouldTriggerUpgrade())
// Query current state again to determine if upgrade is triggered
Data.CardSystem.CardSystemManager.Instance.IsCardNew(_context.CardData, out CardData existingCard);
int currentOwnedCount = (existingCard != null) ? existingCard.CopiesOwned : 0;
int countWithThisCard = currentOwnedCount + 1;
bool willUpgrade = (_context.CardData.Rarity < AppleHills.Data.CardSystem.CardRarity.Legendary) &&
(countWithThisCard >= _settings.CardsToUpgrade);
if (willUpgrade)
{
Logging.Debug($"[CardEnlargedRepeatState] Card will trigger upgrade! ({_context.RepeatCardCount + 1}/{_settings.CardsToUpgrade})");
Logging.Debug($"[CardEnlargedRepeatState] Card will trigger upgrade! ({countWithThisCard}/{_settings.CardsToUpgrade})");
TriggerUpgrade();
}
else
{
// No upgrade - just wait for tap to dismiss
Logging.Debug($"[CardEnlargedRepeatState] Progress shown, waiting for tap to dismiss");
Logging.Debug($"[CardEnlargedRepeatState] Progress shown ({countWithThisCard}/{_settings.CardsToUpgrade}), waiting for tap to dismiss");
_waitingForTap = true;
}
}
private bool ShouldTriggerUpgrade()
{
int currentCount = _context.RepeatCardCount + 1; // +1 for the card we just got
CardRarity currentRarity = _context.CardData.Rarity;
// Can't upgrade if already Legendary
if (currentRarity == CardRarity.Legendary)
return false;
// Check if we've hit the threshold
return currentCount >= _settings.CardsToUpgrade;
}
private void TriggerUpgrade()
{
_context.FireUpgradeTriggered();
CardData cardData = _context.CardData;
CardRarity oldRarity = cardData.Rarity;
CardRarity newRarity = oldRarity + 1;
Logging.Debug($"[CardEnlargedRepeatState] Upgrading card from {oldRarity} to {newRarity}");
var inventory = Data.CardSystem.CardSystemManager.Instance.GetCardInventory();
// Get the existing card at lower rarity from inventory
CardData existingLowerRarity = Data.CardSystem.CardSystemManager.Instance.GetCardInventory().GetCard(cardData.Name, oldRarity);
if (existingLowerRarity != null)
// Remove lower rarity card counts (set to 1 per new rule instead of zeroing out)
CardRarity clearRarity = cardData.Rarity;
while (clearRarity < newRarity)
{
// Reset lower rarity count to 0
existingLowerRarity.CopiesOwned = 0;
var lower = inventory.GetCard(cardData.DefinitionId, clearRarity);
if (lower != null) lower.CopiesOwned = 1; // changed from 0 to 1
clearRarity += 1;
}
// Create upgraded card data
CardData upgradedCard = new CardData(cardData);
upgradedCard.Rarity = newRarity;
upgradedCard.CopiesOwned = 1;
// Check if higher rarity already exists BEFORE adding
CardData existingHigher = inventory.GetCard(cardData.DefinitionId, newRarity);
bool higherExists = existingHigher != null;
// Check if this card is new at the higher rarity
bool isNewAtHigherRarity = Data.CardSystem.CardSystemManager.Instance.IsCardNew(upgradedCard, out CardData existingHigherRarity);
// Add to inventory
Data.CardSystem.CardSystemManager.Instance.GetCardInventory().AddCard(upgradedCard);
// Update our card data to show upgraded rarity
cardData.Rarity = newRarity;
// Update the CardDisplay to show new rarity
if (_context.CardDisplay != null)
if (higherExists)
{
_context.CardDisplay.SetupCard(cardData);
}
// Determine next transition
if (isNewAtHigherRarity || newRarity == CardRarity.Legendary)
{
// Show as NEW at higher rarity
Logging.Debug($"[CardEnlargedRepeatState] Card is NEW at {newRarity}, transitioning to EnlargedNewState");
TransitionToNewCardView();
}
else
{
// Already have copies at higher rarity - show progress there too
int ownedAtHigherRarity = existingHigherRarity.CopiesOwned;
Logging.Debug($"[CardEnlargedRepeatState] Card is REPEAT at {newRarity} ({ownedAtHigherRarity}/{_settings.CardsToUpgrade}), showing progress");
// Update context for higher rarity
_context.IsNewCard = false;
_context.RepeatCardCount = ownedAtHigherRarity;
// Re-enter this state with updated data (will show progress for higher rarity)
// First hide current progress, then show new progress
// Increment existing higher rarity copies
existingHigher.CopiesOwned += 1;
// Update our displayed card to new rarity
cardData.Rarity = newRarity;
cardData.CopiesOwned = existingHigher.CopiesOwned; // reflect correct count
if (_context.CardDisplay != null)
{
_context.CardDisplay.SetupCard(cardData);
}
// For repeat-at-higher-rarity: show a brief progress update at higher rarity while enlarged
int ownedAtHigher = existingHigher.CopiesOwned;
if (progressBar != null)
{
progressBar.ShowProgress(ownedAtHigherRarity + 1, _settings.CardsToUpgrade, () =>
progressBar.ShowProgress(ownedAtHigher, _settings.CardsToUpgrade, () =>
{
// After showing progress at higher rarity, transition to NEW
TransitionToNewCardView();
// After showing higher-rarity progress, wait for tap to dismiss
_waitingForTap = true;
});
}
else
{
TransitionToNewCardView();
_waitingForTap = true;
}
}
else
{
// Create upgraded card as new rarity
CardData upgradedCard = new CardData(cardData);
upgradedCard.Rarity = newRarity;
upgradedCard.CopiesOwned = 1;
// Add to inventory
inventory.AddCard(upgradedCard);
// Update current display card to new rarity
cardData.Rarity = newRarity;
cardData.CopiesOwned = upgradedCard.CopiesOwned;
if (_context.CardDisplay != null)
{
_context.CardDisplay.SetupCard(cardData);
}
// Branch based on whether legendary or not
if (newRarity == CardRarity.Legendary)
{
// Show special enlarged legendary presentation, await click to shrink to revealed
_context.StateMachine.ChangeState("EnlargedLegendaryRepeatState");
}
else
{
// Treat as NEW at higher rarity (enlarged with NEW visuals handled there)
_context.StateMachine.ChangeState("EnlargedNewState");
}
}
}
private void TransitionToNewCardView()
{
// Update context to show as new card
_context.IsNewCard = true;
// Hide progress bar before transitioning
if (progressBar != null)
{
@@ -178,29 +181,27 @@ namespace UI.CardSystem.StateMachine.States
}
// Transition to EnlargedNewState (card is already enlarged, will show NEW badge)
// State will query fresh collection data to determine if truly new
_context.StateMachine.ChangeState("EnlargedNewState");
}
public void OnPointerClick(PointerEventData eventData)
public void OnCardClicked(CardContext context)
{
// Only respond to clicks if waiting for tap
if (!_waitingForTap)
return;
// Fire dismissed event
_context.FireCardDismissed();
// Tap to dismiss - shrink back and transition to revealed state
if (_context.Animator != null)
// Tap to dismiss - shrink back to original scale and transition to revealed state
if (context.Animator != null)
{
_context.Animator.PlayShrink(_originalScale, onComplete: () =>
context.Animator.PlayShrink(context.OriginalScale, onComplete: () =>
{
_context.StateMachine.ChangeState("RevealedState");
context.StateMachine.ChangeState("RevealedState");
});
}
else
{
_context.StateMachine.ChangeState("RevealedState");
context.StateMachine.ChangeState("RevealedState");
}
}
@@ -214,4 +215,3 @@ namespace UI.CardSystem.StateMachine.States
}
}
}

View File

@@ -3,6 +3,7 @@ using Pixelplacement.TweenSystem;
using UnityEngine;
using UnityEngine.EventSystems;
using AppleHills.Core.Settings;
using AppleHills.Data.CardSystem;
using Core;
namespace UI.CardSystem.StateMachine.States
@@ -12,7 +13,7 @@ namespace UI.CardSystem.StateMachine.States
/// Waiting for click to flip and reveal.
/// Based on FlippableCard's idle behavior.
/// </summary>
public class CardIdleState : AppleState, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
public class CardIdleState : AppleState, ICardClickHandler, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
{
[Header("State-Owned Visuals")]
[SerializeField] private GameObject cardBackVisual;
@@ -80,10 +81,10 @@ namespace UI.CardSystem.StateMachine.States
}
}
public void OnPointerClick(PointerEventData eventData)
public void OnCardClicked(CardContext context)
{
// Check if card is clickable (prevents multi-flip in booster opening)
if (!_context.IsClickable)
if (!context.IsClickable)
{
Logging.Debug($"[CardIdleState] Card is not clickable, ignoring click");
return;
@@ -92,27 +93,34 @@ namespace UI.CardSystem.StateMachine.States
// Stop idle hover and pointer interactions
StopIdleHover();
// Play flip animation directly (no state transition yet)
if (_context.Animator != null)
// Play flip animation directly
if (context.Animator != null)
{
_context.Animator.PlayFlip(
context.Animator.PlayFlip(
cardBack: cardBackVisual != null ? cardBackVisual.transform : null,
cardFront: _context.CardDisplay != null ? _context.CardDisplay.transform : null,
cardFront: context.CardDisplay != null ? context.CardDisplay.transform : null,
onComplete: OnFlipComplete
);
_context.Animator.PlayFlipScalePunch();
context.Animator.PlayFlipScalePunch();
}
}
public void OnPointerClick(PointerEventData eventData)
{
// Forward to same logic as routed click to keep behavior unified
OnCardClicked(_context);
}
private void OnFlipComplete()
{
// Fire flip complete event
_context.FireFlipComplete();
// Query current collection state from CardSystemManager (don't use cached values)
bool isNew = Data.CardSystem.CardSystemManager.Instance.IsCardNew(_context.CardData, out CardData existingCard);
// Transition based on whether this is a new card or repeat
if (_context.IsNewCard)
if (isNew)
{
// New card - show "NEW" badge and enlarge
_context.StateMachine.ChangeState("EnlargedNewState");
}
else if (_context.CardData != null && _context.CardData.Rarity == AppleHills.Data.CardSystem.CardRarity.Legendary)
@@ -125,13 +133,10 @@ namespace UI.CardSystem.StateMachine.States
}
_context.StateMachine.ChangeState("RevealedState");
}
else if (_context.RepeatCardCount > 0)
{
_context.StateMachine.ChangeState("EnlargedRepeatState");
}
else
{
_context.StateMachine.ChangeState("RevealedState");
// Repeat card - show progress toward upgrade
_context.StateMachine.ChangeState("EnlargedRepeatState");
}
}
@@ -170,4 +175,3 @@ namespace UI.CardSystem.StateMachine.States
}
}
}

View File

@@ -1,7 +1,6 @@
using Core;
using Core.SaveLoad;
using UnityEngine;
using UnityEngine.EventSystems;
namespace UI.CardSystem.StateMachine.States
{
@@ -9,7 +8,7 @@ namespace UI.CardSystem.StateMachine.States
/// Placed in slot state - card is in an album slot and can be clicked to enlarge.
/// Manages the parent slot reference.
/// </summary>
public class CardPlacedInSlotState : AppleState, IPointerClickHandler
public class CardPlacedInSlotState : AppleState, ICardClickHandler
{
private CardContext _context;
private AlbumCardSlot _parentSlot;
@@ -51,11 +50,11 @@ namespace UI.CardSystem.StateMachine.States
return _parentSlot;
}
public void OnPointerClick(PointerEventData eventData)
public void OnCardClicked(CardContext context)
{
// Click to enlarge when in album
Logging.Debug($"[CardPlacedInSlotState] Card clicked in slot, transitioning to enlarged state");
_context.StateMachine.ChangeState("AlbumEnlargedState");
context.StateMachine.ChangeState("AlbumEnlargedState");
}
}
}

View File

@@ -1,4 +1,5 @@
using Core.SaveLoad;
using AppleHills.Data.CardSystem;
using Core.SaveLoad;
using UnityEngine;
namespace UI.CardSystem.StateMachine.States
@@ -32,34 +33,35 @@ namespace UI.CardSystem.StateMachine.States
_context.CardDisplay.transform.localRotation = Quaternion.Euler(0, 0, 0);
}
// Card is at normal size, fully revealed
// Show appropriate idle badge
if (_context.IsNewCard)
// Show appropriate idle badge unless suppressed
if (_context.SuppressRevealBadges)
{
if (newCardIdleBadge != null)
newCardIdleBadge.SetActive(true);
if (repeatCardIdleBadge != null)
repeatCardIdleBadge.SetActive(false);
}
else if (_context.RepeatCardCount > 0)
{
if (newCardIdleBadge != null)
newCardIdleBadge.SetActive(false);
if (repeatCardIdleBadge != null)
repeatCardIdleBadge.SetActive(true);
if (newCardIdleBadge != null) newCardIdleBadge.SetActive(false);
if (repeatCardIdleBadge != null) repeatCardIdleBadge.SetActive(false);
}
else
{
// Neither new nor repeat - hide both
if (newCardIdleBadge != null)
newCardIdleBadge.SetActive(false);
if (repeatCardIdleBadge != null)
repeatCardIdleBadge.SetActive(false);
bool isNew = Data.CardSystem.CardSystemManager.Instance.IsCardNew(_context.CardData, out CardData existingCard);
int currentOwnedCount = (existingCard != null) ? existingCard.CopiesOwned : 0;
if (isNew)
{
if (newCardIdleBadge != null) newCardIdleBadge.SetActive(true);
if (repeatCardIdleBadge != null) repeatCardIdleBadge.SetActive(false);
}
else if (currentOwnedCount > 0)
{
if (newCardIdleBadge != null) newCardIdleBadge.SetActive(false);
if (repeatCardIdleBadge != null) repeatCardIdleBadge.SetActive(true);
}
else
{
if (newCardIdleBadge != null) newCardIdleBadge.SetActive(false);
if (repeatCardIdleBadge != null) repeatCardIdleBadge.SetActive(false);
}
}
// Fire interaction complete event (for BoosterOpeningPage tracking)
_context.FireCardInteractionComplete();
// Fire reveal flow complete event (signals booster page that this card is done)
_context.NotifyRevealComplete();
}
private void OnDisable()
@@ -72,4 +74,3 @@ namespace UI.CardSystem.StateMachine.States
}
}
}

View File

@@ -51,13 +51,10 @@ namespace UI.CardSystem.Testing
_originalAnchoredPosition = rectTransform.anchoredPosition;
}
// Subscribe to all card events
// Subscribe to card events (new simplified event model)
if (_cardContext != null)
{
_cardContext.OnFlipComplete += OnCardFlipComplete;
_cardContext.OnCardDismissed += OnCardDismissed;
_cardContext.OnCardInteractionComplete += OnCardInteractionComplete;
_cardContext.OnUpgradeTriggered += OnCardUpgradeTriggered;
_cardContext.OnRevealFlowComplete += OnCardRevealFlowComplete;
}
// Subscribe to drag events to ensure card snaps back when released
@@ -89,7 +86,7 @@ namespace UI.CardSystem.Testing
// Initialize card with test data
if (testCard != null && testCardData != null && _cardContext != null)
{
_cardContext.SetupCard(testCardData, isNew: true, repeatCount: 0);
_cardContext.SetupCard(testCardData);
}
LogEvent("Card Test Scene Initialized");
@@ -185,37 +182,37 @@ namespace UI.CardSystem.Testing
{
if (_cardContext == null) return;
_cardContext.IsNewCard = true;
_cardContext.RepeatCardCount = 0;
// NOTE: These properties no longer exist in CardContext (removed to prevent stale data)
// States now query CardSystemManager directly
// This test controller manually manipulates state machine for testing only
_cardContext.IsClickable = true;
TransitionToIdleState();
LogEvent("Simulating NEW CARD flow - click card to flip");
LogEvent("Simulating NEW CARD flow - click card to flip (test bypasses collection checks)");
}
public void SimulateRepeatCardFlow()
{
if (_cardContext == null) return;
int repeatCount = Mathf.RoundToInt(repeatCountSlider.value);
_cardContext.IsNewCard = false;
_cardContext.RepeatCardCount = repeatCount;
// NOTE: RepeatCardCount removed from CardContext
// Test directly transitions to state for visual testing
_cardContext.IsClickable = true;
TransitionToIdleState();
LogEvent($"Simulating REPEAT CARD flow ({repeatCount}/5) - click card to flip");
LogEvent($"Simulating REPEAT CARD flow (test bypasses collection checks)");
}
public void SimulateUpgradeFlow()
{
if (_cardContext == null) return;
_cardContext.IsNewCard = false;
_cardContext.RepeatCardCount = 5; // Trigger upgrade
// NOTE: WillTriggerUpgrade removed from CardContext
// Test directly transitions to state for visual testing
_cardContext.IsClickable = true;
TransitionToIdleState();
LogEvent("Simulating UPGRADE flow (5/5) - click card to flip and auto-upgrade");
LogEvent("Simulating UPGRADE flow (test bypasses collection checks)");
}
public void TestDragAndSnap()
@@ -240,9 +237,6 @@ namespace UI.CardSystem.Testing
bool isNew = isNewToggle != null && isNewToggle.isOn;
int repeatCount = repeatCountSlider != null ? Mathf.RoundToInt(repeatCountSlider.value) : 0;
_cardContext.IsNewCard = isNew;
_cardContext.RepeatCardCount = repeatCount;
// Apply rarity if needed
if (rarityDropdown != null && testCardData != null)
{
@@ -364,24 +358,9 @@ namespace UI.CardSystem.Testing
#region Event Handlers
private void OnCardFlipComplete(CardContext context)
private void OnCardRevealFlowComplete(CardContext context)
{
LogEvent($"Event: OnFlipComplete - IsNew={context.IsNewCard}, RepeatCount={context.RepeatCardCount}");
}
private void OnCardDismissed(CardContext context)
{
LogEvent("Event: OnCardDismissed");
}
private void OnCardInteractionComplete(CardContext context)
{
LogEvent("Event: OnCardInteractionComplete");
}
private void OnCardUpgradeTriggered(CardContext context)
{
LogEvent($"Event: OnUpgradeTriggered - New Rarity={context.CardData?.Rarity}");
LogEvent($"Event: OnRevealFlowComplete - Card reveal complete for {context.CardData?.Name}");
}
private void OnCardDragStarted(UI.DragAndDrop.Core.DraggableObject draggable)
@@ -459,10 +438,7 @@ namespace UI.CardSystem.Testing
// Unsubscribe from events
if (_cardContext != null)
{
_cardContext.OnFlipComplete -= OnCardFlipComplete;
_cardContext.OnCardDismissed -= OnCardDismissed;
_cardContext.OnCardInteractionComplete -= OnCardInteractionComplete;
_cardContext.OnUpgradeTriggered -= OnCardUpgradeTriggered;
_cardContext.OnRevealFlowComplete -= OnCardRevealFlowComplete;
}
if (testCard != null)