Update pages to follow new card flow
This commit is contained in:
@@ -56,16 +56,20 @@ namespace UI.CardSystem.StateMachine
|
||||
protected override void OnDragStartedHook()
|
||||
{
|
||||
base.OnDragStartedHook();
|
||||
|
||||
// Always emit the generic drag started event - consumers can decide what to do
|
||||
context?.NotifyDragStarted();
|
||||
|
||||
string current = GetCurrentStateName();
|
||||
|
||||
if (current == "PendingFaceDownState")
|
||||
{
|
||||
// Notify AlbumViewPage to assign data & flip
|
||||
var albumPage = FindObjectOfType<AlbumViewPage>();
|
||||
if (albumPage != null)
|
||||
// Let the state handle the flip transition
|
||||
var pendingState = GetStateComponent<States.CardPendingFaceDownState>("PendingFaceDownState");
|
||||
if (pendingState != null)
|
||||
{
|
||||
albumPage.HandlePendingCardDragStart(this);
|
||||
pendingState.OnDragStarted();
|
||||
}
|
||||
// State change will be triggered by album page after data assignment
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -38,6 +38,9 @@ namespace UI.CardSystem.StateMachine
|
||||
// Single event for reveal flow completion
|
||||
public event Action<CardContext> OnRevealFlowComplete;
|
||||
|
||||
// Generic drag event - fired when drag starts, consumers decide how to handle based on current state
|
||||
public event Action<CardContext> OnDragStarted;
|
||||
|
||||
private bool _hasCompletedReveal = false;
|
||||
public bool HasCompletedReveal => _hasCompletedReveal;
|
||||
|
||||
@@ -51,6 +54,12 @@ namespace UI.CardSystem.StateMachine
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method for states/card to signal drag started
|
||||
public void NotifyDragStarted()
|
||||
{
|
||||
OnDragStarted?.Invoke(this);
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Auto-find components if not assigned
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
using Core;
|
||||
using Core.SaveLoad;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UI.CardSystem.StateMachine.States
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles flipping a pending face-down card after data assignment.
|
||||
/// Transitions to DraggingRevealedState when flip completes.
|
||||
/// </summary>
|
||||
public class CardFlippingPendingState : AppleState
|
||||
{
|
||||
private CardContext context;
|
||||
private GameObject cardBack;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
context = GetComponentInParent<CardContext>();
|
||||
if (context != null)
|
||||
{
|
||||
var backTransform = context.RootTransform.Find("CardBack");
|
||||
if (backTransform != null) cardBack = backTransform.gameObject;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnEnterState()
|
||||
{
|
||||
if (context == null) return;
|
||||
// Ensure card back visible and front hidden at start
|
||||
if (cardBack != null) cardBack.SetActive(true);
|
||||
if (context.CardDisplay != null) context.CardDisplay.gameObject.SetActive(false);
|
||||
|
||||
// Optional: album navigation
|
||||
var albumPage = Object.FindObjectOfType<AlbumViewPage>();
|
||||
if (albumPage != null && context.CardData != null)
|
||||
{
|
||||
int targetPage = albumPage.FindPageForCard(context.CardData); // placeholder; method may be private
|
||||
}
|
||||
|
||||
if (context.Animator != null)
|
||||
{
|
||||
Transform back = cardBack != null ? cardBack.transform : null;
|
||||
Transform front = context.CardDisplay != null ? context.CardDisplay.transform : null;
|
||||
context.Animator.PlayFlip(back, front, onComplete: () =>
|
||||
{
|
||||
context.StateMachine.ChangeState("DraggingRevealedState");
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (cardBack != null) cardBack.SetActive(false);
|
||||
if (context.CardDisplay != null) context.CardDisplay.gameObject.SetActive(true);
|
||||
context.StateMachine.ChangeState("DraggingRevealedState");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: edffabfce37d42ceac2194c23470acab
|
||||
timeCreated: 1763322190
|
||||
@@ -5,35 +5,97 @@ namespace UI.CardSystem.StateMachine.States
|
||||
{
|
||||
/// <summary>
|
||||
/// Card is in pending face-down state in corner, awaiting drag.
|
||||
/// Front hidden, back visible (assumes CardBack child exists).
|
||||
/// On drag start, triggers data assignment, flip animation, and page navigation.
|
||||
/// </summary>
|
||||
public class CardPendingFaceDownState : AppleState
|
||||
{
|
||||
private CardContext context;
|
||||
private GameObject cardBack;
|
||||
[Header("State-Owned Visuals")]
|
||||
[SerializeField] private GameObject cardBackVisual;
|
||||
|
||||
private CardContext _context;
|
||||
private bool _isFlipping;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
context = GetComponentInParent<CardContext>();
|
||||
if (context != null)
|
||||
{
|
||||
var backTransform = context.RootTransform.Find("CardBack");
|
||||
if (backTransform != null) cardBack = backTransform.gameObject;
|
||||
}
|
||||
_context = GetComponentInParent<CardContext>();
|
||||
}
|
||||
|
||||
public override void OnEnterState()
|
||||
{
|
||||
if (context == null) return;
|
||||
// Hide front
|
||||
if (context.CardDisplay != null)
|
||||
if (_context == null) return;
|
||||
|
||||
_isFlipping = false;
|
||||
|
||||
// Show card back, hide card front
|
||||
if (cardBackVisual != null)
|
||||
{
|
||||
context.CardDisplay.gameObject.SetActive(false);
|
||||
cardBackVisual.SetActive(true);
|
||||
cardBackVisual.transform.localRotation = Quaternion.Euler(0, 0, 0);
|
||||
}
|
||||
|
||||
if (_context.CardDisplay != null)
|
||||
{
|
||||
_context.CardDisplay.gameObject.SetActive(false);
|
||||
_context.CardDisplay.transform.localRotation = Quaternion.Euler(0, 180, 0);
|
||||
}
|
||||
|
||||
// Scale down for corner display
|
||||
_context.RootTransform.localScale = _context.OriginalScale * 0.8f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by Card.OnDragStartedHook when user starts dragging.
|
||||
/// This triggers the smart selection, page navigation, and flip animation.
|
||||
/// </summary>
|
||||
public void OnDragStarted()
|
||||
{
|
||||
if (_isFlipping) return; // Already flipping
|
||||
|
||||
// Start flip animation (data should be assigned by listeners by now)
|
||||
StartFlipAnimation();
|
||||
}
|
||||
|
||||
private void StartFlipAnimation()
|
||||
{
|
||||
_isFlipping = true;
|
||||
|
||||
// Scale up from corner size to normal dragging size
|
||||
if (_context.Animator != null)
|
||||
{
|
||||
_context.Animator.AnimateScale(_context.OriginalScale * 1.15f, 0.3f);
|
||||
}
|
||||
|
||||
// Play flip animation
|
||||
if (_context.Animator != null)
|
||||
{
|
||||
_context.Animator.PlayFlip(
|
||||
cardBack: cardBackVisual != null ? cardBackVisual.transform : null,
|
||||
cardFront: _context.CardDisplay != null ? _context.CardDisplay.transform : null,
|
||||
onComplete: OnFlipComplete
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
// No animator, just switch visibility immediately
|
||||
if (cardBackVisual != null) cardBackVisual.SetActive(false);
|
||||
if (_context.CardDisplay != null) _context.CardDisplay.gameObject.SetActive(true);
|
||||
OnFlipComplete();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnFlipComplete()
|
||||
{
|
||||
// Transition to dragging revealed state
|
||||
_context.StateMachine.ChangeState("DraggingRevealedState");
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
// Hide card back when leaving state
|
||||
if (cardBackVisual != null)
|
||||
{
|
||||
cardBackVisual.SetActive(false);
|
||||
}
|
||||
// Show back
|
||||
if (cardBack != null) cardBack.SetActive(true);
|
||||
// Scale
|
||||
context.RootTransform.localScale = context.OriginalScale * 0.8f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user