Stash half-assed work on testing scene

This commit is contained in:
Michal Pikulski
2025-11-12 11:58:01 +01:00
parent a9f102b3c4
commit 6fd1a10eb6
18 changed files with 3065 additions and 321 deletions

View File

@@ -10,10 +10,9 @@ namespace UI.CardSystem
/// Controls a vertical progress bar made of individual Image elements.
/// Fills from bottom to top and animates the newest element with a blink effect.
///
/// Setup: Place on GameObject with GridLayoutGroup (1 column, N rows).
/// Grid should have "Lower Right" corner start so first child = bottom element.
/// Setup: Place on GameObject with VerticalLayoutGroup (Reverse Arrangement enabled).
/// First child = first progress element (1/5), last child = last progress element (5/5).
/// </summary>
[RequireComponent(typeof(GridLayoutGroup))]
public class ProgressBarController : MonoBehaviour
{
[Header("Progress Elements")]
@@ -73,8 +72,8 @@ namespace UI.CardSystem
element.enabled = false;
}
// Enable elements from BOTTOM to TOP (first N elements)
// Since GridLayout starts at "Lower Right", element[0] = bottom, element[4] = top
// Enable first N elements (since first child = 1/5, last child = 5/5)
// If currentCount = 3, enable elements [0], [1], [2] (first 3 elements)
for (int i = 0; i < currentCount && i < _progressElements.Length; i++)
{
_progressElements[i].enabled = true;
@@ -82,7 +81,7 @@ namespace UI.CardSystem
Logging.Debug($"[ProgressBarController] Showing progress {currentCount}/{maxCount}");
// Blink the NEWEST element (the one we just added)
// Blink the NEWEST element (the last one we just enabled)
// Newest element is at index (currentCount - 1)
int newestIndex = currentCount - 1;
if (newestIndex >= 0 && newestIndex < _progressElements.Length && currentCount > 0)

View File

@@ -29,6 +29,7 @@ namespace UI.CardSystem.StateMachine
// Runtime state
public bool IsNewCard { get; set; }
public int RepeatCardCount { get; set; }
public bool IsClickable { get; set; } = true;
// Events for external coordination (BoosterOpeningPage, etc.)
public event Action<CardContext> OnFlipComplete;

View File

@@ -15,7 +15,6 @@ namespace UI.CardSystem.StateMachine.States
public class CardEnlargedRepeatState : AppleState, IPointerClickHandler
{
[Header("State-Owned Visuals")]
[SerializeField] private GameObject progressBarContainer;
[SerializeField] private ProgressBarController progressBar;
private CardContext _context;
@@ -35,21 +34,11 @@ namespace UI.CardSystem.StateMachine.States
_originalScale = _context.RootTransform.localScale;
_waitingForTap = false;
// Show progress bar container
if (progressBarContainer != null)
{
progressBarContainer.SetActive(true);
}
// Enlarge the card
if (_context.Animator != null)
{
_context.Animator.PlayEnlarge(_settings.NewCardEnlargedScale);
}
// Show progress with blink animation
// Show progress bar
if (progressBar != null)
{
progressBar.gameObject.SetActive(true);
int currentCount = _context.RepeatCardCount + 1; // +1 because we just got this card
int maxCount = _settings.CardsToUpgrade;
@@ -60,6 +49,12 @@ namespace UI.CardSystem.StateMachine.States
Logging.Warning("[CardEnlargedRepeatState] ProgressBar component not assigned!");
OnProgressComplete();
}
// Enlarge the card
if (_context.Animator != null)
{
_context.Animator.PlayEnlarge(_settings.NewCardEnlargedScale);
}
}
private void OnProgressComplete()
@@ -170,9 +165,9 @@ namespace UI.CardSystem.StateMachine.States
_context.IsNewCard = true;
// Hide progress bar before transitioning
if (progressBarContainer != null)
if (progressBar != null)
{
progressBarContainer.SetActive(false);
progressBar.gameObject.SetActive(false);
}
// Transition to EnlargedNewState (card is already enlarged, will show NEW badge)
@@ -205,9 +200,9 @@ namespace UI.CardSystem.StateMachine.States
private void OnDisable()
{
// Hide progress bar when leaving state
if (progressBarContainer != null)
if (progressBar != null)
{
progressBarContainer.SetActive(false);
progressBar.gameObject.SetActive(false);
}
}
}

