Second draft of the consolidated card system
This commit is contained in:
@@ -15,24 +15,7 @@ namespace Data.CardSystem
|
||||
{
|
||||
private static CardSystemManager _instance;
|
||||
private static bool _isQuitting = false;
|
||||
|
||||
public static CardSystemManager Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null && Application.isPlaying && !_isQuitting)
|
||||
{
|
||||
_instance = FindAnyObjectByType<CardSystemManager>();
|
||||
if (_instance == null)
|
||||
{
|
||||
var go = new GameObject("CardSystemManager");
|
||||
_instance = go.AddComponent<CardSystemManager>();
|
||||
DontDestroyOnLoad(go);
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
public static CardSystemManager Instance => _instance;
|
||||
|
||||
[Header("Card Collection")]
|
||||
[SerializeField] private List<CardDefinition> availableCards = new List<CardDefinition>();
|
||||
@@ -51,14 +34,7 @@ namespace Data.CardSystem
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (_instance != null && _instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
_instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
// Build lookup dictionary
|
||||
BuildDefinitionLookup();
|
||||
|
||||
3
Assets/Scripts/Tests.meta
Normal file
3
Assets/Scripts/Tests.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b32796fca0a4b168dfb93a282054c86
|
||||
timeCreated: 1760951960
|
||||
249
Assets/Scripts/Tests/CardSystemTester.cs
Normal file
249
Assets/Scripts/Tests/CardSystemTester.cs
Normal file
@@ -0,0 +1,249 @@
|
||||
using UnityEngine;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using Data.CardSystem;
|
||||
using Core;
|
||||
using AppleHills.UI.CardSystem;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AppleHills.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Testing component for the Card System. Provides editor buttons to test core functionalities.
|
||||
/// Place this in a test scene to easily test card system features without needing full game implementation.
|
||||
/// </summary>
|
||||
public class CardSystemTester : MonoBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField] private CardSystemManager cardSystemManager;
|
||||
[SerializeField] private CardAlbumUI cardAlbumUI;
|
||||
|
||||
[Header("Test Settings")]
|
||||
[SerializeField] [Range(1, 10)] private int boosterPacksToAdd = 3;
|
||||
[SerializeField] [Range(1, 100)] private int cardsToGenerate = 10;
|
||||
[SerializeField] private bool autoOpenPacksWhenAdded = false;
|
||||
|
||||
[Header("Debug Info")]
|
||||
[SerializeField] [ReadOnly] private int currentBoosterCount;
|
||||
[SerializeField] [ReadOnly] private int totalCardsInCollection;
|
||||
[SerializeField] [ReadOnly] private string lastActionMessage;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Auto-find references if needed
|
||||
if (cardSystemManager == null)
|
||||
cardSystemManager = FindAnyObjectByType<CardSystemManager>();
|
||||
|
||||
if (cardAlbumUI == null)
|
||||
cardAlbumUI = FindAnyObjectByType<CardAlbumUI>();
|
||||
|
||||
// Log missing references
|
||||
if (cardSystemManager == null)
|
||||
Debug.LogError("CardSystemTester: No CardSystemManager found in the scene!");
|
||||
|
||||
if (cardAlbumUI == null)
|
||||
Debug.LogError("CardSystemTester: No CardAlbumUI found in the scene!");
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
RefreshDebugInfo();
|
||||
}
|
||||
|
||||
// Refresh the debug information displayed in the inspector
|
||||
private void RefreshDebugInfo()
|
||||
{
|
||||
if (cardSystemManager != null)
|
||||
{
|
||||
currentBoosterCount = cardSystemManager.GetBoosterPackCount();
|
||||
totalCardsInCollection = cardSystemManager.GetCardInventory().GetAllCards().Count;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// Custom editor buttons for testing
|
||||
public void AddBoosterPacks()
|
||||
{
|
||||
if (cardSystemManager != null)
|
||||
{
|
||||
cardSystemManager.AddBoosterPack(boosterPacksToAdd);
|
||||
lastActionMessage = $"Added {boosterPacksToAdd} booster pack(s)";
|
||||
Logging.Debug($"[CardSystemTester] {lastActionMessage}");
|
||||
RefreshDebugInfo();
|
||||
|
||||
if (autoOpenPacksWhenAdded && cardAlbumUI != null)
|
||||
{
|
||||
SimulateBackpackClick();
|
||||
cardAlbumUI.OpenBoosterPack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SimulateBackpackClick()
|
||||
{
|
||||
if (cardAlbumUI != null)
|
||||
{
|
||||
// This will show the main card menu
|
||||
// Manually trigger a click on the backpack icon
|
||||
// Note: This relies on the backpack icon being correctly set up in the CardAlbumUI
|
||||
if (cardAlbumUI.BackpackIcon != null)
|
||||
{
|
||||
Button backpackButton = cardAlbumUI.BackpackIcon.GetComponent<Button>();
|
||||
if (backpackButton != null)
|
||||
{
|
||||
backpackButton.onClick.Invoke();
|
||||
lastActionMessage = "Opened card menu via backpack click";
|
||||
Logging.Debug($"[CardSystemTester] {lastActionMessage}");
|
||||
}
|
||||
else
|
||||
{
|
||||
lastActionMessage = "Failed to find Button component on backpack icon";
|
||||
Logging.Warning($"[CardSystemTester] {lastActionMessage}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lastActionMessage = "BackpackIcon reference is null";
|
||||
Logging.Warning($"[CardSystemTester] {lastActionMessage}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenBoosterPack()
|
||||
{
|
||||
if (cardAlbumUI != null)
|
||||
{
|
||||
SimulateBackpackClick(); // First make sure we've opened the menu
|
||||
cardAlbumUI.OpenBoosterPack();
|
||||
lastActionMessage = "Opening booster pack";
|
||||
Logging.Debug($"[CardSystemTester] {lastActionMessage}");
|
||||
RefreshDebugInfo();
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenAlbumView()
|
||||
{
|
||||
if (cardAlbumUI != null)
|
||||
{
|
||||
SimulateBackpackClick(); // First make sure we've opened the menu
|
||||
cardAlbumUI.OpenAlbumView();
|
||||
lastActionMessage = "Opening album view";
|
||||
Logging.Debug($"[CardSystemTester] {lastActionMessage}");
|
||||
}
|
||||
}
|
||||
|
||||
public void GenerateRandomCards()
|
||||
{
|
||||
if (cardSystemManager != null)
|
||||
{
|
||||
int cardsAdded = 0;
|
||||
List<CardDefinition> allDefinitions = cardSystemManager.GetAllCardDefinitions();
|
||||
|
||||
if (allDefinitions.Count == 0)
|
||||
{
|
||||
lastActionMessage = "Error: No card definitions available";
|
||||
Logging.Warning($"[CardSystemTester] {lastActionMessage}");
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < cardsToGenerate; i++)
|
||||
{
|
||||
// Get a random card definition
|
||||
CardDefinition randomDef = allDefinitions[Random.Range(0, allDefinitions.Count)];
|
||||
|
||||
// Create a card data instance and add it to inventory
|
||||
CardData newCard = randomDef.CreateCardData();
|
||||
cardSystemManager.GetCardInventory().AddCard(newCard);
|
||||
cardsAdded++;
|
||||
}
|
||||
|
||||
lastActionMessage = $"Generated {cardsAdded} random cards";
|
||||
Logging.Debug($"[CardSystemTester] {lastActionMessage}");
|
||||
RefreshDebugInfo();
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearAllCards()
|
||||
{
|
||||
if (cardSystemManager != null)
|
||||
{
|
||||
int count = cardSystemManager.GetCardInventory().GetAllCards().Count;
|
||||
cardSystemManager.GetCardInventory().ClearAllCards();
|
||||
lastActionMessage = $"Cleared {count} cards from inventory";
|
||||
Logging.Debug($"[CardSystemTester] {lastActionMessage}");
|
||||
RefreshDebugInfo();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[CustomEditor(typeof(CardSystemTester))]
|
||||
public class CardSystemTesterEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
DrawDefaultInspector();
|
||||
|
||||
CardSystemTester tester = (CardSystemTester)target;
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Test Actions", EditorStyles.boldLabel);
|
||||
|
||||
if (GUILayout.Button("Add Booster Packs"))
|
||||
{
|
||||
tester.AddBoosterPacks();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Open Card Menu"))
|
||||
{
|
||||
tester.SimulateBackpackClick();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Open Booster Pack"))
|
||||
{
|
||||
tester.OpenBoosterPack();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Open Album View"))
|
||||
{
|
||||
tester.OpenAlbumView();
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if (GUILayout.Button("Generate Random Cards"))
|
||||
{
|
||||
tester.GenerateRandomCards();
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Clear All Cards"))
|
||||
{
|
||||
tester.ClearAllCards();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Simple attribute to make fields read-only in the inspector
|
||||
public class ReadOnlyAttribute : PropertyAttribute { }
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
|
||||
public class ReadOnlyDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
GUI.enabled = false;
|
||||
EditorGUI.PropertyField(position, property, label, true);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
3
Assets/Scripts/Tests/CardSystemTester.cs.meta
Normal file
3
Assets/Scripts/Tests/CardSystemTester.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c59c766505c4342983594dbe19f3db0
|
||||
timeCreated: 1760951960
|
||||
@@ -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