Almost working card state machine

This commit is contained in:
Michal Pikulski
2025-11-16 20:35:54 +01:00
parent 6fe7d012fc
commit 78aafb9275
42 changed files with 3057 additions and 3077 deletions

View File

@@ -1,6 +1,5 @@
using Core.SaveLoad;
using UnityEngine;
using UnityEngine.EventSystems;
using AppleHills.Core.Settings;
using Core;
@@ -10,14 +9,13 @@ namespace UI.CardSystem.StateMachine.States
/// Enlarged state for NEW cards - shows "NEW CARD" badge and waits for tap to dismiss.
/// Owns the NewCardBadge as a child GameObject.
/// </summary>
public class CardEnlargedNewState : AppleState, IPointerClickHandler
public class CardEnlargedNewState : AppleState, ICardClickHandler
{
[Header("State-Owned Visuals")]
[SerializeField] private GameObject newCardBadge;
private CardContext _context;
private ICardSystemSettings _settings;
private Vector3 _originalScale;
private void Awake()
{
@@ -34,39 +32,39 @@ namespace UI.CardSystem.StateMachine.States
_context.CardDisplay.transform.localRotation = Quaternion.Euler(0, 0, 0);
}
// Store original scale
_originalScale = _context.RootTransform.localScale;
// Check if we're already enlarged (coming from upgrade flow)
bool alreadyEnlarged = _context.RootTransform.localScale.x >= _settings.NewCardEnlargedScale * 0.9f;
if (!alreadyEnlarged)
{
// Normal flow - enlarge the card
if (_context.Animator != null)
{
_context.Animator.PlayEnlarge(_settings.NewCardEnlargedScale);
}
}
// Show NEW badge
if (newCardBadge != null)
{
newCardBadge.SetActive(true);
}
// Enlarge the card
if (_context.Animator != null)
{
_context.Animator.PlayEnlarge(_settings.NewCardEnlargedScale);
}
}
public void OnPointerClick(PointerEventData eventData)
public void OnCardClicked(CardContext context)
{
// Fire dismissed event
_context.FireCardDismissed();
// Tap to dismiss - shrink back and transition to revealed state
if (_context.Animator != null)
// Tap to dismiss - shrink back to original scale and transition to revealed state
if (context.Animator != null)
{
_context.Animator.PlayShrink(_originalScale, onComplete: () =>
context.Animator.PlayShrink(context.OriginalScale, onComplete: () =>
{
_context.StateMachine.ChangeState("RevealedState");
context.StateMachine.ChangeState("RevealedState");
});
}
else
{
// Fallback if no animator
_context.StateMachine.ChangeState("RevealedState");
context.StateMachine.ChangeState("RevealedState");
}
}
@@ -80,4 +78,3 @@ namespace UI.CardSystem.StateMachine.States
}
}
}