Almost working card state machine
This commit is contained in:
@@ -3,6 +3,7 @@ using Pixelplacement.TweenSystem;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using AppleHills.Core.Settings;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using Core;
|
||||
|
||||
namespace UI.CardSystem.StateMachine.States
|
||||
@@ -12,7 +13,7 @@ namespace UI.CardSystem.StateMachine.States
|
||||
/// Waiting for click to flip and reveal.
|
||||
/// Based on FlippableCard's idle behavior.
|
||||
/// </summary>
|
||||
public class CardIdleState : AppleState, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler
|
||||
public class CardIdleState : AppleState, ICardClickHandler, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler
|
||||
{
|
||||
[Header("State-Owned Visuals")]
|
||||
[SerializeField] private GameObject cardBackVisual;
|
||||
@@ -80,10 +81,10 @@ namespace UI.CardSystem.StateMachine.States
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
public void OnCardClicked(CardContext context)
|
||||
{
|
||||
// Check if card is clickable (prevents multi-flip in booster opening)
|
||||
if (!_context.IsClickable)
|
||||
if (!context.IsClickable)
|
||||
{
|
||||
Logging.Debug($"[CardIdleState] Card is not clickable, ignoring click");
|
||||
return;
|
||||
@@ -92,27 +93,34 @@ namespace UI.CardSystem.StateMachine.States
|
||||
// Stop idle hover and pointer interactions
|
||||
StopIdleHover();
|
||||
|
||||
// Play flip animation directly (no state transition yet)
|
||||
if (_context.Animator != null)
|
||||
// Play flip animation directly
|
||||
if (context.Animator != null)
|
||||
{
|
||||
_context.Animator.PlayFlip(
|
||||
context.Animator.PlayFlip(
|
||||
cardBack: cardBackVisual != null ? cardBackVisual.transform : null,
|
||||
cardFront: _context.CardDisplay != null ? _context.CardDisplay.transform : null,
|
||||
cardFront: context.CardDisplay != null ? context.CardDisplay.transform : null,
|
||||
onComplete: OnFlipComplete
|
||||
);
|
||||
|
||||
_context.Animator.PlayFlipScalePunch();
|
||||
context.Animator.PlayFlipScalePunch();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
// Forward to same logic as routed click to keep behavior unified
|
||||
OnCardClicked(_context);
|
||||
}
|
||||
|
||||
private void OnFlipComplete()
|
||||
{
|
||||
// Fire flip complete event
|
||||
_context.FireFlipComplete();
|
||||
// Query current collection state from CardSystemManager (don't use cached values)
|
||||
bool isNew = Data.CardSystem.CardSystemManager.Instance.IsCardNew(_context.CardData, out CardData existingCard);
|
||||
|
||||
// Transition based on whether this is a new card or repeat
|
||||
if (_context.IsNewCard)
|
||||
if (isNew)
|
||||
{
|
||||
// New card - show "NEW" badge and enlarge
|
||||
_context.StateMachine.ChangeState("EnlargedNewState");
|
||||
}
|
||||
else if (_context.CardData != null && _context.CardData.Rarity == AppleHills.Data.CardSystem.CardRarity.Legendary)
|
||||
@@ -125,13 +133,10 @@ namespace UI.CardSystem.StateMachine.States
|
||||
}
|
||||
_context.StateMachine.ChangeState("RevealedState");
|
||||
}
|
||||
else if (_context.RepeatCardCount > 0)
|
||||
{
|
||||
_context.StateMachine.ChangeState("EnlargedRepeatState");
|
||||
}
|
||||
else
|
||||
{
|
||||
_context.StateMachine.ChangeState("RevealedState");
|
||||
// Repeat card - show progress toward upgrade
|
||||
_context.StateMachine.ChangeState("EnlargedRepeatState");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,4 +175,3 @@ namespace UI.CardSystem.StateMachine.States
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user