From 689e177c99071b2c792dcfebe7f3e11c4f8ef31e Mon Sep 17 00:00:00 2001 From: Michal Pikulski Date: Mon, 17 Nov 2025 23:49:37 +0100 Subject: [PATCH] Finalize nice animations --- .../AssetGroups/BlokkemonCards.asset | 12 ------ .../Core/Settings/CardSystemSettings.cs | 4 +- Assets/Scripts/UI/CardSystem/AlbumViewPage.cs | 15 +------- .../States/CardAlbumEnlargedState.cs | 37 +++++++++++++++---- Assets/Settings/CardSystemSettings.asset | 2 +- 5 files changed, 34 insertions(+), 36 deletions(-) diff --git a/Assets/AddressableAssetsData/AssetGroups/BlokkemonCards.asset b/Assets/AddressableAssetsData/AssetGroups/BlokkemonCards.asset index 8bea4739..27cbdbc8 100644 --- a/Assets/AddressableAssetsData/AssetGroups/BlokkemonCards.asset +++ b/Assets/AddressableAssetsData/AssetGroups/BlokkemonCards.asset @@ -87,18 +87,6 @@ MonoBehaviour: m_SerializedLabels: - BlokkemonCard FlaggedDuringContentUpdateRestriction: 0 - - m_GUID: 80e3766cc597fd94f895f5cd6aa2bcc6 - m_Address: Assets/Data/Cards/Card_New Card.asset - m_ReadOnly: 0 - m_SerializedLabels: - - BlokkemonCard - FlaggedDuringContentUpdateRestriction: 0 - - m_GUID: 82008856df7c51f47b1582de464ba44b - m_Address: Assets/Data/Cards/Card_New Card.asset - m_ReadOnly: 0 - m_SerializedLabels: - - BlokkemonCard - FlaggedDuringContentUpdateRestriction: 0 - m_GUID: 99d8e528a8f9ead438e4c88a08c6f6c0 m_Address: Assets/Data/Cards/Card_New Card.asset m_ReadOnly: 0 diff --git a/Assets/Scripts/Core/Settings/CardSystemSettings.cs b/Assets/Scripts/Core/Settings/CardSystemSettings.cs index 01e1f4ab..0ea070b1 100644 --- a/Assets/Scripts/Core/Settings/CardSystemSettings.cs +++ b/Assets/Scripts/Core/Settings/CardSystemSettings.cs @@ -29,8 +29,8 @@ namespace AppleHills.Core.Settings [Tooltip("Scale for new cards when enlarged (1.5 = 150% of normal size)")] [SerializeField] private float newCardEnlargedScale = 1.5f; - [Tooltip("Scale for album cards when enlarged (2.5 = 250% of normal size)")] - [SerializeField] private float albumCardEnlargedScale = 2.5f; + [Tooltip("Scale for album cards when enlarged (4.0 = 400% of normal size - dramatic showcase)")] + [SerializeField] private float albumCardEnlargedScale = 4.0f; [Tooltip("Duration of scale animations in seconds")] [SerializeField] private float scaleDuration = 0.3f; diff --git a/Assets/Scripts/UI/CardSystem/AlbumViewPage.cs b/Assets/Scripts/UI/CardSystem/AlbumViewPage.cs index 1c484207..17c88ef7 100644 --- a/Assets/Scripts/UI/CardSystem/AlbumViewPage.cs +++ b/Assets/Scripts/UI/CardSystem/AlbumViewPage.cs @@ -444,23 +444,12 @@ namespace UI.CardSystem private void OnCardShrinkRequested(StateMachine.States.CardAlbumEnlargedState state) { if (state == null) return; - // Hide backdrop + // Hide backdrop; state will animate back to slot and reparent on completion if (cardEnlargedBackdrop != null) { cardEnlargedBackdrop.SetActive(false); } - // Reparent back to original parent and restore local transform - var ctx = state.GetComponentInParent(); - 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(); - } - } + // Do not reparent here; reverse animation is orchestrated by the state } #endregion diff --git a/Assets/Scripts/UI/CardSystem/StateMachine/States/CardAlbumEnlargedState.cs b/Assets/Scripts/UI/CardSystem/StateMachine/States/CardAlbumEnlargedState.cs index fdba3737..481af4f6 100644 --- a/Assets/Scripts/UI/CardSystem/StateMachine/States/CardAlbumEnlargedState.cs +++ b/Assets/Scripts/UI/CardSystem/StateMachine/States/CardAlbumEnlargedState.cs @@ -2,6 +2,7 @@ using Core.SaveLoad; using UnityEngine; using AppleHills.Core.Settings; +using Pixelplacement; namespace UI.CardSystem.StateMachine.States { @@ -17,6 +18,7 @@ namespace UI.CardSystem.StateMachine.States private Transform _originalParent; private Vector3 _originalLocalPosition; private Quaternion _originalLocalRotation; + private Vector3 _originalWorldPosition; // Events for page to manage backdrop and reparenting public event System.Action OnEnlargeRequested; @@ -42,14 +44,18 @@ namespace UI.CardSystem.StateMachine.States _originalParent = _context.RootTransform.parent; _originalLocalPosition = _context.RootTransform.localPosition; _originalLocalRotation = _context.RootTransform.localRotation; + _originalWorldPosition = _context.RootTransform.position; - // Notify page to show backdrop and reparent card to top layer + // Notify page to show backdrop and reparent card to top layer (preserve world transform) OnEnlargeRequested?.Invoke(this); - // Enlarge the card using album scale setting + // Animate into center and scale up significantly if (_context.Animator != null) { - _context.Animator.PlayEnlarge(_settings.AlbumCardEnlargedScale); + // Move to center of enlarged container (assumes zero is centered) + _context.Animator.AnimateLocalPosition(Vector3.zero, _settings.ScaleDuration); + // Enlarge using settings-controlled scale + _context.Animator.PlayEnlarge(_settings.AlbumCardEnlargedScale, _settings.ScaleDuration); } Logging.Debug($"[CardAlbumEnlargedState] Card enlarged from album: {_context.CardData?.Name}"); @@ -57,22 +63,38 @@ namespace UI.CardSystem.StateMachine.States public void OnCardClicked(CardContext context) { - // Click to shrink back + // Click to shrink back (play reverse of opening animation) Logging.Debug($"[CardAlbumEnlargedState] Card clicked while enlarged, shrinking back"); - // Notify page to prepare for shrink + // Ask page to hide backdrop (state will handle moving back & reparenting) OnShrinkRequested?.Invoke(this); - // Shrink animation, then transition back + // Animate back to original world position + shrink to original scale + float duration = _settings.ScaleDuration; + + // Move using world-space tween so we land exactly on the original position + Tween.Position(context.RootTransform, _originalWorldPosition, duration, 0f, Tween.EaseInOut); + if (context.Animator != null) { - context.Animator.PlayShrink(_originalScale, onComplete: () => + context.Animator.PlayShrink(_originalScale, duration, onComplete: () => { + // Reparent back to original hierarchy and restore local transform + context.RootTransform.SetParent(_originalParent, true); + context.RootTransform.localPosition = _originalLocalPosition; + context.RootTransform.localRotation = _originalLocalRotation; + + // Transition back to placed state context.StateMachine.ChangeState("PlacedInSlotState"); }); } else { + // Fallback if no animator: snap back + context.RootTransform.position = _originalWorldPosition; + context.RootTransform.SetParent(_originalParent, true); + context.RootTransform.localPosition = _originalLocalPosition; + context.RootTransform.localRotation = _originalLocalRotation; context.StateMachine.ChangeState("PlacedInSlotState"); } } @@ -102,4 +124,3 @@ namespace UI.CardSystem.StateMachine.States } } } - diff --git a/Assets/Settings/CardSystemSettings.asset b/Assets/Settings/CardSystemSettings.asset index f09c2072..b8677b8c 100644 --- a/Assets/Settings/CardSystemSettings.asset +++ b/Assets/Settings/CardSystemSettings.asset @@ -18,7 +18,7 @@ MonoBehaviour: flipDuration: 0.6 flipScalePunch: 1.1 newCardEnlargedScale: 1.5 - albumCardEnlargedScale: 1.5 + albumCardEnlargedScale: 4 scaleDuration: 0.3 dragScale: 1.1 cardsToUpgrade: 5