120 lines
4.1 KiB
C#
120 lines
4.1 KiB
C#
using Core.SaveLoad;
|
|
using Pixelplacement.TweenSystem;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using AppleHills.Core.Settings;
|
|
using Core;
|
|
|
|
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;
|
|
private ICardSystemSettings _settings;
|
|
private TweenBase _idleHoverTween;
|
|
private Vector2 _originalPosition;
|
|
|
|
private void Awake()
|
|
{
|
|
_context = GetComponentInParent<CardContext>();
|
|
_settings = GameManager.GetSettingsObject<ICardSystemSettings>();
|
|
}
|
|
|
|
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)
|
|
{
|
|
_idleHoverTween = _context.Animator.StartIdleHover(_settings.IdleHoverHeight, _settings.IdleHoverDuration);
|
|
}
|
|
}
|
|
|
|
public void OnPointerEnter(PointerEventData eventData)
|
|
{
|
|
// Scale up slightly on hover
|
|
if (_context.Animator != null)
|
|
{
|
|
_context.Animator.AnimateScale(Vector3.one * _settings.HoverScaleMultiplier, 0.2f);
|
|
}
|
|
}
|
|
|
|
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)
|
|
{
|
|
// Click to flip - transition to flipping state
|
|
_context.StateMachine.ChangeState("FlippingState");
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
// Stop idle hover animation when leaving state
|
|
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);
|
|
}
|
|
}
|
|
|
|
// Reset scale
|
|
if (_context.Animator != null)
|
|
{
|
|
_context.Animator.AnimateScale(Vector3.one, 0.2f);
|
|
}
|
|
|
|
// Hide card back when leaving state
|
|
if (cardBackVisual != null)
|
|
{
|
|
cardBackVisual.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|