Fix up the UI + game flow in minigame, should function correctly now
This commit is contained in:
@@ -2,7 +2,6 @@ using System;
|
||||
using Core;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Input;
|
||||
using Bootstrap;
|
||||
using UI.Core;
|
||||
using Pixelplacement;
|
||||
@@ -47,6 +46,13 @@ namespace UI
|
||||
// Subscribe to scene loaded events
|
||||
SceneManagerService.Instance.SceneLoadCompleted += SetPauseMenuByLevel;
|
||||
|
||||
// Also react to global UI hide/show events from the page controller
|
||||
if (UIPageController.Instance != null)
|
||||
{
|
||||
UIPageController.Instance.OnAllUIHidden += HandleAllUIHidden;
|
||||
UIPageController.Instance.OnAllUIShown += HandleAllUIShown;
|
||||
}
|
||||
|
||||
// SceneManagerService subscription moved to InitializePostBoot
|
||||
|
||||
// Set initial state based on current scene
|
||||
@@ -62,6 +68,11 @@ namespace UI
|
||||
{
|
||||
SceneManagerService.Instance.SceneLoadCompleted -= SetPauseMenuByLevel;
|
||||
}
|
||||
if (UIPageController.Instance != null)
|
||||
{
|
||||
UIPageController.Instance.OnAllUIHidden -= HandleAllUIHidden;
|
||||
UIPageController.Instance.OnAllUIShown -= HandleAllUIShown;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -132,7 +143,6 @@ namespace UI
|
||||
pauseMenuPanel.SetActive(false);
|
||||
if (pauseButton != null)
|
||||
pauseButton.SetActive(true);
|
||||
EndPauseSideEffects();
|
||||
if (canvasGroup != null)
|
||||
{
|
||||
canvasGroup.alpha = 0f;
|
||||
@@ -143,12 +153,18 @@ namespace UI
|
||||
}
|
||||
}
|
||||
|
||||
public void HidePauseMenuAndResumeGame()
|
||||
{
|
||||
HidePauseMenu();
|
||||
EndPauseSideEffects();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resumes the game by hiding the pause menu.
|
||||
/// </summary>
|
||||
public void ResumeGame()
|
||||
{
|
||||
HidePauseMenu();
|
||||
HidePauseMenuAndResumeGame();
|
||||
}
|
||||
|
||||
private void BeginPauseSideEffects()
|
||||
@@ -253,7 +269,7 @@ namespace UI
|
||||
public async void LoadLevel(int levelSelection)
|
||||
{
|
||||
// Hide the pause menu before loading a new level
|
||||
HidePauseMenu();
|
||||
HidePauseMenuAndResumeGame();
|
||||
|
||||
// Replace with the actual scene name as set in Build Settings
|
||||
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
|
||||
@@ -270,5 +286,42 @@ namespace UI
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Handlers for UI controller hide/show events — make these safe with respect to transitions and pause state
|
||||
private void HandleAllUIHidden()
|
||||
{
|
||||
var parent = transform.parent?.gameObject ?? gameObject;
|
||||
|
||||
// If we're currently transitioning, wait for the transition out to complete before deactivating
|
||||
if (_isTransitioning)
|
||||
{
|
||||
Action handler = null;
|
||||
handler = () =>
|
||||
{
|
||||
OnTransitionOutCompleted -= handler;
|
||||
parent.SetActive(false);
|
||||
};
|
||||
OnTransitionOutCompleted += handler;
|
||||
return;
|
||||
}
|
||||
|
||||
// If this page is visible, request a proper hide so transition/out side-effects run (e.g. releasing pause)
|
||||
if (_isVisible)
|
||||
{
|
||||
HidePauseMenu();
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise it's safe to immediately deactivate
|
||||
parent.SetActive(false);
|
||||
}
|
||||
|
||||
private void HandleAllUIShown()
|
||||
{
|
||||
var parent = transform.parent?.gameObject ?? gameObject;
|
||||
|
||||
// Just ensure the parent is active. Do not force pause or transitions here.
|
||||
parent.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user