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:
135
Assets/Scripts/CardSystem/UI/Component/BookTabButton.cs
Normal file
135
Assets/Scripts/CardSystem/UI/Component/BookTabButton.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using System;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using BookCurlPro;
|
||||
using Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Tween = Pixelplacement.Tween;
|
||||
|
||||
namespace UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Tab button for navigating to specific pages in the card album book.
|
||||
/// Coordinates with other tabs via static events for visual feedback.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Button))]
|
||||
public class BookTabButton : MonoBehaviour
|
||||
{
|
||||
[Header("Book Reference")]
|
||||
[SerializeField] private BookPro book;
|
||||
|
||||
[Header("Tab Configuration")]
|
||||
[SerializeField] private int targetPage;
|
||||
[SerializeField] private CardZone zone;
|
||||
|
||||
[Header("Visual Settings")]
|
||||
[SerializeField] private bool enableScaling = true;
|
||||
[SerializeField] private float selectedScale = 2.0f;
|
||||
[SerializeField] private float normalScale = 1.0f;
|
||||
[SerializeField] private float scaleTransitionDuration = 0.2f;
|
||||
|
||||
private Button button;
|
||||
private RectTransform rectTransform;
|
||||
private Vector2 originalSize;
|
||||
|
||||
// Static dispatcher for coordinating all tabs
|
||||
private static event Action<BookTabButton> OnTabClicked;
|
||||
|
||||
// Public properties to access this tab's configuration
|
||||
public CardZone Zone => zone;
|
||||
public int TargetPage => targetPage;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Get required components
|
||||
button = GetComponent<Button>();
|
||||
rectTransform = GetComponent<RectTransform>();
|
||||
|
||||
// Cache original size
|
||||
originalSize = rectTransform.sizeDelta;
|
||||
|
||||
// Register button click
|
||||
button.onClick.AddListener(OnButtonClicked);
|
||||
|
||||
// Subscribe to static tab event
|
||||
OnTabClicked += OnAnyTabClicked;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// Cleanup listeners
|
||||
if (button != null)
|
||||
{
|
||||
button.onClick.RemoveListener(OnButtonClicked);
|
||||
}
|
||||
|
||||
OnTabClicked -= OnAnyTabClicked;
|
||||
}
|
||||
|
||||
private void OnButtonClicked()
|
||||
{
|
||||
if (book == null)
|
||||
{
|
||||
Logging.Warning($"[BookTabButton] No BookPro reference assigned on {gameObject.name}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Notify all tabs that this one was clicked
|
||||
OnTabClicked?.Invoke(this);
|
||||
|
||||
// Flip to target page using AutoFlip
|
||||
BookCurlPro.AutoFlip autoFlip = book.GetComponent<BookCurlPro.AutoFlip>();
|
||||
if (autoFlip == null)
|
||||
{
|
||||
autoFlip = book.gameObject.AddComponent<BookCurlPro.AutoFlip>();
|
||||
}
|
||||
|
||||
autoFlip.enabled = true;
|
||||
autoFlip.StartFlipping(targetPage);
|
||||
}
|
||||
|
||||
private void OnAnyTabClicked(BookTabButton clickedTab)
|
||||
{
|
||||
// Skip scaling if disabled
|
||||
if (!enableScaling) return;
|
||||
|
||||
// Scale this tab based on whether it was clicked
|
||||
if (clickedTab == this)
|
||||
{
|
||||
SetScale(selectedScale);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetScale(normalScale);
|
||||
}
|
||||
}
|
||||
|
||||
private void SetScale(float targetScale)
|
||||
{
|
||||
Vector2 targetSize = originalSize * targetScale;
|
||||
|
||||
// Use Pixelplacement Tween for smooth size change
|
||||
Tween.Value(rectTransform.sizeDelta, targetSize,
|
||||
(Vector2 value) => rectTransform.sizeDelta = value,
|
||||
scaleTransitionDuration, 0f, Tween.EaseInOut);
|
||||
}
|
||||
|
||||
// Public method to programmatically trigger this tab
|
||||
public void ActivateTab()
|
||||
{
|
||||
OnButtonClicked();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnValidate()
|
||||
{
|
||||
// Ensure target page is non-negative
|
||||
if (targetPage < 0)
|
||||
{
|
||||
targetPage = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user