Finish setting up the basic album layout
This commit is contained in:
@@ -1,9 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using Core;
|
||||
using Data.CardSystem;
|
||||
using Pixelplacement;
|
||||
using TMPro;
|
||||
using Pixelplacement;
|
||||
using UI.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -15,260 +10,60 @@ namespace UI.CardSystem
|
||||
/// </summary>
|
||||
public class AlbumViewPage : UIPage
|
||||
{
|
||||
[Header("Album UI Elements")]
|
||||
[SerializeField] private GridLayoutGroup albumGrid;
|
||||
[SerializeField] private GameObject cardPrefab;
|
||||
|
||||
[Header("Filter UI")]
|
||||
[SerializeField] private TMP_Dropdown zoneFilterDropdown;
|
||||
[SerializeField] private TMP_Dropdown rarityFilterDropdown;
|
||||
[SerializeField] private Button resetFiltersButton;
|
||||
[SerializeField] private CanvasGroup canvasGroup;
|
||||
|
||||
[Header("Navigation")]
|
||||
[SerializeField] private Button backButton;
|
||||
|
||||
// Runtime references
|
||||
private CardSystemManager _cardManager;
|
||||
private List<CardDisplay> _displayedCards = new List<CardDisplay>();
|
||||
[SerializeField] private Button exitButton;
|
||||
[SerializeField] private BookCurlPro.BookPro book;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_cardManager = CardSystemManager.Instance;
|
||||
|
||||
// Make sure we have a CanvasGroup for transitions
|
||||
if (canvasGroup == null)
|
||||
canvasGroup = GetComponent<CanvasGroup>();
|
||||
if (canvasGroup == null)
|
||||
canvasGroup = gameObject.AddComponent<CanvasGroup>();
|
||||
|
||||
// Set up back button
|
||||
if (backButton != null)
|
||||
// Set up exit button
|
||||
if (exitButton != null)
|
||||
{
|
||||
backButton.onClick.AddListener(OnBackButtonClicked);
|
||||
exitButton.onClick.AddListener(OnExitButtonClicked);
|
||||
}
|
||||
|
||||
// UI pages should start disabled
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (exitButton != null)
|
||||
{
|
||||
exitButton.onClick.RemoveListener(OnExitButtonClicked);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets up the album when the page becomes active
|
||||
/// </summary>
|
||||
public override void TransitionIn()
|
||||
private void OnExitButtonClicked()
|
||||
{
|
||||
base.TransitionIn();
|
||||
|
||||
// Initialize the album when the page becomes active
|
||||
InitializeAlbum();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the album with the player's collection
|
||||
/// </summary>
|
||||
private void InitializeAlbum()
|
||||
{
|
||||
// Clear any previous setup
|
||||
ClearAlbum();
|
||||
|
||||
// Setup filter UI
|
||||
InitializeFilters();
|
||||
|
||||
// Get all collected cards
|
||||
List<CardData> collectedCards = _cardManager.GetAllCollectedCards();
|
||||
|
||||
// If there are cards to display, create UI elements for them
|
||||
if (collectedCards.Count > 0)
|
||||
if (book != null && book.CurrentPaper != 1)
|
||||
{
|
||||
// Create card UI elements
|
||||
DisplayCards(collectedCards);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates UI elements for the player's collected cards
|
||||
/// </summary>
|
||||
private void DisplayCards(List<CardData> cards)
|
||||
{
|
||||
if (albumGrid == null || cardPrefab == null) return;
|
||||
|
||||
// Sort cards by collection index
|
||||
cards.Sort((a, b) => a.CollectionIndex.CompareTo(b.CollectionIndex));
|
||||
|
||||
// Create card UI elements
|
||||
foreach (var cardData in cards)
|
||||
{
|
||||
GameObject cardObj = Instantiate(cardPrefab, albumGrid.transform);
|
||||
|
||||
// Configure the card UI with the card data
|
||||
// TODO: Update this to use your actual CardDisplay component
|
||||
// CardUIElement cardUI = cardObj.GetComponent<CardUIElement>();
|
||||
// if (cardUI != null)
|
||||
// {
|
||||
// cardUI.SetupCard(cardData);
|
||||
// _displayedCards.Add(cardUI);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all card UI elements from the album
|
||||
/// </summary>
|
||||
private void ClearAlbum()
|
||||
{
|
||||
foreach (var card in _displayedCards)
|
||||
{
|
||||
if (card != null && card.gameObject != null)
|
||||
Destroy(card.gameObject);
|
||||
}
|
||||
_displayedCards.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes filter dropdowns
|
||||
/// </summary>
|
||||
private void InitializeFilters()
|
||||
{
|
||||
// Setup zone filter dropdown
|
||||
if (zoneFilterDropdown != null)
|
||||
{
|
||||
zoneFilterDropdown.ClearOptions();
|
||||
|
||||
// Add "All Zones" option
|
||||
List<string> zoneOptions = new List<string>() { "All Zones" };
|
||||
|
||||
// Add options for each zone
|
||||
foreach (CardZone zone in System.Enum.GetValues(typeof(CardZone)))
|
||||
// Not on page 0, flip to page 0 first
|
||||
BookCurlPro.AutoFlip autoFlip = book.GetComponent<BookCurlPro.AutoFlip>();
|
||||
if (autoFlip == null)
|
||||
{
|
||||
zoneOptions.Add(zone.ToString());
|
||||
autoFlip = book.gameObject.AddComponent<BookCurlPro.AutoFlip>();
|
||||
}
|
||||
|
||||
zoneFilterDropdown.AddOptions(zoneOptions);
|
||||
zoneFilterDropdown.onValueChanged.AddListener(OnFilterChanged);
|
||||
}
|
||||
|
||||
// Setup rarity filter dropdown
|
||||
if (rarityFilterDropdown != null)
|
||||
{
|
||||
rarityFilterDropdown.ClearOptions();
|
||||
|
||||
// Add "All Rarities" option
|
||||
List<string> rarityOptions = new List<string>() { "All Rarities" };
|
||||
|
||||
// Add options for each rarity
|
||||
foreach (CardRarity rarity in System.Enum.GetValues(typeof(CardRarity)))
|
||||
{
|
||||
rarityOptions.Add(rarity.ToString());
|
||||
}
|
||||
|
||||
rarityFilterDropdown.AddOptions(rarityOptions);
|
||||
rarityFilterDropdown.onValueChanged.AddListener(OnFilterChanged);
|
||||
}
|
||||
|
||||
// Setup reset filters button
|
||||
if (resetFiltersButton != null)
|
||||
{
|
||||
resetFiltersButton.onClick.AddListener(OnResetFiltersClicked);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles changes to the filter dropdowns
|
||||
/// </summary>
|
||||
private void OnFilterChanged(int value)
|
||||
{
|
||||
ApplyFilters();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets all filters to their default values
|
||||
/// </summary>
|
||||
private void OnResetFiltersClicked()
|
||||
{
|
||||
if (zoneFilterDropdown != null)
|
||||
zoneFilterDropdown.value = 0;
|
||||
|
||||
if (rarityFilterDropdown != null)
|
||||
rarityFilterDropdown.value = 0;
|
||||
|
||||
ApplyFilters();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Applies the current filter selections to the displayed cards
|
||||
/// </summary>
|
||||
private void ApplyFilters()
|
||||
{
|
||||
// Clear current cards
|
||||
ClearAlbum();
|
||||
|
||||
// Get selected filters
|
||||
CardZone? selectedZone = null;
|
||||
CardRarity? selectedRarity = null;
|
||||
|
||||
// Get zone filter value
|
||||
if (zoneFilterDropdown != null && zoneFilterDropdown.value > 0)
|
||||
{
|
||||
selectedZone = (CardZone)(zoneFilterDropdown.value - 1);
|
||||
}
|
||||
|
||||
// Get rarity filter value
|
||||
if (rarityFilterDropdown != null && rarityFilterDropdown.value > 0)
|
||||
{
|
||||
selectedRarity = (CardRarity)(rarityFilterDropdown.value - 1);
|
||||
}
|
||||
|
||||
// Get filtered cards
|
||||
List<CardData> filteredCards = GetFilteredCards(selectedZone, selectedRarity);
|
||||
|
||||
// Create card UI elements for the filtered cards
|
||||
DisplayCards(filteredCards);
|
||||
|
||||
Logging.Debug($"[AlbumViewPage] Applied filters. Showing {filteredCards.Count} cards.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets cards filtered by zone and/or rarity
|
||||
/// </summary>
|
||||
private List<CardData> GetFilteredCards(CardZone? zone, CardRarity? rarity)
|
||||
{
|
||||
List<CardData> result;
|
||||
|
||||
// Get all collected cards
|
||||
if (zone == null && rarity == null)
|
||||
{
|
||||
// No filters, return all cards
|
||||
result = _cardManager.GetAllCollectedCards();
|
||||
}
|
||||
else if (zone != null && rarity != null)
|
||||
{
|
||||
// Both filters, get cards by zone and rarity
|
||||
result = _cardManager.GetCardsByZoneAndRarity(zone.Value, rarity.Value);
|
||||
}
|
||||
else if (zone != null)
|
||||
{
|
||||
// Only zone filter
|
||||
result = _cardManager.GetCardsByZone(zone.Value);
|
||||
autoFlip.enabled = true;
|
||||
autoFlip.StartFlipping(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Only rarity filter
|
||||
result = _cardManager.GetCardsByRarity(rarity.Value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles click on the back button
|
||||
/// </summary>
|
||||
private void OnBackButtonClicked()
|
||||
{
|
||||
// Use the UIPageController to go back to the previous page
|
||||
UIPageController pageController = UIPageController.Instance;
|
||||
if (pageController != null)
|
||||
{
|
||||
pageController.PopPage();
|
||||
// Already on page 0 or no book reference, exit
|
||||
if (UIPageController.Instance != null)
|
||||
{
|
||||
UIPageController.Instance.PopPage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void DoTransitionIn(System.Action onComplete)
|
||||
{
|
||||
// Simple fade in animation
|
||||
@@ -283,7 +78,7 @@ namespace UI.CardSystem
|
||||
onComplete?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected override void DoTransitionOut(System.Action onComplete)
|
||||
{
|
||||
// Simple fade out animation
|
||||
@@ -297,42 +92,5 @@ namespace UI.CardSystem
|
||||
onComplete?.Invoke();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// Clean up button listeners
|
||||
if (backButton != null)
|
||||
{
|
||||
backButton.onClick.RemoveListener(OnBackButtonClicked);
|
||||
}
|
||||
|
||||
if (zoneFilterDropdown != null)
|
||||
{
|
||||
zoneFilterDropdown.onValueChanged.RemoveListener(OnFilterChanged);
|
||||
}
|
||||
|
||||
if (rarityFilterDropdown != null)
|
||||
{
|
||||
rarityFilterDropdown.onValueChanged.RemoveListener(OnFilterChanged);
|
||||
}
|
||||
|
||||
if (resetFiltersButton != null)
|
||||
{
|
||||
resetFiltersButton.onClick.RemoveListener(OnResetFiltersClicked);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (_cardManager == null)
|
||||
{
|
||||
_cardManager = CardSystemManager.Instance;
|
||||
}
|
||||
}
|
||||
|
||||
public void ExitAlbum()
|
||||
{
|
||||
UIPageController.Instance.PopPage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
128
Assets/Scripts/UI/CardSystem/BookTabButton.cs
Normal file
128
Assets/Scripts/UI/CardSystem/BookTabButton.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using System;
|
||||
using BookCurlPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Tween = Pixelplacement.Tween;
|
||||
|
||||
namespace UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Tab button for navigating to specific pages in the card album book.
|
||||
/// Coordinates with other tabs via static events for visual feedback.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class BookTabButton : MonoBehaviour
|
||||
{
|
||||
[Header("Book Reference")]
|
||||
[SerializeField] private BookPro book;
|
||||
|
||||
[Header("Tab Configuration")]
|
||||
[SerializeField] private int targetPage;
|
||||
|
||||
[Header("Visual Settings")]
|
||||
[SerializeField] private bool enableScaling = true;
|
||||
[SerializeField] private float selectedScale = 2.0f;
|
||||
[SerializeField] private float normalScale = 1.0f;
|
||||
[SerializeField] private float scaleTransitionDuration = 0.2f;
|
||||
|
||||
private Button button;
|
||||
private RectTransform rectTransform;
|
||||
private Vector2 originalSize;
|
||||
|
||||
// Static dispatcher for coordinating all tabs
|
||||
private static event Action<BookTabButton> OnTabClicked;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Get required components
|
||||
button = GetComponent<Button>();
|
||||
rectTransform = GetComponent<RectTransform>();
|
||||
|
||||
// Cache original size
|
||||
originalSize = rectTransform.sizeDelta;
|
||||
|
||||
// Register button click
|
||||
button.onClick.AddListener(OnButtonClicked);
|
||||
|
||||
// Subscribe to static tab event
|
||||
OnTabClicked += OnAnyTabClicked;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// Cleanup listeners
|
||||
if (button != null)
|
||||
{
|
||||
button.onClick.RemoveListener(OnButtonClicked);
|
||||
}
|
||||
|
||||
OnTabClicked -= OnAnyTabClicked;
|
||||
}
|
||||
|
||||
private void OnButtonClicked()
|
||||
{
|
||||
if (book == null)
|
||||
{
|
||||
Debug.LogWarning($"[BookTabButton] No BookPro reference assigned on {gameObject.name}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Notify all tabs that this one was clicked
|
||||
OnTabClicked?.Invoke(this);
|
||||
|
||||
// Flip to target page using AutoFlip
|
||||
BookCurlPro.AutoFlip autoFlip = book.GetComponent<BookCurlPro.AutoFlip>();
|
||||
if (autoFlip == null)
|
||||
{
|
||||
autoFlip = book.gameObject.AddComponent<BookCurlPro.AutoFlip>();
|
||||
}
|
||||
|
||||
autoFlip.enabled = true;
|
||||
autoFlip.StartFlipping(targetPage);
|
||||
}
|
||||
|
||||
private void OnAnyTabClicked(BookTabButton clickedTab)
|
||||
{
|
||||
// Skip scaling if disabled
|
||||
if (!enableScaling) return;
|
||||
|
||||
// Scale this tab based on whether it was clicked
|
||||
if (clickedTab == this)
|
||||
{
|
||||
SetScale(selectedScale);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetScale(normalScale);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetScale(float targetScale)
|
||||
{
|
||||
Vector2 targetSize = originalSize * targetScale;
|
||||
|
||||
// Use Pixelplacement Tween for smooth size change
|
||||
Tween.Value(rectTransform.sizeDelta, targetSize,
|
||||
(Vector2 value) => rectTransform.sizeDelta = value,
|
||||
scaleTransitionDuration, 0f, Tween.EaseInOut);
|
||||
}
|
||||
|
||||
// Public method to programmatically trigger this tab
|
||||
public void ActivateTab()
|
||||
{
|
||||
OnButtonClicked();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnValidate()
|
||||
{
|
||||
// Ensure target page is non-negative
|
||||
if (targetPage < 0)
|
||||
{
|
||||
targetPage = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
3
Assets/Scripts/UI/CardSystem/BookTabButton.cs.meta
Normal file
3
Assets/Scripts/UI/CardSystem/BookTabButton.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff50caabb55742bc8d24a6ddffeda815
|
||||
timeCreated: 1762385754
|
||||
72
Assets/Scripts/UI/CardSystem/CardAlbumOpener.cs
Normal file
72
Assets/Scripts/UI/CardSystem/CardAlbumOpener.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using UI.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Opens the card album view when the button is pressed.
|
||||
/// Attach this to a top-level GameObject in the scene.
|
||||
/// </summary>
|
||||
public class CardAlbumOpener : MonoBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField] private Button openAlbumButton;
|
||||
[SerializeField] private AlbumViewPage albumViewPage;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (openAlbumButton != null)
|
||||
{
|
||||
openAlbumButton.onClick.AddListener(OnOpenAlbumClicked);
|
||||
}
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (UIPageController.Instance != null)
|
||||
{
|
||||
UIPageController.Instance.OnPageChanged += OnPageChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (UIPageController.Instance != null)
|
||||
{
|
||||
UIPageController.Instance.OnPageChanged -= OnPageChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (openAlbumButton != null)
|
||||
{
|
||||
openAlbumButton.onClick.RemoveListener(OnOpenAlbumClicked);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnOpenAlbumClicked()
|
||||
{
|
||||
if (openAlbumButton != null)
|
||||
{
|
||||
openAlbumButton.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (albumViewPage != null && UIPageController.Instance != null)
|
||||
{
|
||||
UIPageController.Instance.PushPage(albumViewPage);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPageChanged(UIPage currentPage)
|
||||
{
|
||||
// If the album page is no longer active, show the button again
|
||||
if (currentPage != albumViewPage && openAlbumButton != null)
|
||||
{
|
||||
openAlbumButton.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
3
Assets/Scripts/UI/CardSystem/CardAlbumOpener.cs.meta
Normal file
3
Assets/Scripts/UI/CardSystem/CardAlbumOpener.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b3b63118ebc48d6b8f28cd69d96191e
|
||||
timeCreated: 1762384087
|
||||
Reference in New Issue
Block a user