Update the card kerfufle
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
using Core.SaveLoad;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
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.
|
||||
/// </summary>
|
||||
public class CardEnlargedRepeatState : AppleState, IPointerClickHandler
|
||||
{
|
||||
[Header("State-Owned Visuals")]
|
||||
[SerializeField] private GameObject progressBarContainer;
|
||||
[SerializeField] private Image progressBarFill;
|
||||
[SerializeField] private TextMeshProUGUI progressText;
|
||||
[SerializeField] private int cardsToUpgrade = 5;
|
||||
|
||||
private CardContext _context;
|
||||
private Vector3 _originalScale;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_context = GetComponentInParent<CardContext>();
|
||||
}
|
||||
|
||||
public override void OnEnterState()
|
||||
{
|
||||
// Store original scale
|
||||
_originalScale = _context.RootTransform.localScale;
|
||||
|
||||
// Show progress bar
|
||||
if (progressBarContainer != null)
|
||||
{
|
||||
progressBarContainer.SetActive(true);
|
||||
UpdateProgressBar();
|
||||
}
|
||||
|
||||
// Enlarge the card
|
||||
if (_context.Animator != null)
|
||||
{
|
||||
_context.Animator.PlayEnlarge();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateProgressBar()
|
||||
{
|
||||
int currentCount = _context.RepeatCardCount;
|
||||
float progress = (float)currentCount / cardsToUpgrade;
|
||||
|
||||
if (progressBarFill != null)
|
||||
{
|
||||
progressBarFill.fillAmount = progress;
|
||||
}
|
||||
|
||||
if (progressText != null)
|
||||
{
|
||||
progressText.text = $"{currentCount}/{cardsToUpgrade}";
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
// Tap to dismiss - shrink back and transition to revealed state
|
||||
if (_context.Animator != null)
|
||||
{
|
||||
_context.Animator.PlayShrink(_originalScale, onComplete: () =>
|
||||
{
|
||||
_context.StateMachine.ChangeState("RevealedState");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
// Hide progress bar when leaving state
|
||||
if (progressBarContainer != null)
|
||||
{
|
||||
progressBarContainer.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user