Update assets, working save kerfuffle
This commit is contained in:
@@ -6,12 +6,7 @@ using UnityEngine;
|
||||
|
||||
namespace UI.CardSystem.StateMachine
|
||||
{
|
||||
/// <summary>
|
||||
/// Main Card controller component.
|
||||
/// Orchestrates the card state machine, context, and animator.
|
||||
/// Inherits from DraggableObject to provide drag/drop capabilities for album placement.
|
||||
/// This is the single entry point for working with cards.
|
||||
/// </summary>
|
||||
// ...existing code...
|
||||
public class Card : DraggableObject
|
||||
{
|
||||
[Header("Components")]
|
||||
@@ -57,34 +52,45 @@ namespace UI.CardSystem.StateMachine
|
||||
{
|
||||
base.OnDragStartedHook();
|
||||
|
||||
// Always emit the generic drag started event - consumers can decide what to do
|
||||
// Always emit the generic drag started event for external consumers (AlbumViewPage, etc.)
|
||||
context?.NotifyDragStarted();
|
||||
|
||||
string current = GetCurrentStateName();
|
||||
|
||||
if (current == "PendingFaceDownState")
|
||||
// Check if current state wants to handle drag behavior
|
||||
if (stateMachine?.currentState != null)
|
||||
{
|
||||
// Let the state handle the flip transition
|
||||
var pendingState = GetStateComponent<States.CardPendingFaceDownState>("PendingFaceDownState");
|
||||
if (pendingState != null)
|
||||
var dragHandler = stateMachine.currentState.GetComponent<ICardStateDragHandler>();
|
||||
if (dragHandler != null && dragHandler.OnCardDragStarted(context))
|
||||
{
|
||||
pendingState.OnDragStarted();
|
||||
return; // State handled it, don't do default behavior
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Logging.Debug($"[Card] Drag started on {CardData?.Name}, transitioning to DraggingState");
|
||||
ChangeState("DraggingState");
|
||||
}
|
||||
|
||||
// Default behavior: transition to DraggingState
|
||||
Logging.Debug($"[Card] Drag started on {CardData?.Name}, transitioning to DraggingState");
|
||||
ChangeState("DraggingState");
|
||||
}
|
||||
|
||||
protected override void OnDragEndedHook()
|
||||
{
|
||||
base.OnDragEndedHook();
|
||||
|
||||
// Always emit the generic drag ended event for external consumers
|
||||
context?.NotifyDragEnded();
|
||||
|
||||
// Check if current state wants to handle drag end
|
||||
if (stateMachine?.currentState != null)
|
||||
{
|
||||
var dragHandler = stateMachine.currentState.GetComponent<ICardStateDragHandler>();
|
||||
if (dragHandler != null && dragHandler.OnCardDragEnded(context))
|
||||
{
|
||||
return; // State handled it
|
||||
}
|
||||
}
|
||||
|
||||
// Default behavior for states that don't implement custom drag end
|
||||
string current = GetCurrentStateName();
|
||||
if (current == "DraggingState")
|
||||
{
|
||||
// Existing logic
|
||||
if (CurrentSlot is AlbumCardSlot albumSlot)
|
||||
{
|
||||
Logging.Debug($"[Card] Dropped in album slot, transitioning to PlacedInSlotState");
|
||||
@@ -102,22 +108,6 @@ namespace UI.CardSystem.StateMachine
|
||||
ChangeState("RevealedState");
|
||||
}
|
||||
}
|
||||
else if (current == "DraggingRevealedState")
|
||||
{
|
||||
// Pending revealed drag state end
|
||||
if (CurrentSlot is AlbumCardSlot albumSlot)
|
||||
{
|
||||
var placedState = GetStateComponent<States.CardPlacedInSlotState>("PlacedInSlotState");
|
||||
if (placedState != null) placedState.SetParentSlot(albumSlot);
|
||||
ChangeState("PlacedInSlotState");
|
||||
OnPlacedInAlbumSlot?.Invoke(this, albumSlot);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Return to corner face-down
|
||||
ChangeState("PendingFaceDownState");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -151,16 +141,6 @@ namespace UI.CardSystem.StateMachine
|
||||
SetDraggingEnabled(false); // Booster cards cannot be dragged
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setup for album placement flow (starts at RevealedState, can be dragged)
|
||||
/// Dragging is ENABLED for album placement cards
|
||||
/// </summary>
|
||||
public void SetupForAlbumPlacement(CardData data)
|
||||
{
|
||||
SetupCard(data, "RevealedState");
|
||||
SetDraggingEnabled(true); // Album placement cards can be dragged
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setup for album placement (starts at PlacedInSlotState)
|
||||
/// Dragging is DISABLED once placed in slot
|
||||
|
||||
@@ -41,6 +41,9 @@ namespace UI.CardSystem.StateMachine
|
||||
// Generic drag event - fired when drag starts, consumers decide how to handle based on current state
|
||||
public event Action<CardContext> OnDragStarted;
|
||||
|
||||
// Generic drag end event - fired when drag ends, consumers decide how to handle based on current state
|
||||
public event Action<CardContext> OnDragEnded;
|
||||
|
||||
private bool _hasCompletedReveal = false;
|
||||
public bool HasCompletedReveal => _hasCompletedReveal;
|
||||
|
||||
@@ -60,6 +63,12 @@ namespace UI.CardSystem.StateMachine
|
||||
OnDragStarted?.Invoke(this);
|
||||
}
|
||||
|
||||
// Helper method for states/card to signal drag ended
|
||||
public void NotifyDragEnded()
|
||||
{
|
||||
OnDragEnded?.Invoke(this);
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Auto-find components if not assigned
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using Core.SaveLoad;
|
||||
|
||||
namespace UI.CardSystem.StateMachine
|
||||
{
|
||||
/// <summary>
|
||||
/// Card state machine that opts out of save system.
|
||||
/// Cards are transient UI elements that don't need persistence.
|
||||
/// </summary>
|
||||
public class CardStateMachine : AppleMachine
|
||||
{
|
||||
/// <summary>
|
||||
/// Opt out of save/load system - cards are transient and spawned from data.
|
||||
/// </summary>
|
||||
public override bool ShouldParticipateInSave()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 87ed5616041a4d878f452a8741e1eeab
|
||||
timeCreated: 1763385180
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace UI.CardSystem.StateMachine
|
||||
{
|
||||
/// <summary>
|
||||
/// Implement on a state component to receive routed drag events from Card.
|
||||
/// Similar to ICardClickHandler but for drag behavior.
|
||||
/// </summary>
|
||||
public interface ICardStateDragHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// Called when drag starts. Return true to handle drag (prevent default DraggingState transition).
|
||||
/// </summary>
|
||||
bool OnCardDragStarted(CardContext context);
|
||||
|
||||
/// <summary>
|
||||
/// Called when drag ends. Return true to handle drag end (prevent default state transitions).
|
||||
/// </summary>
|
||||
bool OnCardDragEnded(CardContext context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc610b791f43409e8231085a70514e2c
|
||||
timeCreated: 1763374419
|
||||
@@ -4,35 +4,60 @@ using UnityEngine;
|
||||
namespace UI.CardSystem.StateMachine.States
|
||||
{
|
||||
/// <summary>
|
||||
/// Dragging revealed state for pending cards after flip; minimal overlay of CardDraggingState but no badges.
|
||||
/// Dragging revealed state for pending cards after flip.
|
||||
/// Shows card front without badges, handles placement or return to corner.
|
||||
/// </summary>
|
||||
public class CardDraggingRevealedState : AppleState
|
||||
public class CardDraggingRevealedState : AppleState, ICardStateDragHandler
|
||||
{
|
||||
private CardContext context;
|
||||
private Vector3 originalScale;
|
||||
private CardContext _context;
|
||||
private Vector3 _originalScale;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
context = GetComponentInParent<CardContext>();
|
||||
_context = GetComponentInParent<CardContext>();
|
||||
}
|
||||
|
||||
public override void OnEnterState()
|
||||
{
|
||||
if (context == null) return;
|
||||
if (context.CardDisplay != null)
|
||||
if (_context == null) return;
|
||||
if (_context.CardDisplay != null)
|
||||
{
|
||||
context.CardDisplay.gameObject.SetActive(true);
|
||||
context.CardDisplay.transform.localRotation = Quaternion.Euler(0,0,0);
|
||||
_context.CardDisplay.gameObject.SetActive(true);
|
||||
_context.CardDisplay.transform.localRotation = Quaternion.Euler(0,0,0);
|
||||
}
|
||||
originalScale = context.RootTransform.localScale;
|
||||
context.RootTransform.localScale = originalScale * 1.15f;
|
||||
_originalScale = _context.RootTransform.localScale;
|
||||
_context.RootTransform.localScale = _originalScale * 1.15f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Already in dragging state, nothing to do
|
||||
/// </summary>
|
||||
public bool OnCardDragStarted(CardContext ctx)
|
||||
{
|
||||
return true; // Prevent default DraggingState transition
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handle drag end - just let AlbumViewPage handle placement logic
|
||||
/// Stay in this state until AlbumViewPage transitions us after tween
|
||||
/// </summary>
|
||||
public bool OnCardDragEnded(CardContext ctx)
|
||||
{
|
||||
// Don't do anything - AlbumViewPage will:
|
||||
// 1. Wait for page flip to complete
|
||||
// 2. Find the correct slot
|
||||
// 3. Tween card to slot
|
||||
// 4. Transition to PlacedInSlotState
|
||||
|
||||
// Return true to prevent default behavior
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (context?.RootTransform != null)
|
||||
if (_context?.RootTransform != null)
|
||||
{
|
||||
context.RootTransform.localScale = originalScale;
|
||||
_context.RootTransform.localScale = _originalScale;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
using Core.SaveLoad;
|
||||
using Core;
|
||||
using Core.SaveLoad;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UI.CardSystem.StateMachine.States
|
||||
{
|
||||
/// <summary>
|
||||
/// Card is in pending face-down state in corner, awaiting drag.
|
||||
/// On drag start, triggers data assignment, flip animation, and page navigation.
|
||||
/// On drag start, triggers flip animation and transitions to revealed dragging.
|
||||
/// </summary>
|
||||
public class CardPendingFaceDownState : AppleState
|
||||
public class CardPendingFaceDownState : AppleState, ICardStateDragHandler
|
||||
{
|
||||
[Header("State-Owned Visuals")]
|
||||
[SerializeField] private GameObject cardBackVisual;
|
||||
@@ -44,15 +45,31 @@ namespace UI.CardSystem.StateMachine.States
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called by Card.OnDragStartedHook when user starts dragging.
|
||||
/// This triggers the smart selection, page navigation, and flip animation.
|
||||
/// Handle drag start - triggers flip animation and page navigation
|
||||
/// </summary>
|
||||
public void OnDragStarted()
|
||||
public bool OnCardDragStarted(CardContext context)
|
||||
{
|
||||
if (_isFlipping) return; // Already flipping
|
||||
if (_isFlipping) return true; // Already handling
|
||||
|
||||
// Start flip animation (data should be assigned by listeners by now)
|
||||
// IMPORTANT: Data must be assigned by event listeners (AlbumViewPage) BEFORE we flip
|
||||
// The event system guarantees this because events are synchronous
|
||||
if (context.CardData == null)
|
||||
{
|
||||
Logging.Warning("[CardPendingFaceDownState] OnCardDragStarted called but no CardData assigned yet!");
|
||||
return true; // Don't flip without data
|
||||
}
|
||||
|
||||
// Start flip animation (data is now guaranteed to be assigned)
|
||||
StartFlipAnimation();
|
||||
return true; // We handled it, prevent default DraggingState transition
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// We don't handle drag end in face-down state
|
||||
/// </summary>
|
||||
public bool OnCardDragEnded(CardContext context)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private void StartFlipAnimation()
|
||||
|
||||
Reference in New Issue
Block a user