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(); if (canvasGroup == null) canvasGroup = gameObject.AddComponent(); // 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 } /// /// Called when the page transitions in. Updates the score display. /// 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(); } } /// /// Called when the page transitions out. /// 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(p => Logging.Debug($"Loading progress: {p * 100:F0}%")); await SceneManagerService.Instance.ReloadCurrentScene(progress); } /// /// Exits to the main menu scene. /// 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(p => Logging.Debug($"Loading progress: {p * 100:F0}%")); await SceneManagerService.Instance.SwitchSceneAsync("AppleHillsOverworld", progress); } /// /// Exits to the Quarry scene. /// 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(p => Logging.Debug($"Loading progress: {p * 100:F0}%")); await SceneManagerService.Instance.SwitchSceneAsync("Quarry", progress); } } }