View File

@@ -1,91 +0,0 @@
using Core.SaveLoad;
using UnityEngine;
namespace UI.CardSystem.StateMachine.States
{
/// <summary>
/// Flipping state - handles the card flip animation from back to front.
/// Owns the CardBackVisual as a child GameObject.
/// </summary>
public class CardFlippingState : AppleState
{
[Header("State-Owned Visuals")]
[SerializeField] private GameObject cardBackVisual;
private CardContext _context;
private void Awake()
{
_context = GetComponentInParent<CardContext>();
}
public override void OnEnterState()
{
// Activate card back, hide card front
if (cardBackVisual != null)
{
cardBackVisual.SetActive(true);
}
if (_context.CardDisplay != null)
{
_context.CardDisplay.gameObject.SetActive(false);
}
// Play flip animation + scale punch
if (_context.Animator != null)
{
_context.Animator.PlayFlip(
cardBack: cardBackVisual.transform,
cardFront: _context.CardDisplay.transform,
onComplete: OnFlipComplete
);
_context.Animator.PlayFlipScalePunch();
}
}
private void OnFlipComplete()
{
// Fire flip complete event
_context.FireFlipComplete();
// Transition based on whether this is a new card or repeat
if (_context.IsNewCard)
{
_context.StateMachine.ChangeState("EnlargedNewState");
}
else if (_context.CardData.Rarity == AppleHills.Data.CardSystem.CardRarity.Legendary)
{
// Legendary repeat - skip enlarge, they can't upgrade
// Add to inventory and move to revealed state
Data.CardSystem.CardSystemManager.Instance.AddCardToInventoryDelayed(_context.CardData);
_context.StateMachine.ChangeState("RevealedState");
}
else if (_context.RepeatCardCount > 0)
{
_context.StateMachine.ChangeState("EnlargedRepeatState");
}
else
{
_context.StateMachine.ChangeState("RevealedState");
}
}
private void OnDisable()
{
// Hide card back when leaving state
if (cardBackVisual != null)
{
cardBackVisual.SetActive(false);
}
// Ensure card front is visible
if (_context?.CardDisplay != null)
{
_context.CardDisplay.gameObject.SetActive(true);
}
}
}
}

View File

@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 7223d6cab8d94f74b00a6a538291850a
timeCreated: 1762884650

View File

