Working card dragging into album slots, persistent slots
This commit is contained in:
@@ -27,14 +27,18 @@ namespace UI.CardSystem
|
||||
|
||||
[Header("Album Card Reveal")]
|
||||
[SerializeField] private SlotContainer bottomRightSlots;
|
||||
[SerializeField] private GameObject albumCardPrefab;
|
||||
[SerializeField] private GameObject albumCardPlacementPrefab; // The wrapper prefab with flip/drag (AlbumPlacementCard)
|
||||
|
||||
[Header("Card Enlarge System")]
|
||||
[SerializeField] private GameObject cardEnlargedBackdrop; // Backdrop to block interactions
|
||||
[SerializeField] private Transform cardEnlargedContainer; // Container for enlarged cards (sits above backdrop)
|
||||
|
||||
[Header("Booster Pack UI")]
|
||||
[SerializeField] private GameObject[] boosterPackButtons;
|
||||
[SerializeField] private BoosterOpeningPage boosterOpeningPage;
|
||||
|
||||
private Input.InputMode _previousInputMode;
|
||||
private List<AlbumCardDraggable> _activeCards = new List<AlbumCardDraggable>();
|
||||
private List<AlbumCardPlacementDraggable> _activeCards = new List<AlbumCardPlacementDraggable>();
|
||||
private const int MAX_VISIBLE_CARDS = 3;
|
||||
|
||||
private void Awake()
|
||||
@@ -45,6 +49,12 @@ namespace UI.CardSystem
|
||||
if (canvasGroup == null)
|
||||
canvasGroup = gameObject.AddComponent<CanvasGroup>();
|
||||
|
||||
// Hide backdrop initially
|
||||
if (cardEnlargedBackdrop != null)
|
||||
{
|
||||
cardEnlargedBackdrop.SetActive(false);
|
||||
}
|
||||
|
||||
// Set up exit button
|
||||
if (exitButton != null)
|
||||
{
|
||||
@@ -242,6 +252,9 @@ namespace UI.CardSystem
|
||||
|
||||
protected override void DoTransitionOut(System.Action onComplete)
|
||||
{
|
||||
// Clean up any enlarged card state before closing
|
||||
CleanupEnlargedCardState();
|
||||
|
||||
// Simple fade out animation
|
||||
if (canvasGroup != null)
|
||||
{
|
||||
@@ -254,6 +267,43 @@ namespace UI.CardSystem
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clean up enlarged card state when closing the album
|
||||
/// </summary>
|
||||
private void CleanupEnlargedCardState()
|
||||
{
|
||||
// Hide backdrop if visible
|
||||
if (cardEnlargedBackdrop != null && cardEnlargedBackdrop.activeSelf)
|
||||
{
|
||||
cardEnlargedBackdrop.SetActive(false);
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
// Force reset state and return to slot
|
||||
Transform originalParent = albumCard.GetOriginalParent();
|
||||
if (originalParent != null)
|
||||
{
|
||||
cardTransform.SetParent(originalParent, true);
|
||||
cardTransform.localPosition = albumCard.GetOriginalLocalPosition();
|
||||
cardTransform.localRotation = albumCard.GetOriginalLocalRotation();
|
||||
}
|
||||
|
||||
albumCard.ForceResetEnlargedState();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region Album Card Reveal System
|
||||
|
||||
/// <summary>
|
||||
@@ -262,7 +312,7 @@ namespace UI.CardSystem
|
||||
/// </summary>
|
||||
private void SpawnPendingCards()
|
||||
{
|
||||
if (CardSystemManager.Instance == null || bottomRightSlots == null || albumCardPrefab == null)
|
||||
if (CardSystemManager.Instance == null || bottomRightSlots == null || albumCardPlacementPrefab == null)
|
||||
return;
|
||||
|
||||
var pending = CardSystemManager.Instance.GetPendingRevealCards();
|
||||
@@ -306,26 +356,26 @@ namespace UI.CardSystem
|
||||
|
||||
// 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(albumCardPrefab, bottomRightSlots.transform);
|
||||
AlbumCardDraggable card = cardObj.GetComponent<AlbumCardDraggable>();
|
||||
GameObject cardObj = Instantiate(albumCardPlacementPrefab, bottomRightSlots.transform);
|
||||
AlbumCardPlacementDraggable cardPlacement = cardObj.GetComponent<AlbumCardPlacementDraggable>();
|
||||
|
||||
if (card != null)
|
||||
if (cardPlacement != null)
|
||||
{
|
||||
// Setup card data
|
||||
card.SetupCard(cardData);
|
||||
cardPlacement.SetupCard(cardData);
|
||||
|
||||
// Subscribe to events
|
||||
card.OnCardRevealed += OnCardRevealed;
|
||||
card.OnCardPlacedInAlbum += OnCardPlacedInAlbum;
|
||||
cardPlacement.OnCardRevealed += OnCardRevealed;
|
||||
cardPlacement.OnCardPlacedInAlbum += OnCardPlacedInAlbum;
|
||||
|
||||
// NOW assign to slot - this will:
|
||||
// 1. Reparent to slot
|
||||
// 2. Apply slot's occupantSizeMode scaling
|
||||
// 3. Animate to slot position
|
||||
card.AssignToSlot(slot, true);
|
||||
cardPlacement.AssignToSlot(slot, true);
|
||||
|
||||
// Track it
|
||||
_activeCards.Add(card);
|
||||
_activeCards.Add(cardPlacement);
|
||||
|
||||
Debug.Log($"[AlbumViewPage] Spawned card '{cardData.Name}' (CopiesOwned: {cardData.CopiesOwned}) in slot {slotIndex}");
|
||||
}
|
||||
@@ -371,7 +421,7 @@ namespace UI.CardSystem
|
||||
/// <summary>
|
||||
/// Handle when a card is revealed (flipped)
|
||||
/// </summary>
|
||||
private void OnCardRevealed(AlbumCardDraggable card, CardData cardData)
|
||||
private void OnCardRevealed(AlbumCardPlacementDraggable cardPlacement, CardData cardData)
|
||||
{
|
||||
Debug.Log($"[AlbumViewPage] Card revealed: {cardData.Name} (Zone: {cardData.Zone}, CopiesOwned: {cardData.CopiesOwned})");
|
||||
|
||||
@@ -383,7 +433,7 @@ namespace UI.CardSystem
|
||||
}
|
||||
|
||||
// Remove this card from active cards list
|
||||
_activeCards.Remove(card);
|
||||
_activeCards.Remove(cardPlacement);
|
||||
|
||||
// Check if we're currently viewing the correct zone for this card
|
||||
CardZone currentZone = GetCurrentZone();
|
||||
@@ -409,13 +459,13 @@ namespace UI.CardSystem
|
||||
/// Card data already moved to inventory in OnCardRevealed
|
||||
/// This just handles cleanup
|
||||
/// </summary>
|
||||
private void OnCardPlacedInAlbum(AlbumCardDraggable card, CardData cardData)
|
||||
private void OnCardPlacedInAlbum(AlbumCardPlacementDraggable cardPlacement, CardData cardData)
|
||||
{
|
||||
Debug.Log($"[AlbumViewPage] Card placed in album slot: {cardData.Name}");
|
||||
|
||||
// Unsubscribe from events (card is now static in album)
|
||||
card.OnCardRevealed -= OnCardRevealed;
|
||||
card.OnCardPlacedInAlbum -= OnCardPlacedInAlbum;
|
||||
cardPlacement.OnCardRevealed -= OnCardRevealed;
|
||||
cardPlacement.OnCardPlacedInAlbum -= OnCardPlacedInAlbum;
|
||||
|
||||
// Note: Card already removed from _activeCards in OnCardRevealed
|
||||
// Note: Shuffle and spawn already done in OnCardRevealed
|
||||
@@ -560,5 +610,91 @@ namespace UI.CardSystem
|
||||
}
|
||||
|
||||
#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;
|
||||
|
||||
Debug.Log($"[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);
|
||||
Debug.Log($"[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
|
||||
Debug.Log($"[AlbumViewPage] Card reparented to enlarged container");
|
||||
}
|
||||
|
||||
Debug.Log($"[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();
|
||||
}
|
||||
|
||||
Debug.Log($"[AlbumViewPage] Card shrunk: {card.GetCardData()?.Name}");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user