Second draft of the consolidated card system
This commit is contained in:
@@ -19,6 +19,7 @@ namespace AppleHills.UI.CardSystem
|
||||
[SerializeField] private Button openBoosterButton;
|
||||
[SerializeField] private Button viewAlbumButton;
|
||||
[SerializeField] private Button changeClothesButton;
|
||||
[SerializeField] private Button backButton; // Added back button field
|
||||
|
||||
[Header("UI Elements")]
|
||||
[SerializeField] private BoosterNotificationDot boosterNotificationDot; // Changed to BoosterNotificationDot
|
||||
@@ -56,6 +57,11 @@ namespace AppleHills.UI.CardSystem
|
||||
// Disable "Coming Soon" feature
|
||||
changeClothesButton.interactable = false;
|
||||
}
|
||||
|
||||
if (backButton != null) // Set up back button listener
|
||||
{
|
||||
backButton.onClick.AddListener(OnBackButtonClicked);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
@@ -80,6 +86,11 @@ namespace AppleHills.UI.CardSystem
|
||||
{
|
||||
changeClothesButton.onClick.RemoveListener(OnChangeClothesClicked);
|
||||
}
|
||||
|
||||
if (backButton != null) // Clean up back button listener
|
||||
{
|
||||
backButton.onClick.RemoveListener(OnBackButtonClicked);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -142,6 +153,20 @@ namespace AppleHills.UI.CardSystem
|
||||
Logging.Debug("[CardMenuPage] Change Clothes feature coming soon!");
|
||||
// No implementation yet - "Coming soon" feature
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles click on the Back button
|
||||
/// </summary>
|
||||
private void OnBackButtonClicked()
|
||||
{
|
||||
// Use the UIPageController to pop this page
|
||||
// This will hide the card menu and return to the game
|
||||
if (UIPageController.Instance != null)
|
||||
{
|
||||
UIPageController.Instance.PopPage();
|
||||
Logging.Debug("[CardMenuPage] Exiting card menu back to game");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override for transition in animation using Pixelplacement.Tween
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using Bootstrap;
|
||||
using Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
{
|
||||
@@ -21,6 +22,9 @@ namespace AppleHills.UI.CardSystem
|
||||
// Event fired when the page stack changes
|
||||
public event Action<UIPage> OnPageChanged;
|
||||
|
||||
private PlayerInput _playerInput;
|
||||
private InputAction _cancelAction;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (_instance != null && _instance != this)
|
||||
@@ -31,9 +35,46 @@ namespace AppleHills.UI.CardSystem
|
||||
|
||||
_instance = this;
|
||||
|
||||
// TODO: Handle generic "cancel" action
|
||||
// _playerInput = FindFirstObjectByType<PlayerInput>();
|
||||
// if (_playerInput == null)
|
||||
// {
|
||||
// Logging.Warning("[UIPageController] No PlayerInput found in the scene. Cancel action might not work.");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // Get the Cancel action from the UI action map
|
||||
// _cancelAction = _playerInput.actions.FindAction("UI/Cancel");
|
||||
// if (_cancelAction != null)
|
||||
// {
|
||||
// _cancelAction.performed += OnCancelActionPerformed;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Logging.Warning("[UIPageController] Cancel action not found in the input actions asset.");
|
||||
// }
|
||||
// }
|
||||
|
||||
// Register for post-boot initialization
|
||||
BootCompletionService.RegisterInitAction(InitializePostBoot);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// Clean up event subscription when the controller is destroyed
|
||||
if (_cancelAction != null)
|
||||
{
|
||||
_cancelAction.performed -= OnCancelActionPerformed;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCancelActionPerformed(InputAction.CallbackContext context)
|
||||
{
|
||||
if (_pageStack.Count > 0)
|
||||
{
|
||||
_pageStack.Peek().OnBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
private void InitializePostBoot()
|
||||
{
|
||||
@@ -105,16 +146,5 @@ namespace AppleHills.UI.CardSystem
|
||||
OnPageChanged?.Invoke(null);
|
||||
Logging.Debug("[UIPageController] Cleared page stack");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles back button input and navigates to the previous page if possible.
|
||||
/// </summary>
|
||||
private void Update()
|
||||
{
|
||||
if (UnityEngine.Input.GetKeyDown(KeyCode.Escape) && _pageStack.Count > 0)
|
||||
{
|
||||
_pageStack.Peek().OnBackPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user