120 lines
4.2 KiB
C#
120 lines
4.2 KiB
C#
using System;
|
|
using Core;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using Minigames.DivingForPictures;
|
|
using UI.Core;
|
|
using Pixelplacement;
|
|
|
|
namespace UI
|
|
{
|
|
public class DivingGameOverScreen : UIPage
|
|
{
|
|
[SerializeField]
|
|
private TextMeshProUGUI finalScoreText;
|
|
|
|
[SerializeField]
|
|
private CanvasGroup canvasGroup;
|
|
|
|
private void Awake()
|
|
{
|
|
// 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);
|
|
}
|
|
}
|
|
} |