using Core;
using Core.SaveLoad;
using UnityEngine;
using AppleHills.Core.Settings;
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.
///
public class CardAlbumEnlargedState : AppleState, ICardClickHandler
{
private CardContext _context;
private ICardSystemSettings _settings;
private Vector3 _originalScale;
private Transform _originalParent;
private Vector3 _originalLocalPosition;
private Quaternion _originalLocalRotation;
// Events for page to manage backdrop and reparenting
public event System.Action OnEnlargeRequested;
public event System.Action OnShrinkRequested;
private void Awake()
{
_context = GetComponentInParent();
_settings = GameManager.GetSettingsObject();
}
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);
}
// 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 using album scale setting
if (_context.Animator != null)
{
_context.Animator.PlayEnlarge(_settings.AlbumCardEnlargedScale);
}
Logging.Debug($"[CardAlbumEnlargedState] Card enlarged from album: {_context.CardData?.Name}");
}
public void OnCardClicked(CardContext context)
{
// 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");
});
}
else
{
context.StateMachine.ChangeState("PlacedInSlotState");
}
}
///
/// Get original parent for restoration
///
public Transform GetOriginalParent() => _originalParent;
///
/// Get original local position for restoration
///
public Vector3 GetOriginalLocalPosition() => _originalLocalPosition;
///
/// Get original local rotation for restoration
///
public Quaternion GetOriginalLocalRotation() => _originalLocalRotation;
private void OnDisable()
{
// Restore original scale when exiting
if (_context?.RootTransform != null)
{
_context.RootTransform.localScale = _originalScale;
}
}
}
}