Merge a card refresh (#59)
- **Refactored Card Placement Flow** - Separated card presentation from orchestration logic - Extracted `CornerCardManager` for pending card lifecycle (spawn, shuffle, rebuild) - Extracted `AlbumNavigationService` for book page navigation and zone mapping - Extracted `CardEnlargeController` for backdrop management and card reparenting - Implemented controller pattern (non-MonoBehaviour) for complex logic - Cards now unparent from slots before rebuild to prevent premature destruction - **Improved Corner Card Display** - Fixed cards spawning on top of each other during rebuild - Implemented shuffle-to-front logic (remaining cards occupy slots 0→1→2) - Added smart card selection (prioritizes cards matching current album page) - Pending cards now removed from queue immediately on drag start - Corner cards rebuild after each placement with proper slot reassignment - **Enhanced Album Card Viewing** - Added dramatic scale increase when viewing cards from album slots - Implemented shrink animation when dismissing enlarged cards - Cards transition: `PlacedInSlotState` → `AlbumEnlargedState` → `PlacedInSlotState` - Backdrop shows/hides with card enlarge/shrink cycle - Cards reparent to enlarged container while viewing, return to slot after - **State Machine Improvements** - Added `CardStateNames` constants for type-safe state transitions - Implemented `ICardClickHandler` and `ICardStateDragHandler` interfaces - State transitions now use cached property indices - `BoosterCardContext` separated from `CardContext` for single responsibility - **Code Cleanup** - Identified unused `SlotContainerHelper.cs` (superseded by `CornerCardManager`) - Identified unused `BoosterPackDraggable.canOpenOnDrop` field - Identified unused `AlbumViewPage._previousInputMode` (hardcoded value) - Identified unused `Card.OnPlacedInAlbumSlot` event (no subscribers) Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com> Co-authored-by: Michal Pikulski <michal@foolhardyhorizons.com> Reviewed-on: #59
This commit is contained in:
@@ -20,8 +20,10 @@ namespace AppleHills.Editor
|
||||
|
||||
// Cache for display
|
||||
private Dictionary<CardRarity, List<CardData>> cardsByRarity = new Dictionary<CardRarity, List<CardData>>();
|
||||
private List<CardData> pendingCards = new List<CardData>();
|
||||
private int totalCards = 0;
|
||||
private int totalUniqueCards = 0;
|
||||
private int totalPendingCards = 0;
|
||||
private int boosterCount = 0;
|
||||
private string lastEventMessage = "";
|
||||
|
||||
@@ -72,6 +74,8 @@ namespace AppleHills.Editor
|
||||
CardSystemManager.Instance.OnBoosterOpened += OnBoosterOpened;
|
||||
CardSystemManager.Instance.OnCardCollected += OnCardCollected;
|
||||
CardSystemManager.Instance.OnBoosterCountChanged += OnBoosterCountChanged;
|
||||
CardSystemManager.Instance.OnPendingCardAdded += OnPendingCardAdded;
|
||||
CardSystemManager.Instance.OnPendingCardRemoved += OnPendingCardRemoved;
|
||||
|
||||
isSubscribed = true;
|
||||
Debug.Log("[CardSystemLivePreview] Subscribed to CardSystemManager events");
|
||||
@@ -87,6 +91,8 @@ namespace AppleHills.Editor
|
||||
CardSystemManager.Instance.OnBoosterOpened -= OnBoosterOpened;
|
||||
CardSystemManager.Instance.OnCardCollected -= OnCardCollected;
|
||||
CardSystemManager.Instance.OnBoosterCountChanged -= OnBoosterCountChanged;
|
||||
CardSystemManager.Instance.OnPendingCardAdded -= OnPendingCardAdded;
|
||||
CardSystemManager.Instance.OnPendingCardRemoved -= OnPendingCardRemoved;
|
||||
}
|
||||
|
||||
isSubscribed = false;
|
||||
@@ -114,21 +120,40 @@ namespace AppleHills.Editor
|
||||
Repaint();
|
||||
}
|
||||
|
||||
private void OnPendingCardAdded(CardData card)
|
||||
{
|
||||
lastEventMessage = $"Pending card added: {card.Name} ({card.Rarity})";
|
||||
RefreshData();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
private void OnPendingCardRemoved(CardData card)
|
||||
{
|
||||
lastEventMessage = $"Card removed from pending: {card.Name} ({card.Rarity}) - being placed";
|
||||
RefreshData();
|
||||
Repaint();
|
||||
}
|
||||
|
||||
private void RefreshData()
|
||||
{
|
||||
if (!Application.isPlaying || CardSystemManager.Instance == null) return;
|
||||
|
||||
var allCards = CardSystemManager.Instance.GetAllCollectedCards();
|
||||
// Get ONLY collected cards (not pending) to avoid duplicates
|
||||
var collectedCards = CardSystemManager.Instance.GetCollectionOnly();
|
||||
|
||||
// Group by rarity
|
||||
cardsByRarity.Clear();
|
||||
cardsByRarity[CardRarity.Normal] = allCards.Where(c => c.Rarity == CardRarity.Normal).ToList();
|
||||
cardsByRarity[CardRarity.Rare] = allCards.Where(c => c.Rarity == CardRarity.Rare).ToList();
|
||||
cardsByRarity[CardRarity.Legendary] = allCards.Where(c => c.Rarity == CardRarity.Legendary).ToList();
|
||||
cardsByRarity[CardRarity.Normal] = collectedCards.Where(c => c.Rarity == CardRarity.Normal).ToList();
|
||||
cardsByRarity[CardRarity.Rare] = collectedCards.Where(c => c.Rarity == CardRarity.Rare).ToList();
|
||||
cardsByRarity[CardRarity.Legendary] = collectedCards.Where(c => c.Rarity == CardRarity.Legendary).ToList();
|
||||
|
||||
totalCards = allCards.Sum(c => c.CopiesOwned);
|
||||
totalUniqueCards = allCards.Count;
|
||||
totalCards = collectedCards.Sum(c => c.CopiesOwned);
|
||||
totalUniqueCards = collectedCards.Count;
|
||||
boosterCount = CardSystemManager.Instance.GetBoosterPackCount();
|
||||
|
||||
// Get pending cards separately
|
||||
pendingCards = CardSystemManager.Instance.GetPendingRevealCards();
|
||||
totalPendingCards = pendingCards.Count;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -173,6 +198,7 @@ namespace AppleHills.Editor
|
||||
EditorGUILayout.LabelField("Total Unique Cards:", totalUniqueCards.ToString());
|
||||
EditorGUILayout.LabelField("Total Cards Owned:", totalCards.ToString());
|
||||
EditorGUILayout.LabelField("Booster Packs:", boosterCount.ToString());
|
||||
EditorGUILayout.LabelField("Pending Reveal:", totalPendingCards.ToString(), EditorStyles.boldLabel);
|
||||
|
||||
if (!string.IsNullOrEmpty(lastEventMessage))
|
||||
{
|
||||
@@ -187,6 +213,13 @@ namespace AppleHills.Editor
|
||||
// Collection by Rarity
|
||||
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
|
||||
|
||||
// Pending Cards Section
|
||||
if (totalPendingCards > 0)
|
||||
{
|
||||
DrawPendingCardsSection();
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
DrawRaritySection(CardRarity.Legendary, Color.yellow);
|
||||
DrawRaritySection(CardRarity.Rare, new Color(0.5f, 0.5f, 1f)); // Light blue
|
||||
DrawRaritySection(CardRarity.Normal, Color.white);
|
||||
@@ -208,6 +241,52 @@ namespace AppleHills.Editor
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private void DrawPendingCardsSection()
|
||||
{
|
||||
var oldColor = GUI.backgroundColor;
|
||||
GUI.backgroundColor = new Color(1f, 0.8f, 0.4f); // Orange tint for pending
|
||||
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUI.backgroundColor = oldColor;
|
||||
|
||||
GUILayout.Label($"⏳ Pending Reveal ({pendingCards.Count} cards)", EditorStyles.boldLabel);
|
||||
|
||||
// Group pending by rarity for display
|
||||
var pendingByRarity = pendingCards.GroupBy(c => c.Rarity).OrderByDescending(g => g.Key);
|
||||
|
||||
foreach (var rarityGroup in pendingByRarity)
|
||||
{
|
||||
EditorGUILayout.Space(5);
|
||||
var rarityColor = GetRarityColor(rarityGroup.Key);
|
||||
|
||||
oldColor = GUI.color;
|
||||
GUI.color = rarityColor;
|
||||
GUILayout.Label($"{rarityGroup.Key} ({rarityGroup.Count()})", EditorStyles.miniBoldLabel);
|
||||
GUI.color = oldColor;
|
||||
|
||||
foreach (var card in rarityGroup.OrderBy(c => c.Name))
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField(" • " + card.Name, GUILayout.Width(200));
|
||||
EditorGUILayout.LabelField(card.Zone.ToString(), GUILayout.Width(100));
|
||||
EditorGUILayout.LabelField($"Copies: {card.CopiesOwned}", GUILayout.Width(80));
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
private Color GetRarityColor(CardRarity rarity)
|
||||
{
|
||||
switch (rarity)
|
||||
{
|
||||
case CardRarity.Legendary: return Color.yellow;
|
||||
case CardRarity.Rare: return new Color(0.5f, 0.5f, 1f);
|
||||
case CardRarity.Normal: return Color.white;
|
||||
default: return Color.gray;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawRaritySection(CardRarity rarity, Color color)
|
||||
{
|
||||
if (!cardsByRarity.ContainsKey(rarity) || cardsByRarity[rarity].Count == 0)
|
||||
|
||||
@@ -216,6 +216,13 @@ namespace Editor.CardSystem
|
||||
|
||||
EditorGUILayout.Space(5);
|
||||
|
||||
if (GUILayout.Button("Populate Pending (6 Unique Cards)", GUILayout.Height(30)))
|
||||
{
|
||||
PopulatePendingCards();
|
||||
}
|
||||
|
||||
EditorGUILayout.Space(5);
|
||||
|
||||
// Danger Zone
|
||||
EditorGUILayout.Space(10);
|
||||
EditorGUILayout.LabelField("Danger Zone", EditorStyles.miniBoldLabel);
|
||||
@@ -304,6 +311,53 @@ namespace Editor.CardSystem
|
||||
}
|
||||
}
|
||||
|
||||
private void PopulatePendingCards()
|
||||
{
|
||||
if (CardSystemManager.Instance != null)
|
||||
{
|
||||
List<CardDefinition> allDefinitions = CardSystemManager.Instance.GetAllCardDefinitions();
|
||||
|
||||
if (allDefinitions.Count == 0)
|
||||
{
|
||||
lastActionMessage = "Error: No card definitions available";
|
||||
Logging.Warning($"[CardSystemTesterWindow] {lastActionMessage}");
|
||||
Repaint();
|
||||
return;
|
||||
}
|
||||
|
||||
// Ensure we have enough definitions to pick 6 unique cards
|
||||
int cardsToAdd = Mathf.Min(6, allDefinitions.Count);
|
||||
|
||||
// Shuffle definitions to get random unique cards
|
||||
List<CardDefinition> shuffledDefs = new List<CardDefinition>(allDefinitions);
|
||||
for (int i = 0; i < shuffledDefs.Count; i++)
|
||||
{
|
||||
int randomIndex = Random.Range(i, shuffledDefs.Count);
|
||||
(shuffledDefs[i], shuffledDefs[randomIndex]) = (shuffledDefs[randomIndex], shuffledDefs[i]);
|
||||
}
|
||||
|
||||
// Add first 6 unique cards to pending
|
||||
// AddCardToInventoryDelayed automatically routes NEW cards to pending queue
|
||||
int cardsAdded = 0;
|
||||
for (int i = 0; i < cardsToAdd; i++)
|
||||
{
|
||||
CardData newCard = shuffledDefs[i].CreateCardData();
|
||||
CardSystemManager.Instance.AddCardToInventoryDelayed(newCard);
|
||||
cardsAdded++;
|
||||
}
|
||||
|
||||
lastActionMessage = $"Added {cardsAdded} unique cards to pending reveal queue";
|
||||
Logging.Debug($"[CardSystemTesterWindow] {lastActionMessage}");
|
||||
RefreshDebugInfo();
|
||||
}
|
||||
else
|
||||
{
|
||||
lastActionMessage = "Error: CardSystemManager instance not found!";
|
||||
Debug.LogError("[CardSystemTesterWindow] " + lastActionMessage);
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearAllCards()
|
||||
{
|
||||
if (CardSystemManager.Instance != null)
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace AppleHills.Core.Settings.Editor
|
||||
{
|
||||
private Vector2 scrollPosition;
|
||||
private List<BaseSettings> allSettings = new List<BaseSettings>();
|
||||
private string[] tabNames = new string[] { "Player & Follower", "Interaction & Items", "Diving Minigame" };
|
||||
private string[] tabNames = new string[] { "Player & Follower", "Interaction & Items", "Diving Minigame", "Card System" };
|
||||
private int selectedTab = 0;
|
||||
private Dictionary<string, SerializedObject> serializedSettingsObjects = new Dictionary<string, SerializedObject>();
|
||||
private GUIStyle headerStyle;
|
||||
@@ -48,6 +48,7 @@ namespace AppleHills.Core.Settings.Editor
|
||||
CreateSettingsIfMissing<PlayerFollowerSettings>("PlayerFollowerSettings");
|
||||
CreateSettingsIfMissing<InteractionSettings>("InteractionSettings");
|
||||
CreateSettingsIfMissing<DivingMinigameSettings>("DivingMinigameSettings");
|
||||
CreateSettingsIfMissing<CardSystemSettings>("CardSystemSettings");
|
||||
}
|
||||
|
||||
private void CreateSettingsIfMissing<T>(string fileName) where T : BaseSettings
|
||||
@@ -114,6 +115,9 @@ namespace AppleHills.Core.Settings.Editor
|
||||
case 2: // Minigames
|
||||
DrawSettingsEditor<DivingMinigameSettings>();
|
||||
break;
|
||||
case 3: // Card System
|
||||
DrawSettingsEditor<CardSystemSettings>();
|
||||
break;
|
||||
}
|
||||
|
||||
EditorGUILayout.EndScrollView();
|
||||
|
||||
Reference in New Issue
Block a user