using Core.SaveLoad; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; using AppleHills.Core.Settings; using Core; namespace UI.CardSystem.StateMachine.States { /// /// Enlarged state for REPEAT cards - shows progress bar toward next rarity upgrade. /// Owns the ProgressBarUI as a child GameObject. /// public class CardEnlargedRepeatState : AppleState, IPointerClickHandler { [Header("State-Owned Visuals")] [SerializeField] private GameObject progressBarContainer; [SerializeField] private Image progressBarFill; [SerializeField] private TextMeshProUGUI progressText; private CardContext _context; private ICardSystemSettings _settings; private Vector3 _originalScale; private void Awake() { _context = GetComponentInParent(); _settings = GameManager.GetSettingsObject(); } 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(_settings.NewCardEnlargedScale); } } private void UpdateProgressBar() { int currentCount = _context.RepeatCardCount; int cardsToUpgrade = _settings.CardsToUpgrade; 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); } } } }