Make the score display a UIPage as well

This commit is contained in:
Michal Adam Pikulski
2025-10-22 10:37:51 +02:00
parent acf3ecec3f
commit 8591490cb2
7 changed files with 820 additions and 803 deletions

View File

@@ -2,12 +2,14 @@ using System;
using System.Collections.Generic;
using Bootstrap;
using Core;
using UI;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.Playables;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UI.Core;
namespace Cinematics
{
@@ -25,7 +27,7 @@ namespace Cinematics
private bool _isCinematicPlaying = false;
public bool IsCinematicPlaying => _isCinematicPlaying;
public GameObject cinematicBackground;
public GameObject divingGameOverScreen;
public DivingGameOverScreen divingGameOverScreen;
// Dictionary to track addressable handles by PlayableDirector
private Dictionary<PlayableDirector, AsyncOperationHandle<PlayableAsset>> _addressableHandles
@@ -204,7 +206,20 @@ namespace Cinematics
public void ShowGameOverScreen()
{
divingGameOverScreen.SetActive(true);
if (divingGameOverScreen != null && UIPageController.Instance != null)
{
UIPageController.Instance.PushPage(divingGameOverScreen);
}
else if (divingGameOverScreen != null)
{
// Fallback if UIPageController is not available
divingGameOverScreen.gameObject.SetActive(true);
Logging.Warning("[CinematicsManager] UIPageController not found, falling back to simple activation.");
}
else
{
Logging.Warning("[CinematicsManager] DivingGameOverScreen reference is not set!");
}
}
}
}

View File

@@ -146,27 +146,18 @@ namespace UI.CardSystem
var backpackInput = backpackIcon.gameObject.GetComponentInParent<BackpackInput>();
InputManager.Instance.RegisterOverrideConsumer(backpackInput);
// If no pages are open, push the main menu
if (PageController.CurrentPage == null)
PageController.PushPage(mainMenuPage);
// Clear notification for unseen cards when opening menu
if (_hasUnseenCards)
{
PageController.PushPage(mainMenuPage);
// Clear notification for unseen cards when opening menu
if (_hasUnseenCards)
{
_hasUnseenCards = false;
}
// Hide the backpack button when entering menu
if (backpackButton != null)
{
backpackButton.gameObject.SetActive(false);
}
_hasUnseenCards = false;
}
else if (PageController.CurrentPage == mainMenuPage)
// Hide the backpack button when entering menu
if (backpackButton != null)
{
// If main menu is open, pop it
PageController.PopPage();
backpackButton.gameObject.SetActive(false);
}
}
@@ -184,8 +175,28 @@ namespace UI.CardSystem
}
else
{
// Check if any page in the stack has "Card" or "Album" in the name
bool hasCardOrAlbumPage = false;
if (PageController != null && PageController.PageStack != null)
{
foreach (var page in PageController.PageStack)
{
if (page != null && page.PageName != null)
{
if (page.PageName.Contains("Card") || page.PageName.Contains("Album"))
{
hasCardOrAlbumPage = true;
break;
}
}
}
}
// Hide backpack button if there's a card/album page in the stack
if (backpackButton != null)
backpackButton.gameObject.SetActive(false);
{
backpackButton.gameObject.SetActive(!hasCardOrAlbumPage);
}
}
// Update menu if it's the main menu page

View File

@@ -18,6 +18,7 @@ namespace UI.Core
private Stack<UIPage> _pageStack = new Stack<UIPage>();
public UIPage CurrentPage => _pageStack.Count > 0 ? _pageStack.Peek() : null;
public IEnumerable<UIPage> PageStack => _pageStack;
// Event fired when the page stack changes
public event Action<UIPage> OnPageChanged;

View File

@@ -3,47 +3,117 @@ using Core;
using UnityEngine;
using TMPro;
using Minigames.DivingForPictures;
using UI.Core;
using Pixelplacement;
public class DivingGameOverScreen : MonoBehaviour
namespace UI
{
[SerializeField]
private TextMeshProUGUI finalScoreText;
void OnEnable()
public class DivingGameOverScreen : UIPage
{
if (DivingGameManager.Instance != null)
[SerializeField]
private TextMeshProUGUI finalScoreText;
[SerializeField]
private CanvasGroup canvasGroup;
private void Awake()
{
int finalScore = DivingGameManager.Instance.PlayerScore;
finalScoreText.text = $"{finalScore}";
// 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);
}
/// <summary>
/// Called when the page transitions in. Updates the score display.
/// </summary>
protected override void DoTransitionIn(Action onComplete)
{
// Update score when showing the screen
if (DivingGameManager.Instance != null)
{
int finalScore = DivingGameManager.Instance.PlayerScore;
finalScoreText.text = $"{finalScore}";
}
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();
}
}
/// <summary>
/// Called when the page transitions out.
/// </summary>
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, onComplete);
}
else
{
onComplete?.Invoke();
}
}
public async void PlayAgain()
{
// Pop this page from the stack before reloading
if (UIPageController.Instance != null && UIPageController.Instance.CurrentPage == this)
{
UIPageController.Instance.PopPage();
}
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
await SceneManagerService.Instance.ReloadCurrentScene(progress);
}
/// <summary>
/// Exits to the main menu scene.
/// </summary>
public async void ExitToAppleHills()
{
// Pop this page from the stack before switching scenes
if (UIPageController.Instance != null && UIPageController.Instance.CurrentPage == this)
{
UIPageController.Instance.PopPage();
}
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
await SceneManagerService.Instance.SwitchSceneAsync("AppleHillsOverworld", progress);
}
/// <summary>
/// Exits to the Quarry scene.
/// </summary>
public async void ExitToQuarry()
{
// Pop this page from the stack before switching scenes
if (UIPageController.Instance != null && UIPageController.Instance.CurrentPage == this)
{
UIPageController.Instance.PopPage();
}
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
await SceneManagerService.Instance.SwitchSceneAsync("Quarry", progress);
}
}
public async void PlayAgain()
{
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
await SceneManagerService.Instance.ReloadCurrentScene(progress);;
gameObject.SetActive(false);
}
/// <summary>
/// Exits to the main menu scene.
/// </summary>
public async void ExitToAppleHills()
{
gameObject.SetActive(false);
// Replace with the actual scene name as set in Build Settings
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
await SceneManagerService.Instance.SwitchSceneAsync("AppleHillsOverworld", progress);
}
/// <summary>
/// Exits to the main menu scene.
/// </summary>
public async void ExitToQuarry()
{
gameObject.SetActive(false);
// Replace with the actual scene name as set in Build Settings
var progress = new Progress<float>(p => Logging.Debug($"Loading progress: {p * 100:F0}%"));
await SceneManagerService.Instance.SwitchSceneAsync("Quarry", progress);
}
}