Refactor, cleanup code and add documentaiton
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
using Core.SaveLoad;
|
||||
using UnityEngine;
|
||||
using AppleHills.Core.Settings;
|
||||
using Core;
|
||||
|
||||
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>
|
||||
public class CardEnlargedNewState : AppleState, ICardClickHandler
|
||||
{
|
||||
[Header("State-Owned Visuals")]
|
||||
[SerializeField] private GameObject newCardBadge;
|
||||
|
||||
private CardContext _context;
|
||||
private ICardSystemSettings _settings;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_context = GetComponentInParent<CardContext>();
|
||||
_settings = GameManager.GetSettingsObject<ICardSystemSettings>();
|
||||
}
|
||||
|
||||
public override void OnEnterState()
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Check if we're already enlarged (coming from upgrade flow)
|
||||
bool alreadyEnlarged = _context.RootTransform.localScale.x >= _settings.NewCardEnlargedScale * 0.9f;
|
||||
|
||||
if (!alreadyEnlarged)
|
||||
{
|
||||
// Normal flow - enlarge the card
|
||||
if (_context.Animator != null)
|
||||
{
|
||||
_context.Animator.PlayEnlarge(_settings.NewCardEnlargedScale);
|
||||
}
|
||||
}
|
||||
|
||||
// Show NEW badge
|
||||
if (newCardBadge != null)
|
||||
{
|
||||
newCardBadge.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCardClicked(CardContext context)
|
||||
{
|
||||
// Tap to dismiss - shrink back to original scale and transition to revealed state
|
||||
if (context.Animator != null)
|
||||
{
|
||||
context.Animator.PlayShrink(context.OriginalScale, onComplete: () =>
|
||||
{
|
||||
context.StateMachine.ChangeState(CardStateNames.Revealed);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback if no animator
|
||||
context.StateMachine.ChangeState(CardStateNames.Revealed);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
// Hide NEW badge when leaving state
|
||||
if (newCardBadge != null)
|
||||
{
|
||||
newCardBadge.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user