First draft of the consolidated card system

This commit is contained in:
Michal Adam Pikulski
2025-10-20 10:29:22 +02:00
parent 07750dd5ba
commit 542dd9a4b7
19 changed files with 3014 additions and 1041 deletions

View File

@@ -23,19 +23,18 @@ namespace AppleHills.UI.CardSystem
[Header("UI Elements")]
[SerializeField] private Button backpackButton;
[SerializeField] private BoosterNotificationDot boosterNotificationDot; // Changed to BoosterNotificationDot
[SerializeField] private GameObject backpackAnimationTarget;
[SerializeField] private GameObject newCardNotification;
[SerializeField] private BoosterNotificationDot boosterNotificationDot;
[Header("Notification Settings")]
[SerializeField] private float notificationDuration = 3f;
[SerializeField] private AudioSource notificationSound;
// Public property to access the backpack icon for animations
public GameObject BackpackIcon => backpackIcon;
private UIPageController _pageController;
private CardSystemManager _cardManager;
private bool _isInitialized = false;
private bool _hasUnseenCards = false;
private Coroutine _notificationCoroutine;
private void Awake()
{
@@ -60,12 +59,9 @@ namespace AppleHills.UI.CardSystem
// Initially show only the backpack icon
ShowOnlyBackpackIcon();
// Hide notifications initially
// Hide notification dot initially
if (boosterNotificationDot != null)
boosterNotificationDot.gameObject.SetActive(false);
if (newCardNotification != null)
newCardNotification.SetActive(false);
}
private void Start()
@@ -105,9 +101,11 @@ namespace AppleHills.UI.CardSystem
backpackButton.onClick.RemoveListener(OnBackpackButtonClicked);
}
// Stop any coroutines
if (_notificationCoroutine != null)
StopCoroutine(_notificationCoroutine);
// Unsubscribe from page controller events
if (_pageController != null)
{
_pageController.OnPageChanged -= OnPageChanged;
}
}
/// <summary>
@@ -152,11 +150,12 @@ namespace AppleHills.UI.CardSystem
{
_pageController.PushPage(mainMenuPage);
// Clear notification
if (boosterNotificationDot != null)
boosterNotificationDot.gameObject.SetActive(false);
_hasUnseenCards = false;
// Clear notification for unseen cards when opening menu
if (_hasUnseenCards)
{
_hasUnseenCards = false;
UpdateBoosterVisibility();
}
}
else if (_pageController.CurrentPage == mainMenuPage)
{
@@ -177,7 +176,15 @@ namespace AppleHills.UI.CardSystem
}
else
{
backpackIcon.SetActive(false);
if (backpackIcon != null)
backpackIcon.SetActive(false);
}
// Update menu if it's the main menu page
if (newPage == mainMenuPage && mainMenuPage is CardMenuPage menuPage)
{
// Force UI refresh when returning to main menu
menuPage.RefreshUI();
}
}
@@ -186,7 +193,11 @@ namespace AppleHills.UI.CardSystem
/// </summary>
private void ShowOnlyBackpackIcon()
{
backpackIcon.SetActive(true);
if (backpackIcon != null)
backpackIcon.SetActive(true);
// Update booster notification visibility
UpdateBoosterVisibility();
}
/// <summary>
@@ -209,60 +220,9 @@ namespace AppleHills.UI.CardSystem
else
{
Logging.Debug("[CardAlbumUI] No booster packs available");
ShowNoBoostersNotification();
}
}
/// <summary>
/// Shows a notification that no booster packs are available
/// </summary>
private void ShowNoBoostersNotification()
{
if (newCardNotification != null)
{
// Set notification text
Text notificationText = newCardNotification.GetComponentInChildren<Text>();
if (notificationText != null)
notificationText.text = "No booster packs available!";
// Show and animate the notification
ShowTemporaryNotification(newCardNotification);
}
}
/// <summary>
/// Shows a notification temporarily and then hides it
/// </summary>
private void ShowTemporaryNotification(GameObject notification)
{
if (notification == null) return;
// Stop any existing notification coroutine
if (_notificationCoroutine != null)
StopCoroutine(_notificationCoroutine);
// Start new notification coroutine
_notificationCoroutine = StartCoroutine(ShowNotificationCoroutine(notification));
}
private IEnumerator ShowNotificationCoroutine(GameObject notification)
{
// Show notification
notification.SetActive(true);
notification.transform.localScale = Vector3.zero;
// Animate in
Tween.LocalScale(notification.transform, Vector3.one, 0.3f, 0f, Tween.EaseOutBack);
// Wait for duration
yield return new WaitForSeconds(notificationDuration);
// Animate out
Tween.LocalScale(notification.transform, Vector3.zero, 0.3f, 0f, Tween.EaseInBack, Tween.LoopType.None, null, () => {
notification.SetActive(false);
});
}
/// <summary>
/// Updates the booster count display
/// </summary>
@@ -272,9 +232,25 @@ namespace AppleHills.UI.CardSystem
{
boosterNotificationDot.SetCount(count);
// Animate the text for feedback
// Animate the notification dot for feedback
boosterNotificationDot.transform.localScale = Vector3.one * 1.2f;
Tween.LocalScale(boosterNotificationDot.transform, Vector3.one, 0.3f, 0f);
// Update visibility based on count
UpdateBoosterVisibility();
}
}
/// <summary>
/// Updates the visibility of the booster notification dot based on current state
/// </summary>
private void UpdateBoosterVisibility()
{
if (boosterNotificationDot != null)
{
// Show dot if there are boosters or unseen cards
bool hasBooters = _cardManager != null && _cardManager.GetBoosterPackCount() > 0;
boosterNotificationDot.gameObject.SetActive(hasBooters || _hasUnseenCards);
}
}
@@ -298,8 +274,7 @@ namespace AppleHills.UI.CardSystem
_pageController.CurrentPage != boosterOpeningPage)
{
_hasUnseenCards = true;
if (boosterNotificationDot != null)
boosterNotificationDot.gameObject.SetActive(true);
UpdateBoosterVisibility();
}
Logging.Debug($"[CardAlbumUI] New card collected: {card.Name}");
@@ -310,18 +285,7 @@ namespace AppleHills.UI.CardSystem
/// </summary>
private void HandleCardRarityUpgraded(CardData card)
{
// Show a special notification for rarity upgrade
if (newCardNotification != null)
{
// Set notification text
Text notificationText = newCardNotification.GetComponentInChildren<Text>();
if (notificationText != null)
notificationText.text = $"{card.Name} upgraded to {card.Rarity}!";
// Show and animate the notification
ShowTemporaryNotification(newCardNotification);
}
// Just log the upgrade event without showing a notification
Logging.Debug($"[CardAlbumUI] Card upgraded: {card.Name} to {card.Rarity}");
}
}