Files
AppleHillsProduction/Assets/Scripts/UI/DivingGameOverScreen.cs

120 lines
4.2 KiB
C#
Raw Normal View History

using System;
2025-10-16 22:35:23 +02:00
using Core;
using UnityEngine;
2025-10-16 23:59:25 +02:00
using TMPro;
using Minigames.DivingForPictures;
using UI.Core;
using Pixelplacement;
2025-10-16 22:35:23 +02:00
namespace UI
2025-10-16 22:35:23 +02:00
{
public class DivingGameOverScreen : UIPage
2025-10-16 23:59:25 +02:00
{
[SerializeField]
private TextMeshProUGUI finalScoreText;
[SerializeField]
private CanvasGroup canvasGroup;
private void Awake()
2025-10-16 23:59:25 +02:00
{
// Ensure we have a CanvasGroup for transitions
if (canvasGroup == null)
canvasGroup = GetComponent<CanvasGroup>();
if (canvasGroup == null)
canvasGroup = gameObject.AddComponent<CanvasGroup>();
// Start invisible but keep the GameObject active so we can control visibility with alpha
canvasGroup.alpha = 0f;
canvasGroup.interactable = false;
canvasGroup.blocksRaycasts = false;
// Don't disable the GameObject - let UIPageController handle that
}
/// <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.picturesTaken;
finalScoreText.text = $"x {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);
2025-10-16 23:59:25 +02:00
}
2025-10-17 14:28:13 +02:00
}
}