2025-11-06 10:10:54 +01:00
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using AppleHills.Data.CardSystem;
|
|
|
|
|
|
using Data.CardSystem;
|
|
|
|
|
|
using Core;
|
|
|
|
|
|
using UI.CardSystem;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Editor.CardSystem
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Editor window for testing the Card System in play mode.
|
|
|
|
|
|
/// Provides buttons to test core functionalities like adding booster packs, opening packs, and generating cards.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class CardSystemTesterWindow : EditorWindow
|
|
|
|
|
|
{
|
|
|
|
|
|
// Test Settings
|
|
|
|
|
|
private int boosterPacksToAdd = 3;
|
|
|
|
|
|
private int cardsToGenerate = 10;
|
|
|
|
|
|
|
|
|
|
|
|
// Debug Info
|
|
|
|
|
|
private int currentBoosterCount;
|
|
|
|
|
|
private int totalCardsInCollection;
|
|
|
|
|
|
private string lastActionMessage = "";
|
|
|
|
|
|
|
|
|
|
|
|
// UI State
|
|
|
|
|
|
private Vector2 scrollPosition;
|
|
|
|
|
|
|
|
|
|
|
|
[MenuItem("AppleHills/Card System Tester")]
|
|
|
|
|
|
public static void ShowWindow()
|
|
|
|
|
|
{
|
|
|
|
|
|
var window = GetWindow<CardSystemTesterWindow>(false, "Card System Tester", true);
|
|
|
|
|
|
window.minSize = new Vector2(400, 500);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnEnable()
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnDisable()
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnPlayModeStateChanged(PlayModeStateChange state)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (state == PlayModeStateChange.EnteredPlayMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
RefreshDebugInfo();
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (state == PlayModeStateChange.ExitingPlayMode)
|
|
|
|
|
|
{
|
|
|
|
|
|
lastActionMessage = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Repaint();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnGUI()
|
|
|
|
|
|
{
|
|
|
|
|
|
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
|
|
|
|
|
|
|
|
|
|
|
|
// Header
|
|
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
|
|
EditorGUILayout.LabelField("Card System Tester", EditorStyles.boldLabel);
|
|
|
|
|
|
EditorGUILayout.HelpBox("This tool allows you to test the card system in play mode. " +
|
|
|
|
|
|
"Enter play mode to enable the testing functions.", MessageType.Info);
|
|
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
|
|
|
|
|
|
|
|
// Test Settings Section
|
|
|
|
|
|
DrawTestSettings();
|
|
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
|
|
|
|
|
|
|
|
// Debug Info Section
|
|
|
|
|
|
DrawDebugInfo();
|
|
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
|
|
|
|
|
|
|
|
// Test Actions Section
|
|
|
|
|
|
DrawTestActions();
|
|
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.EndScrollView();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void DrawTestSettings()
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorGUILayout.LabelField("Test Settings", EditorStyles.boldLabel);
|
|
|
|
|
|
|
|
|
|
|
|
EditorGUI.BeginDisabledGroup(!Application.isPlaying);
|
|
|
|
|
|
|
|
|
|
|
|
boosterPacksToAdd = EditorGUILayout.IntSlider("Booster Packs to Add", boosterPacksToAdd, 1, 10);
|
|
|
|
|
|
cardsToGenerate = EditorGUILayout.IntSlider("Cards to Generate", cardsToGenerate, 1, 100);
|
|
|
|
|
|
|
|
|
|
|
|
EditorGUI.EndDisabledGroup();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void DrawDebugInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorGUILayout.LabelField("Debug Info", EditorStyles.boldLabel);
|
|
|
|
|
|
|
|
|
|
|
|
if (Application.isPlaying)
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorGUI.BeginDisabledGroup(true);
|
|
|
|
|
|
EditorGUILayout.IntField("Current Booster Count", currentBoosterCount);
|
|
|
|
|
|
EditorGUILayout.IntField("Total Cards in Collection", totalCardsInCollection);
|
|
|
|
|
|
EditorGUI.EndDisabledGroup();
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(lastActionMessage))
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorGUILayout.Space(5);
|
|
|
|
|
|
EditorGUILayout.HelpBox(lastActionMessage, MessageType.None);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.Space(5);
|
|
|
|
|
|
if (GUILayout.Button("Refresh Debug Info"))
|
|
|
|
|
|
{
|
|
|
|
|
|
RefreshDebugInfo();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorGUILayout.HelpBox("Debug info available in play mode.", MessageType.Warning);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void DrawTestActions()
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorGUILayout.LabelField("Test Actions", EditorStyles.boldLabel);
|
|
|
|
|
|
|
|
|
|
|
|
if (!Application.isPlaying)
|
|
|
|
|
|
{
|
|
|
|
|
|
EditorGUILayout.HelpBox("Enter Play Mode to use these testing functions.", MessageType.Warning);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Booster Pack Actions
|
|
|
|
|
|
EditorGUILayout.Space(5);
|
|
|
|
|
|
EditorGUILayout.LabelField("Booster Pack Actions", EditorStyles.miniBoldLabel);
|
|
|
|
|
|
|
|
|
|
|
|
if (GUILayout.Button("Add Booster Packs", GUILayout.Height(30)))
|
|
|
|
|
|
{
|
|
|
|
|
|
AddBoosterPacks();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Card Generation Actions
|
|
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
|
|
EditorGUILayout.LabelField("Card Generation Actions", EditorStyles.miniBoldLabel);
|
|
|
|
|
|
|
|
|
|
|
|
if (GUILayout.Button("Generate Random Cards", GUILayout.Height(30)))
|
|
|
|
|
|
{
|
|
|
|
|
|
GenerateRandomCards();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.Space(5);
|
|
|
|
|
|
|
|
|
|
|
|
// Danger Zone
|
|
|
|
|
|
EditorGUILayout.Space(10);
|
|
|
|
|
|
EditorGUILayout.LabelField("Danger Zone", EditorStyles.miniBoldLabel);
|
|
|
|
|
|
|
|
|
|
|
|
GUI.backgroundColor = new Color(1f, 0.6f, 0.6f);
|
|
|
|
|
|
if (GUILayout.Button("Clear All Cards", GUILayout.Height(30)))
|
|
|
|
|
|
{
|
|
|
|
|
|
if (EditorUtility.DisplayDialog("Clear All Cards",
|
|
|
|
|
|
"Are you sure you want to clear all cards from the inventory? This cannot be undone in this play session.",
|
|
|
|
|
|
"Clear All", "Cancel"))
|
|
|
|
|
|
{
|
|
|
|
|
|
ClearAllCards();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
GUI.backgroundColor = Color.white;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Refresh the debug information
|
|
|
|
|
|
private void RefreshDebugInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Application.isPlaying)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (CardSystemManager.Instance != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
currentBoosterCount = CardSystemManager.Instance.GetBoosterPackCount();
|
|
|
|
|
|
totalCardsInCollection = CardSystemManager.Instance.GetCardInventory().GetAllCards().Count;
|
|
|
|
|
|
Repaint();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test Action Methods
|
|
|
|
|
|
|
|
|
|
|
|
private void AddBoosterPacks()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CardSystemManager.Instance != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
CardSystemManager.Instance.AddBoosterPack(boosterPacksToAdd);
|
|
|
|
|
|
lastActionMessage = $"Added {boosterPacksToAdd} booster pack(s)";
|
|
|
|
|
|
Logging.Debug($"[CardSystemTesterWindow] {lastActionMessage}");
|
|
|
|
|
|
RefreshDebugInfo();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
lastActionMessage = "Error: CardSystemManager instance not found!";
|
|
|
|
|
|
Debug.LogError("[CardSystemTesterWindow] " + lastActionMessage);
|
|
|
|
|
|
Repaint();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void GenerateRandomCards()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CardSystemManager.Instance != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
int cardsAdded = 0;
|
|
|
|
|
|
List<CardDefinition> allDefinitions = CardSystemManager.Instance.GetAllCardDefinitions();
|
|
|
|
|
|
|
|
|
|
|
|
if (allDefinitions.Count == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
lastActionMessage = "Error: No card definitions available";
|
|
|
|
|
|
Logging.Warning($"[CardSystemTesterWindow] {lastActionMessage}");
|
|
|
|
|
|
Repaint();
|
|
|
|
|
|
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.Instance.GetCardInventory().AddCard(newCard);
|
|
|
|
|
|
cardsAdded++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lastActionMessage = $"Generated {cardsAdded} random cards";
|
|
|
|
|
|
Logging.Debug($"[CardSystemTesterWindow] {lastActionMessage}");
|
|
|
|
|
|
RefreshDebugInfo();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
lastActionMessage = "Error: CardSystemManager instance not found!";
|
|
|
|
|
|
Debug.LogError("[CardSystemTesterWindow] " + lastActionMessage);
|
|
|
|
|
|
Repaint();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ClearAllCards()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (CardSystemManager.Instance != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
int count = CardSystemManager.Instance.GetCardInventory().GetAllCards().Count;
|
|
|
|
|
|
CardSystemManager.Instance.GetCardInventory().ClearAllCards();
|
|
|
|
|
|
lastActionMessage = $"Cleared {count} cards from inventory";
|
|
|
|
|
|
Logging.Debug($"[CardSystemTesterWindow] {lastActionMessage}");
|
|
|
|
|
|
RefreshDebugInfo();
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
lastActionMessage = "Error: CardSystemManager instance not found!";
|
|
|
|
|
|
Debug.LogError("[CardSystemTesterWindow] " + lastActionMessage);
|
|
|
|
|
|
Repaint();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|