Make cards use settings
This commit is contained in:
committed by
Michal Pikulski
parent
4fdbbb0aa8
commit
a6471ede45
@@ -5,6 +5,7 @@ using Pixelplacement;
|
||||
using Pixelplacement.TweenSystem;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using AppleHills.Core.Settings;
|
||||
|
||||
namespace UI.CardSystem
|
||||
{
|
||||
@@ -22,23 +23,15 @@ namespace UI.CardSystem
|
||||
|
||||
[Header("Idle Hover Animation")]
|
||||
[SerializeField] private bool enableIdleHover = true;
|
||||
[SerializeField] private float idleHoverHeight = 10f;
|
||||
[SerializeField] private float idleHoverDuration = 1.5f;
|
||||
[SerializeField] private float hoverScaleMultiplier = 1.05f;
|
||||
|
||||
[Header("Flip Animation")]
|
||||
[SerializeField] private float flipDuration = 0.6f;
|
||||
[SerializeField] private float flipScalePunch = 1.1f;
|
||||
|
||||
[Header("New/Repeat Card Display")]
|
||||
[SerializeField] private GameObject newCardText;
|
||||
[SerializeField] private GameObject newCardIdleText;
|
||||
[SerializeField] private GameObject repeatText;
|
||||
[SerializeField] private GameObject progressBarContainer;
|
||||
[SerializeField] private int cardsToUpgrade = 5;
|
||||
[SerializeField] private float enlargedScale = 1.5f;
|
||||
|
||||
// State
|
||||
private ICardSystemSettings _settings;
|
||||
private bool _isFlipped = false;
|
||||
private bool _isFlipping = false;
|
||||
private TweenBase _idleHoverTween;
|
||||
@@ -57,10 +50,12 @@ namespace UI.CardSystem
|
||||
|
||||
public bool IsFlipped => _isFlipped;
|
||||
public CardData CardData => _cardData;
|
||||
public int CardsToUpgrade => cardsToUpgrade; // Expose upgrade threshold
|
||||
public int CardsToUpgrade => _settings?.CardsToUpgrade ?? 5;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_settings = GameManager.GetSettingsObject<ICardSystemSettings>();
|
||||
|
||||
// Auto-find CardDisplay if not assigned
|
||||
if (cardDisplay == null && cardFrontObject != null)
|
||||
{
|
||||
@@ -149,15 +144,18 @@ namespace UI.CardSystem
|
||||
// Card back: 0° → 90° (rotates away)
|
||||
// Card front: 180° → 90° → 0° (rotates into view)
|
||||
|
||||
float flipDur = _settings.FlipDuration;
|
||||
float flipPunch = _settings.FlipScalePunch;
|
||||
|
||||
// Phase 1: Rotate both to 90 degrees (edge view)
|
||||
if (cardBackObject != null)
|
||||
{
|
||||
Tween.LocalRotation(cardBackObject.transform, Quaternion.Euler(0, 90, 0), flipDuration * 0.5f, 0f, Tween.EaseInOut);
|
||||
Tween.LocalRotation(cardBackObject.transform, Quaternion.Euler(0, 90, 0), flipDur * 0.5f, 0f, Tween.EaseInOut);
|
||||
}
|
||||
|
||||
if (cardFrontObject != null)
|
||||
{
|
||||
Tween.LocalRotation(cardFrontObject.transform, Quaternion.Euler(0, 90, 0), flipDuration * 0.5f, 0f, Tween.EaseInOut,
|
||||
Tween.LocalRotation(cardFrontObject.transform, Quaternion.Euler(0, 90, 0), flipDur * 0.5f, 0f, Tween.EaseInOut,
|
||||
completeCallback: () =>
|
||||
{
|
||||
// At edge (90°), switch visibility
|
||||
@@ -167,7 +165,7 @@ namespace UI.CardSystem
|
||||
cardFrontObject.SetActive(true);
|
||||
|
||||
// Phase 2: Rotate front from 90 to 0 (show at correct orientation)
|
||||
Tween.LocalRotation(cardFrontObject.transform, Quaternion.Euler(0, 0, 0), flipDuration * 0.5f, 0f, Tween.EaseInOut,
|
||||
Tween.LocalRotation(cardFrontObject.transform, Quaternion.Euler(0, 0, 0), flipDur * 0.5f, 0f, Tween.EaseInOut,
|
||||
completeCallback: () =>
|
||||
{
|
||||
_isFlipped = true;
|
||||
@@ -181,10 +179,10 @@ namespace UI.CardSystem
|
||||
|
||||
// Scale punch during flip for extra juice
|
||||
Vector3 originalScale = transform.localScale;
|
||||
Tween.LocalScale(transform, originalScale * flipScalePunch, flipDuration * 0.5f, 0f, Tween.EaseOutBack,
|
||||
Tween.LocalScale(transform, originalScale * flipPunch, flipDur * 0.5f, 0f, Tween.EaseOutBack,
|
||||
completeCallback: () =>
|
||||
{
|
||||
Tween.LocalScale(transform, originalScale, flipDuration * 0.5f, 0f, Tween.EaseInBack);
|
||||
Tween.LocalScale(transform, originalScale, flipDur * 0.5f, 0f, Tween.EaseInBack);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -201,7 +199,7 @@ namespace UI.CardSystem
|
||||
return;
|
||||
|
||||
Vector2 originalPos = rectTransform.anchoredPosition;
|
||||
Vector2 targetPos = originalPos + Vector2.up * idleHoverHeight;
|
||||
Vector2 targetPos = originalPos + Vector2.up * _settings.IdleHoverHeight;
|
||||
|
||||
_idleHoverTween = Tween.Value(0f, 1f,
|
||||
(val) =>
|
||||
@@ -212,7 +210,7 @@ namespace UI.CardSystem
|
||||
rectTransform.anchoredPosition = Vector2.Lerp(originalPos, targetPos, t);
|
||||
}
|
||||
},
|
||||
idleHoverDuration, 0f, Tween.EaseInOut, Tween.LoopType.Loop);
|
||||
_settings.IdleHoverDuration, 0f, Tween.EaseInOut, Tween.LoopType.Loop);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -242,7 +240,7 @@ namespace UI.CardSystem
|
||||
return;
|
||||
|
||||
// Scale up slightly on hover
|
||||
Tween.LocalScale(transform, Vector3.one * hoverScaleMultiplier, 0.2f, 0f, Tween.EaseOutBack);
|
||||
Tween.LocalScale(transform, Vector3.one * _settings.HoverScaleMultiplier, 0.2f, 0f, Tween.EaseOutBack);
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
@@ -492,7 +490,7 @@ namespace UI.CardSystem
|
||||
/// </summary>
|
||||
private void EnlargeCard()
|
||||
{
|
||||
Tween.LocalScale(transform, Vector3.one * enlargedScale, 0.3f, 0f, Tween.EaseOutBack);
|
||||
Tween.LocalScale(transform, Vector3.one * _settings.NewCardEnlargedScale, _settings.ScaleDuration, 0f, Tween.EaseOutBack);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -500,7 +498,7 @@ namespace UI.CardSystem
|
||||
/// </summary>
|
||||
public void ReturnToNormalSize()
|
||||
{
|
||||
Tween.LocalScale(transform, Vector3.one, 0.3f, 0f, Tween.EaseOutBack, completeCallback: () =>
|
||||
Tween.LocalScale(transform, Vector3.one, _settings.ScaleDuration, 0f, Tween.EaseOutBack, completeCallback: () =>
|
||||
{
|
||||
// After returning to normal, hide new card text, show idle text
|
||||
if (_isNew)
|
||||
@@ -531,6 +529,8 @@ namespace UI.CardSystem
|
||||
// Get all child Image components
|
||||
UnityEngine.UI.Image[] progressElements = progressBarContainer.GetComponentsInChildren<UnityEngine.UI.Image>(true);
|
||||
|
||||
int cardsToUpgrade = _settings.CardsToUpgrade;
|
||||
|
||||
// Check if we have the required number of elements (should match cardsToUpgrade)
|
||||
if (progressElements.Length < cardsToUpgrade)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user