Roll the pause menu into the UI page system

This commit is contained in:
Michal Adam Pikulski
2025-10-22 09:35:34 +02:00
parent 357f942e0d
commit 68886aafd4
8 changed files with 395 additions and 151 deletions

View File

@@ -1,36 +0,0 @@
using UnityEngine;
public class BackpackInput : MonoBehaviour, ITouchInputConsumer
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void OnTap(Vector2 position)
{
return;
}
public void OnHoldStart(Vector2 position)
{
return;
}
public void OnHoldMove(Vector2 position)
{
return;
}
public void OnHoldEnd(Vector2 position)
{
return;
}
}

View File

@@ -0,0 +1,39 @@
using UnityEngine;
namespace UI.CardSystem
{
public class BackpackInput : MonoBehaviour, ITouchInputConsumer
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void OnTap(Vector2 position)
{
return;
}
public void OnHoldStart(Vector2 position)
{
return;
}
public void OnHoldMove(Vector2 position)
{
return;
}
public void OnHoldEnd(Vector2 position)
{
return;
}
}
}

View File

@@ -0,0 +1,39 @@
using UnityEngine;
namespace UI
{
public class DummyInput : MonoBehaviour, ITouchInputConsumer
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void OnTap(Vector2 position)
{
return;
}
public void OnHoldStart(Vector2 position)
{
return;
}
public void OnHoldMove(Vector2 position)
{
return;
}
public void OnHoldEnd(Vector2 position)
{
return;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 494d0aedce9744308499355006071138
timeCreated: 1761117932

View File

@@ -4,10 +4,12 @@ using UnityEngine;
using UnityEngine.SceneManagement;
using Input;
using Bootstrap;
using UI.Core;
using Pixelplacement;
namespace UI
{
public class PauseMenu : MonoBehaviour, ITouchInputConsumer
public class PauseMenu : UIPage
{
private static PauseMenu _instance;
private static bool _isQuitting;
@@ -20,6 +22,7 @@ namespace UI
[Header("UI References")]
[SerializeField] private GameObject pauseMenuPanel;
[SerializeField] private GameObject pauseButton;
[SerializeField] private CanvasGroup canvasGroup;
public event Action OnGamePaused;
public event Action OnGameResumed;
@@ -35,6 +38,16 @@ namespace UI
{
_instance = this;
// Ensure we have a CanvasGroup for transitions
if (canvasGroup == null)
canvasGroup = GetComponent<CanvasGroup>();
if (canvasGroup == null)
canvasGroup = gameObject.AddComponent<CanvasGroup>();
canvasGroup.alpha = 0f;
canvasGroup.interactable = false;
canvasGroup.blocksRaycasts = false;
gameObject.SetActive(false);
// Register for post-boot initialization
BootCompletionService.RegisterInitAction(InitializePostBoot);
}
@@ -90,18 +103,26 @@ namespace UI
/// </summary>
public void ShowPauseMenu()
{
if (pauseMenuPanel != null)
pauseMenuPanel.SetActive(true);
if (pauseButton != null)
pauseButton.SetActive(false);
// Set paused flag and broadcast event
_isPaused = true;
InputManager.Instance.SetInputMode(InputMode.UI);
OnGamePaused?.Invoke();
Logging.Debug("[PauseMenu] Game Paused");
if (_isPaused) return;
if (UIPageController.Instance != null)
{
UIPageController.Instance.PushPage(this);
}
else
{
// Fallback if no controller, just show
if (pauseMenuPanel != null)
pauseMenuPanel.SetActive(true);
gameObject.SetActive(true);
BeginPauseSideEffects();
// no animation fallback
if (canvasGroup != null)
{
canvasGroup.alpha = 1f;
canvasGroup.interactable = true;
canvasGroup.blocksRaycasts = true;
}
}
}
/// <summary>
@@ -109,19 +130,33 @@ namespace UI
/// </summary>
public void HidePauseMenu(bool resetInput = true)
{
if (pauseMenuPanel != null)
pauseMenuPanel.SetActive(false);
if (pauseButton != null)
pauseButton.SetActive(true);
// Clear paused flag and broadcast event
_isPaused = false;
InputManager.Instance.SetInputMode(InputMode.GameAndUI);
if(resetInput)
OnGameResumed?.Invoke();
Logging.Debug("[PauseMenu] Game Resumed");
if (!_isPaused)
{
// Ensure UI is hidden if somehow active without state
if (pauseMenuPanel != null) pauseMenuPanel.SetActive(false);
gameObject.SetActive(false);
return;
}
if (UIPageController.Instance != null && UIPageController.Instance.CurrentPage == this)
{
UIPageController.Instance.PopPage();
}
else
{
// Fallback if no controller, just hide
if (pauseMenuPanel != null)
pauseMenuPanel.SetActive(false);
if (pauseButton != null)
pauseButton.SetActive(true);
EndPauseSideEffects(resetInput);
if (canvasGroup != null)
{
canvasGroup.alpha = 0f;
canvasGroup.interactable = false;
canvasGroup.blocksRaycasts = false;
}
gameObject.SetActive(false);
}
}
/// <summary>
@@ -132,6 +167,64 @@ namespace UI
HidePauseMenu();
}
private void BeginPauseSideEffects()
{
_isPaused = true;
if (pauseButton != null) pauseButton.SetActive(false);
InputManager.Instance.SetInputMode(InputMode.UI);
OnGamePaused?.Invoke();
Logging.Debug("[PauseMenu] Game Paused");
}
private void EndPauseSideEffects(bool invokeEvent)
{
_isPaused = false;
if (pauseButton != null) pauseButton.SetActive(true);
InputManager.Instance.SetInputMode(InputMode.GameAndUI);
if (invokeEvent) OnGameResumed?.Invoke();
Logging.Debug("[PauseMenu] Game Resumed");
}
protected override void DoTransitionIn(Action onComplete)
{
// Ensure the panel root is active
if (pauseMenuPanel != null) pauseMenuPanel.SetActive(true);
BeginPauseSideEffects();
if (canvasGroup != null)
{
canvasGroup.interactable = true;
canvasGroup.blocksRaycasts = true;
canvasGroup.alpha = 0f;
Tween.Value(0f, 1f, v => canvasGroup.alpha = v, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete);
}
else
{
onComplete?.Invoke();
}
}
protected override void DoTransitionOut(Action onComplete)
{
if (canvasGroup != null)
{
canvasGroup.interactable = false;
canvasGroup.blocksRaycasts = false;
Tween.Value(canvasGroup.alpha, 0f, v => canvasGroup.alpha = v, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, () =>
{
EndPauseSideEffects(true);
if (pauseMenuPanel != null) pauseMenuPanel.SetActive(false);
onComplete?.Invoke();
});
}
else
{
EndPauseSideEffects(true);
if (pauseMenuPanel != null) pauseMenuPanel.SetActive(false);
onComplete?.Invoke();
}
}
/// <summary>
/// Exits to the main menu scene.
/// </summary>
@@ -185,25 +278,5 @@ namespace UI
break;
}
}
public void OnTap(Vector2 position)
{
ShowPauseMenu();
}
public void OnHoldStart(Vector2 position)
{
throw new NotImplementedException();
}
public void OnHoldMove(Vector2 position)
{
throw new NotImplementedException();
}
public void OnHoldEnd(Vector2 position)
{
throw new NotImplementedException();
}
}
}