Update the card kerfufle
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
using Core;
|
||||
using Core.SaveLoad;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UI.CardSystem.StateMachine;
|
||||
|
||||
namespace UI.CardSystem.StateMachine.States
|
||||
{
|
||||
/// <summary>
|
||||
/// 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
|
||||
{
|
||||
private CardContext _context;
|
||||
private Vector3 _originalScale;
|
||||
private Transform _originalParent;
|
||||
private Vector3 _originalLocalPosition;
|
||||
private Quaternion _originalLocalRotation;
|
||||
|
||||
// Events for page to manage backdrop and reparenting
|
||||
public event System.Action<CardAlbumEnlargedState> OnEnlargeRequested;
|
||||
public event System.Action<CardAlbumEnlargedState> OnShrinkRequested;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_context = GetComponentInParent<CardContext>();
|
||||
}
|
||||
|
||||
public override void OnEnterState()
|
||||
{
|
||||
// Store original transform for restoration
|
||||
_originalScale = _context.RootTransform.localScale;
|
||||
_originalParent = _context.RootTransform.parent;
|
||||
_originalLocalPosition = _context.RootTransform.localPosition;
|
||||
_originalLocalRotation = _context.RootTransform.localRotation;
|
||||
|
||||
// Notify page to show backdrop and reparent card to top layer
|
||||
OnEnlargeRequested?.Invoke(this);
|
||||
|
||||
// Enlarge the card
|
||||
if (_context.Animator != null)
|
||||
{
|
||||
_context.Animator.PlayEnlarge();
|
||||
}
|
||||
|
||||
Logging.Debug($"[CardAlbumEnlargedState] Card enlarged from album: {_context.CardData?.Name}");
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
// Click to shrink back
|
||||
Logging.Debug($"[CardAlbumEnlargedState] Card clicked while enlarged, shrinking back");
|
||||
|
||||
// Notify page to prepare for shrink
|
||||
OnShrinkRequested?.Invoke(this);
|
||||
|
||||
// Shrink animation, then transition back
|
||||
if (_context.Animator != null)
|
||||
{
|
||||
_context.Animator.PlayShrink(_originalScale, onComplete: () =>
|
||||
{
|
||||
_context.StateMachine.ChangeState("PlacedInSlotState");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get original parent for restoration
|
||||
/// </summary>
|
||||
public Transform GetOriginalParent() => _originalParent;
|
||||
|
||||
/// <summary>
|
||||
/// Get original local position for restoration
|
||||
/// </summary>
|
||||
public Vector3 GetOriginalLocalPosition() => _originalLocalPosition;
|
||||
|
||||
/// <summary>
|
||||
/// Get original local rotation for restoration
|
||||
/// </summary>
|
||||
public Quaternion GetOriginalLocalRotation() => _originalLocalRotation;
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
// Restore original scale when exiting
|
||||
if (_context?.RootTransform != null)
|
||||
{
|
||||
_context.RootTransform.localScale = _originalScale;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user