Working card system

This commit is contained in:
Michal Adam Pikulski
2025-10-20 16:33:18 +02:00
parent 83b5c8994d
commit 3e833b8991
18 changed files with 485 additions and 339 deletions

View File

@@ -497,20 +497,38 @@ namespace AppleHills.UI.CardSystem
/// </summary>
private IEnumerator MoveCardsToBackpack()
{
// Find the backpack icon position if available
// Find the backpack button GameObject
GameObject backpackButton = null;
Transform backpackTransform = null;
if (_cardAlbumUI != null && _cardAlbumUI.BackpackIcon != null)
{
backpackTransform = _cardAlbumUI.BackpackIcon.transform;
// Get the backpack icon
GameObject backpackIcon = _cardAlbumUI.BackpackIcon;
backpackTransform = backpackIcon.transform;
// Find the parent button that controls visibility
backpackButton = backpackIcon.transform.parent.gameObject;
// Make sure the backpack button is visible for the animation
if (backpackButton != null)
{
backpackButton.SetActive(true);
Debug.Log("[BoosterOpeningPage] Made backpack button visible for animation");
}
}
if (backpackTransform == null)
{
// If no backpack is found, just return to the menu
UIPageController.Instance.PopPage();
yield break;
}
// Speed up the animation by reducing the delay
float animationDuration = 0.3f; // Faster animation duration
float cardDelay = 0.15f; // Even shorter delay between cards
// Move each card to the backpack with slight delay between cards
for (int i = 0; i < _revealedCards.Count; i++)
{
@@ -519,25 +537,34 @@ namespace AppleHills.UI.CardSystem
{
// Get the world position of the backpack
Vector3 backpackWorldPos = backpackTransform.position;
// Convert to local space of the card's parent for Tween
Vector3 targetPos = card.transform.parent.InverseTransformPoint(backpackWorldPos);
// Start the move animation
Tween.LocalPosition(card.transform, targetPos, 0.5f, cardMoveToBackpackDelay * i);
Tween.LocalScale(card.transform, Vector3.zero, 0.5f, cardMoveToBackpackDelay * i);
// Start the move animation - ensure no cancellation between animations
Tween.LocalPosition(card.transform, targetPos, animationDuration, cardDelay * i, Tween.EaseInOut);
Tween.LocalScale(card.transform, Vector3.zero, animationDuration, cardDelay * i, Tween.EaseIn);
Debug.Log($"[BoosterOpeningPage] Starting animation for card {i}");
}
// Only wait after starting each animation (don't wait after the last one)
if (i < _revealedCards.Count - 1)
{
yield return new WaitForSeconds(cardDelay);
}
// Wait before starting the next card
yield return new WaitForSeconds(cardMoveToBackpackDelay);
}
// Wait a bit after the last card
yield return new WaitForSeconds(0.5f);
// Calculate total animation time and wait for it to complete
float totalAnimationTime = cardDelay * (_revealedCards.Count - 1) + animationDuration;
yield return new WaitForSeconds(totalAnimationTime + 0.1f); // Small buffer to ensure animations complete
// The backpack visibility will be handled by CardAlbumUI's OnPageChanged after popping this page
// We don't need to explicitly hide it here as the system will handle it properly
// Update state
_currentState = OpeningState.Completed;
// Return to the menu
UIPageController.Instance.PopPage();
}