Cleanup the card implementation, add some readme files and update namespaces
This commit is contained in:
@@ -4,10 +4,11 @@ using Core;
|
||||
using Data.CardSystem;
|
||||
using Pixelplacement;
|
||||
using TMPro;
|
||||
using UI.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
namespace UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// UI page for viewing the player's card collection in an album.
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using Pixelplacement;
|
||||
using Pixelplacement;
|
||||
using Pixelplacement.TweenSystem;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
namespace UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages a notification dot that displays a count (e.g., booster packs)
|
||||
|
||||
@@ -4,11 +4,11 @@ using AppleHills.Data.CardSystem;
|
||||
using Core;
|
||||
using Data.CardSystem;
|
||||
using Pixelplacement;
|
||||
using TMPro;
|
||||
using UI.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
namespace UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// UI page for opening booster packs and displaying the cards obtained.
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using Core;
|
||||
using Data.CardSystem;
|
||||
using Pixelplacement;
|
||||
using UI.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
namespace UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Main UI controller for the card album system.
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using Core;
|
||||
using Core;
|
||||
using Data.CardSystem;
|
||||
using Pixelplacement;
|
||||
using TMPro;
|
||||
using UI.Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
namespace UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// UI page for the main menu of the card system.
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using Core;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
namespace UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles displaying and interacting with a single card in the UI.
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for UI pages that can transition in and out.
|
||||
/// Extended by specific UI page implementations for the card system.
|
||||
/// </summary>
|
||||
public abstract class UIPage : MonoBehaviour
|
||||
{
|
||||
[Header("Page Settings")]
|
||||
public string PageName;
|
||||
|
||||
// Events using System.Action instead of UnityEvents
|
||||
public event Action OnTransitionInStarted;
|
||||
public event Action OnTransitionInCompleted;
|
||||
public event Action OnTransitionOutStarted;
|
||||
public event Action OnTransitionOutCompleted;
|
||||
|
||||
// Default duration for transitions
|
||||
[SerializeField] protected float transitionDuration = 0.3f;
|
||||
|
||||
// State flags
|
||||
protected bool _isTransitioning = false;
|
||||
protected bool _isVisible = false;
|
||||
|
||||
/// <summary>
|
||||
/// Called when the page is shown. Handles the transition in animation.
|
||||
/// </summary>
|
||||
public virtual void TransitionIn()
|
||||
{
|
||||
gameObject.SetActive(true);
|
||||
_isTransitioning = true;
|
||||
OnTransitionInStarted?.Invoke();
|
||||
|
||||
// Override in child classes for specific transition animations
|
||||
DoTransitionIn(() => {
|
||||
_isTransitioning = false;
|
||||
_isVisible = true;
|
||||
OnTransitionInCompleted?.Invoke();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the page is hidden. Handles the transition out animation.
|
||||
/// </summary>
|
||||
public virtual void TransitionOut()
|
||||
{
|
||||
_isTransitioning = true;
|
||||
OnTransitionOutStarted?.Invoke();
|
||||
|
||||
// Override in child classes for specific transition animations
|
||||
DoTransitionOut(() => {
|
||||
_isTransitioning = false;
|
||||
_isVisible = false;
|
||||
OnTransitionOutCompleted?.Invoke();
|
||||
gameObject.SetActive(false);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the back button is pressed while this page is active.
|
||||
/// Default implementation pops the page from the stack.
|
||||
/// </summary>
|
||||
public virtual void OnBackPressed()
|
||||
{
|
||||
if (!_isTransitioning)
|
||||
{
|
||||
UIPageController.Instance.PopPage();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implement transition in animation in child classes.
|
||||
/// </summary>
|
||||
protected virtual void DoTransitionIn(Action onComplete)
|
||||
{
|
||||
// Default implementation - instant transition
|
||||
onComplete?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Implement transition out animation in child classes.
|
||||
/// </summary>
|
||||
protected virtual void DoTransitionOut(Action onComplete)
|
||||
{
|
||||
// Default implementation - instant transition
|
||||
onComplete?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57fa26be941c43dc9331534ab59416b1
|
||||
timeCreated: 1759923734
|
||||
@@ -1,150 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Bootstrap;
|
||||
using Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
namespace AppleHills.UI.CardSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Manages UI page transitions and maintains a stack of active pages.
|
||||
/// Pages are pushed onto a stack for navigation and popped when going back.
|
||||
/// </summary>
|
||||
public class UIPageController : MonoBehaviour
|
||||
{
|
||||
private static UIPageController _instance;
|
||||
public static UIPageController Instance => _instance;
|
||||
|
||||
private Stack<UIPage> _pageStack = new Stack<UIPage>();
|
||||
public UIPage CurrentPage => _pageStack.Count > 0 ? _pageStack.Peek() : null;
|
||||
|
||||
// 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)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
_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()
|
||||
{
|
||||
// Initialize any dependencies that require other services to be ready
|
||||
Logging.Debug("[UIPageController] Post-boot initialization complete");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pushes a new page onto the stack, hiding the current page and showing the new one.
|
||||
/// </summary>
|
||||
public void PushPage(UIPage page)
|
||||
{
|
||||
if (page == null) return;
|
||||
|
||||
// Hide current page if there is one
|
||||
if (_pageStack.Count > 0)
|
||||
{
|
||||
UIPage currentPage = _pageStack.Peek();
|
||||
currentPage.TransitionOut();
|
||||
}
|
||||
|
||||
// Push and show new page
|
||||
_pageStack.Push(page);
|
||||
page.TransitionIn();
|
||||
|
||||
OnPageChanged?.Invoke(page);
|
||||
Logging.Debug($"[UIPageController] Pushed page: {page.PageName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pops the current page from the stack and shows the previous page.
|
||||
/// </summary>
|
||||
public void PopPage()
|
||||
{
|
||||
if (_pageStack.Count <= 0) return;
|
||||
|
||||
// Hide and pop current page
|
||||
UIPage currentPage = _pageStack.Pop();
|
||||
currentPage.TransitionOut();
|
||||
|
||||
// Show previous page if there is one
|
||||
if (_pageStack.Count > 0)
|
||||
{
|
||||
UIPage previousPage = _pageStack.Peek();
|
||||
previousPage.TransitionIn();
|
||||
OnPageChanged?.Invoke(previousPage);
|
||||
Logging.Debug($"[UIPageController] Popped to previous page: {previousPage.PageName}");
|
||||
}
|
||||
else
|
||||
{
|
||||
OnPageChanged?.Invoke(null);
|
||||
Logging.Debug("[UIPageController] Popped last page, no pages left in stack");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears all pages from the stack.
|
||||
/// </summary>
|
||||
public void ClearStack()
|
||||
{
|
||||
if (_pageStack.Count <= 0) return;
|
||||
|
||||
// Hide current page
|
||||
UIPage currentPage = _pageStack.Peek();
|
||||
currentPage.TransitionOut();
|
||||
|
||||
// Clear stack
|
||||
_pageStack.Clear();
|
||||
OnPageChanged?.Invoke(null);
|
||||
Logging.Debug("[UIPageController] Cleared page stack");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1ae6c1745e44e22a0fa9209ebe45ee3
|
||||
timeCreated: 1759923720
|
||||
Reference in New Issue
Block a user