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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user