Second draft of the consolidated card system

This commit is contained in:
Michal Adam Pikulski
2025-10-20 12:04:55 +02:00
parent 542dd9a4b7
commit 32f726d229
13 changed files with 1152 additions and 85 deletions

View File

@@ -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();
}
}
}
}