Moved UIPageController out of the card system and into a dedicated prefab

This commit is contained in:
Michal Adam Pikulski
2025-10-22 09:20:18 +02:00
parent faed21edab
commit 357f942e0d
7 changed files with 912 additions and 55 deletions

View File

@@ -1,4 +1,5 @@
using AppleHills.Data.CardSystem;
using Bootstrap;
using Core;
using Data.CardSystem;
using Input;
@@ -30,26 +31,13 @@ namespace UI.CardSystem
// Public property to access the backpack icon for animations
public GameObject BackpackIcon => backpackIcon;
private UIPageController _pageController;
private UIPageController PageController => UIPageController.Instance;
private CardSystemManager _cardManager;
private bool _isInitialized = false;
private bool _hasUnseenCards = false;
private void Awake()
{
// Get or create a UI page controller
_pageController = FindAnyObjectByType<UIPageController>();
if (_pageController == null)
{
GameObject controllerObj = new GameObject("UIPageController");
controllerObj.transform.SetParent(transform);
_pageController = controllerObj.AddComponent<UIPageController>();
}
// Initialize pages and hide them
InitializePages();
// Set up backpack button
if (backpackButton != null)
{
@@ -62,8 +50,17 @@ namespace UI.CardSystem
// Hide notification dot initially
if (boosterNotificationDot != null)
boosterNotificationDot.gameObject.SetActive(false);
// Register for post-boot initialization
BootCompletionService.RegisterInitAction(InitializePostBoot);
}
private void InitializePostBoot()
{
// Initialize pages and hide them
InitializePages();
}
private void Start()
{
// Get card manager
@@ -102,9 +99,9 @@ namespace UI.CardSystem
}
// Unsubscribe from page controller events
if (_pageController != null)
if (PageController != null)
{
_pageController.OnPageChanged -= OnPageChanged;
PageController.OnPageChanged -= OnPageChanged;
}
}
@@ -130,9 +127,9 @@ namespace UI.CardSystem
}
// Set up page changed callback
if (_pageController != null)
if (PageController != null)
{
_pageController.OnPageChanged += OnPageChanged;
PageController.OnPageChanged += OnPageChanged;
}
}
@@ -150,9 +147,9 @@ namespace UI.CardSystem
InputManager.Instance.RegisterOverrideConsumer(backpackInput);
// If no pages are open, push the main menu
if (_pageController.CurrentPage == null)
if (PageController.CurrentPage == null)
{
_pageController.PushPage(mainMenuPage);
PageController.PushPage(mainMenuPage);
// Clear notification for unseen cards when opening menu
if (_hasUnseenCards)
@@ -166,10 +163,10 @@ namespace UI.CardSystem
backpackButton.gameObject.SetActive(false);
}
}
else if (_pageController.CurrentPage == mainMenuPage)
else if (PageController.CurrentPage == mainMenuPage)
{
// If main menu is open, pop it
_pageController.PopPage();
PageController.PopPage();
}
}
@@ -224,7 +221,7 @@ namespace UI.CardSystem
/// </summary>
public void OpenAlbumView()
{
_pageController.PushPage(albumViewPage);
PageController.PushPage(albumViewPage);
}
/// <summary>
@@ -234,7 +231,7 @@ namespace UI.CardSystem
{
if (_cardManager != null && _cardManager.GetBoosterPackCount() > 0)
{
_pageController.PushPage(boosterOpeningPage);
PageController.PushPage(boosterOpeningPage);
}
else
{
@@ -289,8 +286,8 @@ namespace UI.CardSystem
{
// If we're not in the album view or booster opening view,
// show a notification dot on the backpack
if (_pageController.CurrentPage != albumViewPage &&
_pageController.CurrentPage != boosterOpeningPage)
if (PageController.CurrentPage != albumViewPage &&
PageController.CurrentPage != boosterOpeningPage)
{
_hasUnseenCards = true;
UpdateBoosterVisibility();