@@ -82,13 +82,61 @@ namespace UI.CardSystem.StateMachine.States
public void OnPointerClick(PointerEventData eventData)
{
// Click to flip - transition to flipping state
_context.StateMachine.ChangeState("FlippingState");
// Check if card is clickable (prevents multi-flip in booster opening)
if (!_context.IsClickable)
{
Logging.Debug($"[CardIdleState] Card is not clickable, ignoring click");
return;
}
// Stop idle hover and pointer interactions
StopIdleHover();
// Play flip animation directly (no state transition yet)
if (_context.Animator != null)
{
_context.Animator.PlayFlip(
cardBack: cardBackVisual != null ? cardBackVisual.transform : null,
cardFront: _context.CardDisplay != null ? _context.CardDisplay.transform : null,
onComplete: OnFlipComplete
);
_context.Animator.PlayFlipScalePunch();
}
}
private void OnDisable()
private void OnFlipComplete()
{
// Fire flip complete event
_context.FireFlipComplete();
// Transition based on whether this is a new card or repeat
if (_context.IsNewCard)
{
_context.StateMachine.ChangeState("EnlargedNewState");
}
else if (_context.CardData != null && _context.CardData.Rarity == AppleHills.Data.CardSystem.CardRarity.Legendary)
{
// Legendary repeat - skip enlarge, they can't upgrade
// Add to inventory and move to revealed state
if (Data.CardSystem.CardSystemManager.Instance != null)
{
Data.CardSystem.CardSystemManager.Instance.AddCardToInventoryDelayed(_context.CardData);
}
_context.StateMachine.ChangeState("RevealedState");
}
else if (_context.RepeatCardCount > 0)
{
_context.StateMachine.ChangeState("EnlargedRepeatState");
}
else
{
_context.StateMachine.ChangeState("RevealedState");
}
}
private void StopIdleHover()
{
// Stop idle hover animation when leaving state
if (_idleHoverTween != null)
{
_idleHoverTween.Stop();
@@ -101,9 +149,15 @@ namespace UI.CardSystem.StateMachine.States
_context.Animator.AnimateAnchoredPosition(_originalPosition, 0.3f);
}
}
}
private void OnDisable()
{
// Stop idle hover animation when leaving state
StopIdleHover();
// Reset scale
if (_context.Animator != null)
if (_context?.Animator != null)
{
_context.Animator.AnimateScale(Vector3.one, 0.2f);
}

View File

@@ -1,4 +1,5 @@
using Core.SaveLoad;
using UnityEngine;
namespace UI.CardSystem.StateMachine.States
{
@@ -7,9 +8,14 @@ namespace UI.CardSystem.StateMachine.States
/// This is the "waiting" state:
/// - In booster flow: waiting for all cards to finish before animating to album
/// - In album placement flow: waiting to be dragged to a slot
/// Shows small idle badges for NEW or REPEAT cards.
/// </summary>
public class CardRevealedState : AppleState
{
[Header("State-Owned Visuals")]
[SerializeField] private UnityEngine.GameObject newCardIdleBadge;
[SerializeField] private UnityEngine.GameObject repeatCardIdleBadge;
private CardContext _context;
private void Awake()
@@ -20,9 +26,43 @@ namespace UI.CardSystem.StateMachine.States
public override void OnEnterState()
{
// Card is at normal size, fully revealed
// Show appropriate idle badge
if (_context.IsNewCard)
{
if (newCardIdleBadge != null)
newCardIdleBadge.SetActive(true);
if (repeatCardIdleBadge != null)
repeatCardIdleBadge.SetActive(false);
}
else if (_context.RepeatCardCount > 0)
{
if (newCardIdleBadge != null)
newCardIdleBadge.SetActive(false);
if (repeatCardIdleBadge != null)
repeatCardIdleBadge.SetActive(true);
}
else
{
// Neither new nor repeat - hide both
if (newCardIdleBadge != null)
newCardIdleBadge.SetActive(false);
if (repeatCardIdleBadge != null)
repeatCardIdleBadge.SetActive(false);
}
// Fire interaction complete event (for BoosterOpeningPage tracking)
_context.FireCardInteractionComplete();
}
private void OnDisable()
{
// Hide badges when leaving state
if (newCardIdleBadge != null)
newCardIdleBadge.SetActive(false);
if (repeatCardIdleBadge != null)
repeatCardIdleBadge.SetActive(false);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: be244d3b69267554682b35f0c9d12151
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,385 @@
using System.Collections.Generic;
using AppleHills.Data.CardSystem;
using Core;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UI.CardSystem.StateMachine;
using UI.CardSystem.StateMachine.States;
namespace UI.CardSystem.Testing
{
/// <summary>
/// Test controller for card state machine testing.
/// Provides UI controls to manually test state transitions, animations, and flows.
/// </summary>
public class CardTestController : MonoBehaviour
{
[Header("Test Card")]
[SerializeField] private Card testCard;
[SerializeField] private CardData testCardData;
[Header("Album Slots for Drag Testing")]
[SerializeField] private AlbumCardSlot slot1;
[SerializeField] private AlbumCardSlot slot2;
[Header("UI References")]
[SerializeField] private TextMeshProUGUI eventLogText;
[SerializeField] private Toggle isNewToggle;
[SerializeField] private Slider repeatCountSlider;
[SerializeField] private TextMeshProUGUI repeatCountLabel;
[SerializeField] private TMP_Dropdown rarityDropdown;
[SerializeField] private Toggle isClickableToggle;
[SerializeField] private TextMeshProUGUI currentStateText;
private List<string> _eventLog = new List<string>();
private CardContext _cardContext;
private Vector3 _originalCardPosition;
private void Awake()
{
if (testCard != null)
{
_cardContext = testCard.GetComponent<CardContext>();
_originalCardPosition = testCard.transform.position;
// Subscribe to all card events
if (_cardContext != null)
{
_cardContext.OnFlipComplete += OnCardFlipComplete;
_cardContext.OnCardDismissed += OnCardDismissed;
_cardContext.OnCardInteractionComplete += OnCardInteractionComplete;
_cardContext.OnUpgradeTriggered += OnCardUpgradeTriggered;
}
}
// Setup UI listeners
if (repeatCountSlider != null)
{
repeatCountSlider.onValueChanged.AddListener(OnRepeatCountChanged);
}
if (isClickableToggle != null)
{
isClickableToggle.onValueChanged.AddListener(OnIsClickableToggled);
}
}
private void Start()
{
// Initialize card with test data
if (testCard != null && testCardData != null && _cardContext != null)
{
_cardContext.SetupCard(testCardData, isNew: true, repeatCount: 0);
}
LogEvent("Card Test Scene Initialized");
UpdateCurrentStateDisplay();
}
private void Update()
{
// Update current state display every frame
if (Time.frameCount % 30 == 0) // Every 0.5 seconds at 60fps
{
UpdateCurrentStateDisplay();
}
}
#region State Transition Buttons
public void TransitionToIdleState()
{
_cardContext?.StateMachine.ChangeState("IdleState");
LogEvent("Transitioned to IdleState");
}
public void TransitionToRevealedState()
{
_cardContext?.StateMachine.ChangeState("RevealedState");
LogEvent("Transitioned to RevealedState");
}
public void TransitionToEnlargedNewState()
{
_cardContext?.StateMachine.ChangeState("EnlargedNewState");
LogEvent("Transitioned to EnlargedNewState");
}
public void TransitionToEnlargedRepeatState()
{
_cardContext?.StateMachine.ChangeState("EnlargedRepeatState");
LogEvent("Transitioned to EnlargedRepeatState");
}
public void TransitionToDraggingState()
{
_cardContext?.StateMachine.ChangeState("DraggingState");
LogEvent("Transitioned to DraggingState");
}
public void TransitionToPlacedInSlotState()
{
_cardContext?.StateMachine.ChangeState("PlacedInSlotState");
LogEvent("Transitioned to PlacedInSlotState");
}
public void TransitionToAlbumEnlargedState()
{
_cardContext?.StateMachine.ChangeState("AlbumEnlargedState");
LogEvent("Transitioned to AlbumEnlargedState");
}
#endregion
#region Simulation Buttons
public void SimulateNewCardFlow()
{
if (_cardContext == null) return;
_cardContext.IsNewCard = true;
_cardContext.RepeatCardCount = 0;
_cardContext.IsClickable = true;
TransitionToIdleState();
LogEvent("Simulating NEW CARD flow - click card to flip");
}
public void SimulateRepeatCardFlow()
{
if (_cardContext == null) return;
int repeatCount = Mathf.RoundToInt(repeatCountSlider.value);
_cardContext.IsNewCard = false;
_cardContext.RepeatCardCount = repeatCount;
_cardContext.IsClickable = true;
TransitionToIdleState();
LogEvent($"Simulating REPEAT CARD flow ({repeatCount}/5) - click card to flip");
}
public void SimulateUpgradeFlow()
{
if (_cardContext == null) return;
_cardContext.IsNewCard = false;
_cardContext.RepeatCardCount = 5; // Trigger upgrade
_cardContext.IsClickable = true;
TransitionToIdleState();
LogEvent("Simulating UPGRADE flow (5/5) - click card to flip and auto-upgrade");
}
public void SimulateAlbumPlacementFlow()
{
if (_cardContext == null) return;
_cardContext.IsNewCard = false;
_cardContext.RepeatCardCount = 0;
TransitionToRevealedState();
LogEvent("Simulating ALBUM PLACEMENT - drag card to slot");
}
#endregion
#region Card Setup Controls
public void ApplyCardSetup()
{
if (_cardContext == null) return;
bool isNew = isNewToggle != null && isNewToggle.isOn;
int repeatCount = repeatCountSlider != null ? Mathf.RoundToInt(repeatCountSlider.value) : 0;
_cardContext.IsNewCard = isNew;
_cardContext.RepeatCardCount = repeatCount;
// Apply rarity if needed
if (rarityDropdown != null && testCardData != null)
{
testCardData.Rarity = (CardRarity)rarityDropdown.value;
}
LogEvent($"Card setup applied: IsNew={isNew}, RepeatCount={repeatCount}");
}
private void OnRepeatCountChanged(float value)
{
if (repeatCountLabel != null)
{
repeatCountLabel.text = $"{Mathf.RoundToInt(value)}/5";
}
}
private void OnIsClickableToggled(bool isClickable)
{
if (_cardContext != null)
{
_cardContext.IsClickable = isClickable;
LogEvent($"Card clickable: {isClickable}");
}
}
#endregion
#region Animation Test Buttons
public void PlayFlipAnimation()
{
// Transition to IdleState and programmatically trigger flip
TransitionToIdleState();
// Get IdleState and trigger click
var idleState = testCard.GetComponentInChildren<CardIdleState>();
if (idleState != null)
{
idleState.OnPointerClick(null);
LogEvent("Playing flip animation");
}
}
public void PlayEnlargeAnimation()
{
if (_cardContext?.Animator != null)
{
_cardContext.Animator.PlayEnlarge(2.5f);
LogEvent("Playing enlarge animation");
}
}
public void PlayShrinkAnimation()
{
if (_cardContext?.Animator != null)
{
_cardContext.Animator.PlayShrink(Vector3.one, null);
LogEvent("Playing shrink animation");
}
}
public void StartIdleHoverAnimation()
{
if (_cardContext?.Animator != null)
{
_cardContext.Animator.StartIdleHover(10f, 1.5f);
LogEvent("Started idle hover animation");
}
}
public void StopIdleHoverAnimation()
{
// Stopping hover is handled by IdleState's OnDisable
LogEvent("Idle hover stopped (change state to stop)");
}
#endregion
#region Utility Buttons
public void ResetCardPosition()
{
if (testCard != null)
{
testCard.transform.position = _originalCardPosition;
testCard.transform.localScale = Vector3.one;
LogEvent("Card position reset");
}
}
public void ClearEventLog()
{
_eventLog.Clear();
UpdateEventLog();
LogEvent("Event log cleared");
}
#endregion
#region Event Handlers
private void OnCardFlipComplete(CardContext context)
{
LogEvent($"Event: OnFlipComplete - IsNew={context.IsNewCard}, RepeatCount={context.RepeatCardCount}");
}
private void OnCardDismissed(CardContext context)
{
LogEvent("Event: OnCardDismissed");
}
private void OnCardInteractionComplete(CardContext context)
{
LogEvent("Event: OnCardInteractionComplete");
}
private void OnCardUpgradeTriggered(CardContext context)
{
LogEvent($"Event: OnUpgradeTriggered - New Rarity={context.CardData?.Rarity}");
}
#endregion
#region Event Log
private void LogEvent(string message)
{
string timestamp = $"[{Time.time:F2}s]";
_eventLog.Add($"{timestamp} {message}");
// Keep only last 20 events
if (_eventLog.Count > 20)
{
_eventLog.RemoveAt(0);
}
UpdateEventLog();
Logging.Debug($"[CardTest] {message}");
}
private void UpdateEventLog()
{
if (eventLogText != null)
{
eventLogText.text = string.Join("\n", _eventLog);
}
}
private void UpdateCurrentStateDisplay()
{
if (currentStateText != null && _cardContext != null && _cardContext.StateMachine != null)
{
// Get the active state by checking which child state GameObject is active
string stateName = "Unknown";
Transform stateMachineTransform = _cardContext.StateMachine.transform;
for (int i = 0; i < stateMachineTransform.childCount; i++)
{
Transform child = stateMachineTransform.GetChild(i);
if (child.gameObject.activeSelf)
{
stateName = child.name;
break;
}
}
currentStateText.text = $"Current State: {stateName}";
}
}
#endregion
private void OnDestroy()
{
// Unsubscribe from events
if (_cardContext != null)
{
_cardContext.OnFlipComplete -= OnCardFlipComplete;
_cardContext.OnCardDismissed -= OnCardDismissed;
_cardContext.OnCardInteractionComplete -= OnCardInteractionComplete;
_cardContext.OnUpgradeTriggered -= OnCardUpgradeTriggered;
}
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1d6de9a5b64e791409043fb8c858bda2