2025-11-11 20:25:23 +01:00
|
|
|
|
using Core.SaveLoad;
|
|
|
|
|
|
using Pixelplacement.TweenSystem;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.EventSystems;
|
2025-11-12 09:24:27 +01:00
|
|
|
|
using AppleHills.Core.Settings;
|
|
|
|
|
|
using Core;
|
2025-11-11 20:25:23 +01:00
|
|
|
|
|
|
|
|
|
|
namespace UI.CardSystem.StateMachine.States
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Idle state - card back is showing with gentle hover animation.
|
|
|
|
|
|
/// Waiting for click to flip and reveal.
|
|
|
|
|
|
/// Based on FlippableCard's idle behavior.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class CardIdleState : AppleState, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
|
|
|
|
|
|
{
|
|
|
|
|
|
[Header("State-Owned Visuals")]
|
|
|
|
|
|
[SerializeField] private GameObject cardBackVisual;
|
|
|
|
|
|
|
|
|
|
|
|
[Header("Idle Hover Settings")]
|
|
|
|
|
|
[SerializeField] private bool enableIdleHover = true;
|
|
|
|
|
|
|
|
|
|
|
|
private CardContext _context;
|
2025-11-12 09:24:27 +01:00
|
|
|
|
private ICardSystemSettings _settings;
|
2025-11-11 20:25:23 +01:00
|
|
|
|
private TweenBase _idleHoverTween;
|
|
|
|
|
|
private Vector2 _originalPosition;
|
|
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
_context = GetComponentInParent<CardContext>();
|
2025-11-12 09:24:27 +01:00
|
|
|
|
_settings = GameManager.GetSettingsObject<ICardSystemSettings>();
|
2025-11-11 20:25:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnEnterState()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Show card back, hide card front
|
|
|
|
|
|
if (cardBackVisual != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
cardBackVisual.SetActive(true);
|
|
|
|
|
|
// Ensure card back is at 0° rotation (facing camera)
|
|
|
|
|
|
cardBackVisual.transform.localRotation = Quaternion.Euler(0, 0, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_context.CardDisplay != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_context.CardDisplay.gameObject.SetActive(false);
|
|
|
|
|
|
// Ensure card front starts at 180° rotation (flipped away)
|
|
|
|
|
|
_context.CardDisplay.transform.localRotation = Quaternion.Euler(0, 180, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Save original position for hover animation
|
|
|
|
|
|
RectTransform rectTransform = _context.RootTransform.GetComponent<RectTransform>();
|
|
|
|
|
|
if (rectTransform != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_originalPosition = rectTransform.anchoredPosition;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Start idle hover animation
|
|
|
|
|
|
if (enableIdleHover && _context.Animator != null)
|
|
|
|
|
|
{
|
2025-11-12 09:24:27 +01:00
|
|
|
|
_idleHoverTween = _context.Animator.StartIdleHover(_settings.IdleHoverHeight, _settings.IdleHoverDuration);
|
2025-11-11 20:25:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Scale up slightly on hover
|
|
|
|
|
|
if (_context.Animator != null)
|
|
|
|
|
|
{
|
2025-11-12 09:24:27 +01:00
|
|
|
|
_context.Animator.AnimateScale(Vector3.one * _settings.HoverScaleMultiplier, 0.2f);
|
2025-11-11 20:25:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnPointerExit(PointerEventData eventData)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Scale back to normal
|
|
|
|
|
|
if (_context.Animator != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_context.Animator.AnimateScale(Vector3.one, 0.2f);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void OnPointerClick(PointerEventData eventData)
|
|
|
|
|
|
{
|
2025-11-12 11:58:01 +01:00
|
|
|
|
// Check if card is clickable (prevents multi-flip in booster opening)
|
|
|
|
|
|
if (!_context.IsClickable)
|
|
|
|
|
|
{
|
|
|
|
|
|
Logging.Debug($"[CardIdleState] Card is not clickable, ignoring click");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Stop idle hover and pointer interactions
|
|
|
|
|
|
StopIdleHover();
|
|
|
|
|
|
|
|
|
|
|
|
// Play flip animation directly (no state transition yet)
|
|
|
|
|
|
if (_context.Animator != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_context.Animator.PlayFlip(
|
|
|
|
|
|
cardBack: cardBackVisual != null ? cardBackVisual.transform : null,
|
|
|
|
|
|
cardFront: _context.CardDisplay != null ? _context.CardDisplay.transform : null,
|
|
|
|
|
|
onComplete: OnFlipComplete
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
_context.Animator.PlayFlipScalePunch();
|
|
|
|
|
|
}
|
2025-11-11 20:25:23 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-12 11:58:01 +01:00
|
|
|
|
private void OnFlipComplete()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Fire flip complete event
|
|
|
|
|
|
_context.FireFlipComplete();
|
|
|
|
|
|
|
|
|
|
|
|
// Transition based on whether this is a new card or repeat
|
|
|
|
|
|
if (_context.IsNewCard)
|
|
|
|
|
|
{
|
|
|
|
|
|
_context.StateMachine.ChangeState("EnlargedNewState");
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (_context.CardData != null && _context.CardData.Rarity == AppleHills.Data.CardSystem.CardRarity.Legendary)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Legendary repeat - skip enlarge, they can't upgrade
|
|
|
|
|
|
// Add to inventory and move to revealed state
|
|
|
|
|
|
if (Data.CardSystem.CardSystemManager.Instance != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Data.CardSystem.CardSystemManager.Instance.AddCardToInventoryDelayed(_context.CardData);
|
|
|
|
|
|
}
|
|
|
|
|
|
_context.StateMachine.ChangeState("RevealedState");
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (_context.RepeatCardCount > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
_context.StateMachine.ChangeState("EnlargedRepeatState");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_context.StateMachine.ChangeState("RevealedState");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void StopIdleHover()
|
2025-11-11 20:25:23 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (_idleHoverTween != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_idleHoverTween.Stop();
|
|
|
|
|
|
_idleHoverTween = null;
|
|
|
|
|
|
|
|
|
|
|
|
// Return to original position
|
|
|
|
|
|
RectTransform rectTransform = _context.RootTransform.GetComponent<RectTransform>();
|
|
|
|
|
|
if (rectTransform != null && _context.Animator != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_context.Animator.AnimateAnchoredPosition(_originalPosition, 0.3f);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-12 11:58:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Stop idle hover animation when leaving state
|
|
|
|
|
|
StopIdleHover();
|
2025-11-11 20:25:23 +01:00
|
|
|
|
|
|
|
|
|
|
// Reset scale
|
2025-11-12 11:58:01 +01:00
|
|
|
|
if (_context?.Animator != null)
|
2025-11-11 20:25:23 +01:00
|
|
|
|
{
|
|
|
|
|
|
_context.Animator.AnimateScale(Vector3.one, 0.2f);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Hide card back when leaving state
|
|
|
|
|
|
if (cardBackVisual != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
cardBackVisual.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|