Files
AppleHillsProduction/Assets/Scripts/CardSystem/StateMachine/States/CardEnlargedNewState.cs

81 lines
2.6 KiB
C#
Raw Normal View History

2025-11-11 20:25:23 +01:00
using Core.SaveLoad;
using UnityEngine;
2025-11-12 09:24:27 +01:00
using AppleHills.Core.Settings;
using Core;
2025-11-11 20:25:23 +01:00
namespace UI.CardSystem.StateMachine.States
{
/// <summary>
/// Enlarged state for NEW cards - shows "NEW CARD" badge and waits for tap to dismiss.
/// Owns the NewCardBadge as a child GameObject.
/// </summary>
2025-11-16 20:35:54 +01:00
public class CardEnlargedNewState : AppleState, ICardClickHandler
2025-11-11 20:25:23 +01:00
{
[Header("State-Owned Visuals")]
[SerializeField] private GameObject newCardBadge;
private CardContext _context;
2025-11-12 09:24:27 +01:00
private ICardSystemSettings _settings;
2025-11-11 20:25:23 +01:00
private void Awake()
{
_context = GetComponentInParent<CardContext>();
2025-11-12 09:24:27 +01:00
_settings = GameManager.GetSettingsObject<ICardSystemSettings>();
2025-11-11 20:25:23 +01:00
}
public override void OnEnterState()
{
2025-11-12 20:26:51 +01:00
// Ensure card front is visible and facing camera
if (_context.CardDisplay != null)
{
_context.CardDisplay.gameObject.SetActive(true);
_context.CardDisplay.transform.localRotation = Quaternion.Euler(0, 0, 0);
}
2025-11-16 20:35:54 +01:00
// Check if we're already enlarged (coming from upgrade flow)
bool alreadyEnlarged = _context.RootTransform.localScale.x >= _settings.NewCardEnlargedScale * 0.9f;
2025-11-11 20:25:23 +01:00
2025-11-16 20:35:54 +01:00
if (!alreadyEnlarged)
2025-11-11 20:25:23 +01:00
{
2025-11-16 20:35:54 +01:00
// Normal flow - enlarge the card
if (_context.Animator != null)
{
_context.Animator.PlayEnlarge(_settings.NewCardEnlargedScale);
}
2025-11-11 20:25:23 +01:00
}
2025-11-16 20:35:54 +01:00
// Show NEW badge
if (newCardBadge != null)
2025-11-11 20:25:23 +01:00
{
2025-11-16 20:35:54 +01:00
newCardBadge.SetActive(true);
2025-11-11 20:25:23 +01:00
}
}
2025-11-16 20:35:54 +01:00
public void OnCardClicked(CardContext context)
2025-11-11 20:25:23 +01:00
{
2025-11-16 20:35:54 +01:00
// Tap to dismiss - shrink back to original scale and transition to revealed state
if (context.Animator != null)
2025-11-11 20:25:23 +01:00
{
2025-11-16 20:35:54 +01:00
context.Animator.PlayShrink(context.OriginalScale, onComplete: () =>
2025-11-11 20:25:23 +01:00
{
context.StateMachine.ChangeState(CardStateNames.Revealed);
2025-11-11 20:25:23 +01:00
});
}
else
{
// Fallback if no animator
context.StateMachine.ChangeState(CardStateNames.Revealed);
}
2025-11-11 20:25:23 +01:00
}
private void OnDisable()
{
// Hide NEW badge when leaving state
if (newCardBadge != null)
{
newCardBadge.SetActive(false);
}
}
}
}