Setup more of the card system stuff
This commit is contained in:
committed by
Michal Adam Pikulski
parent
b1df36d48c
commit
80005e6b7d
185
Assets/Scripts/UI/CardSystem/BoosterNotificationDot.cs
Normal file
185
Assets/Scripts/UI/CardSystem/BoosterNotificationDot.cs
Normal file
@@ -0,0 +1,185 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using Pixelplacement;
|
||||
using Pixelplacement.TweenSystem;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages a notification dot that displays a count (e.g., booster packs)
|
||||
/// Can be reused across different UI elements that need to show numeric notifications
|
||||
/// </summary>
|
||||
public class BoosterNotificationDot : MonoBehaviour
|
||||
{
|
||||
[Header("UI References")]
|
||||
[SerializeField] private GameObject dotBackground;
|
||||
[SerializeField] private TextMeshProUGUI countText;
|
||||
|
||||
[Header("Settings")]
|
||||
[SerializeField] private bool hideWhenZero = true;
|
||||
[SerializeField] private bool useAnimation = false;
|
||||
[SerializeField] private string textPrefix = "";
|
||||
[SerializeField] private string textSuffix = "";
|
||||
[SerializeField] private Color textColor = Color.white;
|
||||
|
||||
[Header("Animation")]
|
||||
[SerializeField] private bool useTween = true;
|
||||
[SerializeField] private float pulseDuration = 0.3f;
|
||||
[SerializeField] private float pulseScale = 1.2f;
|
||||
|
||||
// Optional animator reference
|
||||
[SerializeField] private Animator animator;
|
||||
[SerializeField] private string animationTrigger = "Update";
|
||||
|
||||
// Current count value
|
||||
private int _currentCount;
|
||||
private Vector3 _originalScale;
|
||||
|
||||
private TweenBase _activeTween;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Store original scale for pulse animation
|
||||
if (dotBackground != null)
|
||||
{
|
||||
_originalScale = dotBackground.transform.localScale;
|
||||
}
|
||||
|
||||
// Apply text color
|
||||
if (countText != null)
|
||||
{
|
||||
countText.color = textColor;
|
||||
}
|
||||
|
||||
// Initial setup based on current count
|
||||
SetCount(_currentCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the count displayed on the notification dot
|
||||
/// Also handles visibility based on settings
|
||||
/// </summary>
|
||||
public void SetCount(int count)
|
||||
{
|
||||
bool countChanged = count != _currentCount;
|
||||
_currentCount = count;
|
||||
|
||||
// Update text
|
||||
if (countText != null)
|
||||
{
|
||||
countText.text = textPrefix + count.ToString() + textSuffix;
|
||||
}
|
||||
|
||||
// Handle visibility
|
||||
if (hideWhenZero)
|
||||
{
|
||||
SetVisibility(count > 0);
|
||||
}
|
||||
|
||||
// Play animation if value changed and animation is enabled
|
||||
if (countChanged && count > 0)
|
||||
{
|
||||
if (useAnimation)
|
||||
{
|
||||
Animate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current count value
|
||||
/// </summary>
|
||||
public int GetCount()
|
||||
{
|
||||
return _currentCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set text formatting options
|
||||
/// </summary>
|
||||
public void SetFormatting(string prefix, string suffix, Color color)
|
||||
{
|
||||
textPrefix = prefix;
|
||||
textSuffix = suffix;
|
||||
textColor = color;
|
||||
|
||||
if (countText != null)
|
||||
{
|
||||
countText.color = color;
|
||||
// Update text with new formatting
|
||||
countText.text = textPrefix + _currentCount.ToString() + textSuffix;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Explicitly control the notification dot visibility
|
||||
/// </summary>
|
||||
public void SetVisibility(bool isVisible)
|
||||
{
|
||||
if (dotBackground != null)
|
||||
{
|
||||
dotBackground.SetActive(isVisible);
|
||||
}
|
||||
|
||||
if (countText != null)
|
||||
{
|
||||
countText.gameObject.SetActive(isVisible);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show the notification dot
|
||||
/// </summary>
|
||||
public void Show()
|
||||
{
|
||||
SetVisibility(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hide the notification dot
|
||||
/// </summary>
|
||||
public void Hide()
|
||||
{
|
||||
SetVisibility(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Play animation manually - either using Animator or Tween
|
||||
/// </summary>
|
||||
public void Animate()
|
||||
{
|
||||
if (useAnimation)
|
||||
{
|
||||
if (animator != null)
|
||||
{
|
||||
animator.SetTrigger(animationTrigger);
|
||||
}
|
||||
else if (useTween && dotBackground != null)
|
||||
{
|
||||
// Cancel any existing tweens on this transform
|
||||
_activeTween.Cancel();
|
||||
|
||||
// Reset to original scale
|
||||
dotBackground.transform.localScale = _originalScale;
|
||||
|
||||
// Pulse animation using Tween
|
||||
_activeTween = Tween.LocalScale(dotBackground.transform,
|
||||
_originalScale * pulseScale,
|
||||
pulseDuration/2,
|
||||
0,
|
||||
Tween.EaseOut,
|
||||
Tween.LoopType.None,
|
||||
null,
|
||||
() => {
|
||||
// Scale back to original size
|
||||
Tween.LocalScale(dotBackground.transform,
|
||||
_originalScale,
|
||||
pulseDuration/2,
|
||||
0,
|
||||
Tween.EaseIn);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ed8cced1478640229c5a61e3c6bd42df
|
||||
timeCreated: 1760710148
|
||||
@@ -23,8 +23,7 @@ namespace AppleHills.UI.CardSystem
|
||||
|
||||
[Header("UI Elements")]
|
||||
[SerializeField] private Button backpackButton;
|
||||
[SerializeField] private Text boosterCountText;
|
||||
[SerializeField] private GameObject notificationDot;
|
||||
[SerializeField] private BoosterNotificationDot boosterNotificationDot; // Changed to BoosterNotificationDot
|
||||
[SerializeField] private GameObject backpackAnimationTarget;
|
||||
[SerializeField] private GameObject newCardNotification;
|
||||
|
||||
@@ -62,8 +61,8 @@ namespace AppleHills.UI.CardSystem
|
||||
ShowOnlyBackpackIcon();
|
||||
|
||||
// Hide notifications initially
|
||||
if (notificationDot != null)
|
||||
notificationDot.SetActive(false);
|
||||
if (boosterNotificationDot != null)
|
||||
boosterNotificationDot.gameObject.SetActive(false);
|
||||
|
||||
if (newCardNotification != null)
|
||||
newCardNotification.SetActive(false);
|
||||
@@ -154,8 +153,8 @@ namespace AppleHills.UI.CardSystem
|
||||
_pageController.PushPage(mainMenuPage);
|
||||
|
||||
// Clear notification
|
||||
if (notificationDot != null)
|
||||
notificationDot.SetActive(false);
|
||||
if (boosterNotificationDot != null)
|
||||
boosterNotificationDot.gameObject.SetActive(false);
|
||||
|
||||
_hasUnseenCards = false;
|
||||
}
|
||||
@@ -269,13 +268,13 @@ namespace AppleHills.UI.CardSystem
|
||||
/// </summary>
|
||||
private void UpdateBoosterCount(int count)
|
||||
{
|
||||
if (boosterCountText != null)
|
||||
if (boosterNotificationDot != null)
|
||||
{
|
||||
boosterCountText.text = count.ToString();
|
||||
boosterNotificationDot.SetCount(count);
|
||||
|
||||
// Animate the text for feedback
|
||||
boosterCountText.transform.localScale = Vector3.one * 1.2f;
|
||||
Tween.LocalScale(boosterCountText.transform, Vector3.one, 0.3f, 0f);
|
||||
boosterNotificationDot.transform.localScale = Vector3.one * 1.2f;
|
||||
Tween.LocalScale(boosterNotificationDot.transform, Vector3.one, 0.3f, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,8 +298,8 @@ namespace AppleHills.UI.CardSystem
|
||||
_pageController.CurrentPage != boosterOpeningPage)
|
||||
{
|
||||
_hasUnseenCards = true;
|
||||
if (notificationDot != null)
|
||||
notificationDot.SetActive(true);
|
||||
if (boosterNotificationDot != null)
|
||||
boosterNotificationDot.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
Logging.Debug($"[CardAlbumUI] New card collected: {card.Name}");
|
||||
|
||||
@@ -3,7 +3,7 @@ using AppleHills.Data.CardSystem;
|
||||
using Core;
|
||||
using Data.CardSystem;
|
||||
using Pixelplacement;
|
||||
using TMPro; // Added TMP namespace
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace AppleHills.UI.CardSystem
|
||||
[SerializeField] private Button changeClothesButton;
|
||||
|
||||
[Header("UI Elements")]
|
||||
[SerializeField] private TextMeshProUGUI boosterCountText; // Changed to TextMeshProUGUI
|
||||
[SerializeField] private BoosterNotificationDot boosterNotificationDot; // Changed to BoosterNotificationDot
|
||||
[SerializeField] private CanvasGroup canvasGroup;
|
||||
|
||||
private CardAlbumUI _cardAlbumUI;
|
||||
@@ -91,10 +91,10 @@ namespace AppleHills.UI.CardSystem
|
||||
|
||||
int boosterCount = _cardManager.GetBoosterPackCount();
|
||||
|
||||
// Update booster count text
|
||||
if (boosterCountText != null)
|
||||
// Update booster count text using the notification dot
|
||||
if (boosterNotificationDot != null)
|
||||
{
|
||||
boosterCountText.text = $"Boosters: {boosterCount}";
|
||||
boosterNotificationDot.SetCount(boosterCount);
|
||||
}
|
||||
|
||||
// Enable/disable open booster button based on availability
|
||||
|
||||
Reference in New Issue
Block a user