Fix up card flows, align with the old 1:1
This commit is contained in:
@@ -1,27 +1,27 @@
|
||||
using Core.SaveLoad;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using AppleHills.Core.Settings;
|
||||
using Core;
|
||||
using AppleHills.Data.CardSystem;
|
||||
|
||||
namespace UI.CardSystem.StateMachine.States
|
||||
{
|
||||
/// <summary>
|
||||
/// Enlarged state for REPEAT cards - shows progress bar toward next rarity upgrade.
|
||||
/// Owns the ProgressBarUI as a child GameObject.
|
||||
/// Uses ProgressBarController to animate progress filling.
|
||||
/// Auto-upgrades card when threshold is reached.
|
||||
/// </summary>
|
||||
public class CardEnlargedRepeatState : AppleState, IPointerClickHandler
|
||||
{
|
||||
[Header("State-Owned Visuals")]
|
||||
[SerializeField] private GameObject progressBarContainer;
|
||||
[SerializeField] private Image progressBarFill;
|
||||
[SerializeField] private TextMeshProUGUI progressText;
|
||||
[SerializeField] private ProgressBarController progressBar;
|
||||
|
||||
private CardContext _context;
|
||||
private ICardSystemSettings _settings;
|
||||
private Vector3 _originalScale;
|
||||
private bool _waitingForTap = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -33,12 +33,12 @@ namespace UI.CardSystem.StateMachine.States
|
||||
{
|
||||
// Store original scale
|
||||
_originalScale = _context.RootTransform.localScale;
|
||||
_waitingForTap = false;
|
||||
|
||||
// Show progress bar
|
||||
// Show progress bar container
|
||||
if (progressBarContainer != null)
|
||||
{
|
||||
progressBarContainer.SetActive(true);
|
||||
UpdateProgressBar();
|
||||
}
|
||||
|
||||
// Enlarge the card
|
||||
@@ -46,27 +46,148 @@ namespace UI.CardSystem.StateMachine.States
|
||||
{
|
||||
_context.Animator.PlayEnlarge(_settings.NewCardEnlargedScale);
|
||||
}
|
||||
|
||||
// Show progress with blink animation
|
||||
if (progressBar != null)
|
||||
{
|
||||
int currentCount = _context.RepeatCardCount + 1; // +1 because we just got this card
|
||||
int maxCount = _settings.CardsToUpgrade;
|
||||
|
||||
progressBar.ShowProgress(currentCount, maxCount, OnProgressComplete);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logging.Warning("[CardEnlargedRepeatState] ProgressBar component not assigned!");
|
||||
OnProgressComplete();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateProgressBar()
|
||||
private void OnProgressComplete()
|
||||
{
|
||||
int currentCount = _context.RepeatCardCount;
|
||||
int cardsToUpgrade = _settings.CardsToUpgrade;
|
||||
float progress = (float)currentCount / cardsToUpgrade;
|
||||
|
||||
if (progressBarFill != null)
|
||||
// Check if this card triggers an upgrade
|
||||
if (ShouldTriggerUpgrade())
|
||||
{
|
||||
progressBarFill.fillAmount = progress;
|
||||
Logging.Debug($"[CardEnlargedRepeatState] Card will trigger upgrade! ({_context.RepeatCardCount + 1}/{_settings.CardsToUpgrade})");
|
||||
TriggerUpgrade();
|
||||
}
|
||||
else
|
||||
{
|
||||
// No upgrade - just wait for tap to dismiss
|
||||
Logging.Debug($"[CardEnlargedRepeatState] Progress shown, waiting for tap to dismiss");
|
||||
_waitingForTap = true;
|
||||
}
|
||||
}
|
||||
|
||||
private bool ShouldTriggerUpgrade()
|
||||
{
|
||||
int currentCount = _context.RepeatCardCount + 1; // +1 for the card we just got
|
||||
CardRarity currentRarity = _context.CardData.Rarity;
|
||||
|
||||
// Can't upgrade if already Legendary
|
||||
if (currentRarity == CardRarity.Legendary)
|
||||
return false;
|
||||
|
||||
// Check if we've hit the threshold
|
||||
return currentCount >= _settings.CardsToUpgrade;
|
||||
}
|
||||
|
||||
private void TriggerUpgrade()
|
||||
{
|
||||
_context.FireUpgradeTriggered();
|
||||
|
||||
CardData cardData = _context.CardData;
|
||||
CardRarity oldRarity = cardData.Rarity;
|
||||
CardRarity newRarity = oldRarity + 1;
|
||||
|
||||
Logging.Debug($"[CardEnlargedRepeatState] Upgrading card from {oldRarity} to {newRarity}");
|
||||
|
||||
// Get the existing card at lower rarity from inventory
|
||||
CardData existingLowerRarity = Data.CardSystem.CardSystemManager.Instance.GetCardInventory().GetCard(cardData.Name, oldRarity);
|
||||
|
||||
if (existingLowerRarity != null)
|
||||
{
|
||||
// Reset lower rarity count to 0
|
||||
existingLowerRarity.CopiesOwned = 0;
|
||||
}
|
||||
|
||||
if (progressText != null)
|
||||
// Create upgraded card data
|
||||
CardData upgradedCard = new CardData(cardData);
|
||||
upgradedCard.Rarity = newRarity;
|
||||
upgradedCard.CopiesOwned = 1;
|
||||
|
||||
// Check if this card is new at the higher rarity
|
||||
bool isNewAtHigherRarity = Data.CardSystem.CardSystemManager.Instance.IsCardNew(upgradedCard, out CardData existingHigherRarity);
|
||||
|
||||
// Add to inventory
|
||||
Data.CardSystem.CardSystemManager.Instance.GetCardInventory().AddCard(upgradedCard);
|
||||
|
||||
// Update our card data to show upgraded rarity
|
||||
cardData.Rarity = newRarity;
|
||||
|
||||
// Update the CardDisplay to show new rarity
|
||||
if (_context.CardDisplay != null)
|
||||
{
|
||||
progressText.text = $"{currentCount}/{cardsToUpgrade}";
|
||||
_context.CardDisplay.SetupCard(cardData);
|
||||
}
|
||||
|
||||
// Determine next transition
|
||||
if (isNewAtHigherRarity || newRarity == CardRarity.Legendary)
|
||||
{
|
||||
// Show as NEW at higher rarity
|
||||
Logging.Debug($"[CardEnlargedRepeatState] Card is NEW at {newRarity}, transitioning to EnlargedNewState");
|
||||
TransitionToNewCardView();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Already have copies at higher rarity - show progress there too
|
||||
int ownedAtHigherRarity = existingHigherRarity.CopiesOwned;
|
||||
Logging.Debug($"[CardEnlargedRepeatState] Card is REPEAT at {newRarity} ({ownedAtHigherRarity}/{_settings.CardsToUpgrade}), showing progress");
|
||||
|
||||
// Update context for higher rarity
|
||||
_context.IsNewCard = false;
|
||||
_context.RepeatCardCount = ownedAtHigherRarity;
|
||||
|
||||
// Re-enter this state with updated data (will show progress for higher rarity)
|
||||
// First hide current progress, then show new progress
|
||||
if (progressBar != null)
|
||||
{
|
||||
progressBar.ShowProgress(ownedAtHigherRarity + 1, _settings.CardsToUpgrade, () =>
|
||||
{
|
||||
// After showing progress at higher rarity, transition to NEW
|
||||
TransitionToNewCardView();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
TransitionToNewCardView();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TransitionToNewCardView()
|
||||
{
|
||||
// Update context to show as new card
|
||||
_context.IsNewCard = true;
|
||||
|
||||
// Hide progress bar before transitioning
|
||||
if (progressBarContainer != null)
|
||||
{
|
||||
progressBarContainer.SetActive(false);
|
||||
}
|
||||
|
||||
// Transition to EnlargedNewState (card is already enlarged, will show NEW badge)
|
||||
_context.StateMachine.ChangeState("EnlargedNewState");
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
// Only respond to clicks if waiting for tap
|
||||
if (!_waitingForTap)
|
||||
return;
|
||||
|
||||
// Fire dismissed event
|
||||
_context.FireCardDismissed();
|
||||
|
||||
// Tap to dismiss - shrink back and transition to revealed state
|
||||
if (_context.Animator != null)
|
||||
{
|
||||
@@ -75,6 +196,10 @@ namespace UI.CardSystem.StateMachine.States
|
||||
_context.StateMachine.ChangeState("RevealedState");
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_context.StateMachine.ChangeState("RevealedState");
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
|
||||
Reference in New Issue
Block a user