<commit_before>﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using ClumsyBat.UI.DropdownMenuComponents;

using Levels = LevelProgressionHandler.Levels;

namespace ClumsyBat.UI
{
    public class DropdownMenu : MonoBehaviour
    {
        private RectTransform _menuPanel;
        private Image _menuBackPanel;

        public DropdownMainMenu MainMenu;
        public DropdownOptionsMenu OptionsMenu;
        public DropdownStatsMenu StatsMenu;

        private const float BounceDuration = 0.18f;
        private const float PanelDropAnimDuration = 0.30f;

        private const float MenuTopOffset = 11f;
        private const float MenuBottomOffset = 0f;

        private enum States
        {
            Hidden, Visible
        }
        private States state;

        private void Awake()
        {
            state = States.Hidden;
            GetMenuObjects();
        }

        private void Start()
        {
            HideAll();
            HideImmediate();
            GameStatics.Camera.OnCameraChanged += CameraChanged;
        }

        private void OnDestroy()
        {
            GameStatics.Camera.OnCameraChanged -= CameraChanged;
        }

        public void ReturnButtonClicked()
        {
            if (GameStatics.GameManager.IsInMenu)
            {
                GameStatics.UI.MainMenuTransitions.GotoMainMenuArea();
            }
            else
            {
                ShowPauseMenu();
            }
        }

        public void ShowLevelCompletion(Levels level, Levels nextLevel)
        {
            HideAll();
            MainMenu.ShowScreen();
            MainMenu.ShowLevelCompletion(level, nextLevel);
        }
        
        public void ShowOptions()
        {
            HideAll();
            OptionsMenu.ShowScreen();
            ShowDropdownMenu();
        }

        public void ShowStats()
        {
            HideAll();
            StatsMenu.ShowScreen();
            ShowDropdownMenu();
        }
        
        public void ShowPauseMenu()
        {
            HideAll();
            MainMenu.SetupPauseMenu();
            MainMenu.ShowScreen();
            ShowDropdownMenu();
        }
        
        public void ShowGameOverMenu()
        {
            HideAll();
            MainMenu.ShowScreen();
            ShowDropdownMenu();
        }
        
        public void HideImmediate()
        {
            state = States.Hidden;
            CanvasGroup canvasGroup = GetComponent<CanvasGroup>();
            canvasGroup.alpha = 0;
            canvasGroup.blocksRaycasts = false;
            canvasGroup.interactable = false;
        }
        
        public IEnumerator DropMenuRoutine()
        {
            yield return StartCoroutine(PanelDropAnim(true));
        }

        public IEnumerator RaiseMenuRoutine()
        {
            yield return StartCoroutine(PanelDropAnim(false));
        }

        private void ShowDropdownMenu()
        {
            if (state == States.Hidden)
            {
                state = States.Visible;
                StartCoroutine(DropMenuRoutine());
                CanvasGroup canvasGroup = GetComponent<CanvasGroup>();
                canvasGroup.alpha = 1;
                canvasGroup.blocksRaycasts = true;
                canvasGroup.interactable = true;
            }
        }

        private IEnumerator PanelDropAnim(bool bEnteringScreen) // todo create separate coroutine for raising and dropping
        {
            if (!bEnteringScreen)
            {
                StartCoroutine(Bounce(-0.7f));
                yield return new WaitForSecondsRealtime(BounceDuration);
            }

            const float animDuration = PanelDropAnimDuration;
            float yPosTop = GameStatics.Camera.CurrentCamera.transform.position.y + MenuTopOffset;
            float yPosBottom = GameStatics.Camera.CurrentCamera.transform.position.y;<commit_msg>fixed bug where pausing and unpausing meant the dropdownmenu wouldn't show next pause<commit_after>﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using ClumsyBat.UI.DropdownMenuComponents;

using Levels = LevelProgressionHandler.Levels;

namespace ClumsyBat.UI
{
    public class DropdownMenu : MonoBehaviour
    {
        private RectTransform _menuPanel;
        private Image _menuBackPanel;

        public DropdownMainMenu MainMenu;
        public DropdownOptionsMenu OptionsMenu;
        public DropdownStatsMenu StatsMenu;

        private const float BounceDuration = 0.18f;
        private const float PanelDropAnimDuration = 0.30f;

        private const float MenuTopOffset = 11f;
        private const float MenuBottomOffset = 0f;

        private enum States
        {
            Hidden, Visible
        }
        private States state;

        private void Awake()
        {
            state = States.Hidden;
            GetMenuObjects();
        }

        private void Start()
        {
            HideAll();
            HideImmediate();
            GameStatics.Camera.OnCameraChanged += CameraChanged;
        }

        private void OnDestroy()
        {
            GameStatics.Camera.OnCameraChanged -= CameraChanged;
        }

        public void ReturnButtonClicked()
        {
            if (GameStatics.GameManager.IsInMenu)
            {
                GameStatics.UI.MainMenuTransitions.GotoMainMenuArea();
            }
            else
            {
                ShowPauseMenu();
            }
        }

        public void ShowLevelCompletion(Levels level, Levels nextLevel)
        {
            HideAll();
            MainMenu.ShowScreen();
            MainMenu.ShowLevelCompletion(level, nextLevel);
        }
        
        public void ShowOptions()
        {
            HideAll();
            OptionsMenu.ShowScreen();
            ShowDropdownMenu();
        }

        public void ShowStats()
        {
            HideAll();
            StatsMenu.ShowScreen();
            ShowDropdownMenu();
        }
        
        public void ShowPauseMenu()
        {
            HideAll();
            MainMenu.SetupPauseMenu();
            MainMenu.ShowScreen();
            ShowDropdownMenu();
        }
        
        public void ShowGameOverMenu()
        {
            HideAll();
            MainMenu.ShowScreen();
            ShowDropdownMenu();
        }
        
        public void HideImmediate()
        {
            state = States.Hidden;
            CanvasGroup canvasGroup = GetComponent<CanvasGroup>();
            canvasGroup.alpha = 0;
            canvasGroup.blocksRaycasts = false;
            canvasGroup.interactable = false;
        }
        
        public IEnumerator DropMenuRoutine()
        {
            yield return StartCoroutine(PanelDropAnim(true));
        }

        public IEnumerator RaiseMenuRoutine()
        {
            yield return StartCoroutine(PanelDropAnim(false));
        }

        private void ShowDropdownMenu()
        {
            if (state == States.Hidden)
            {
                state = States.Visible;
                StartCoroutine(DropMenuRoutine());
                CanvasGroup canvasGroup = GetComponent<CanvasGroup>();
                canvasGroup.alpha = 1;
                canvasGroup.blocksRaycasts = true;
                canvasGroup.interactable = true;
            }
        }

        private IEnumerator PanelDropAnim(bool bEnteringScreen) // todo create separate coroutine for raising and dropping
        {
            if (!bEnteringScreen)
            {
                state = States.Hidden;
                StartCoroutine(Bounce(-0.7f));
                yield return new WaitForSecondsRealtime(BounceDuration);
            }

            const float animDuration = PanelDropAnimDuration;
            float yPosTop = GameStatics.Camera.CurrentCamera.transform.position.y + MenuTopOffset;
            float yPosBottom = GameStatics.Camera.CurrentCamera.transform.position.y;
{'fraction_non_alphanumeric': 0.07140153904377444, 'fraction_numerical': 0.0032799293553677305, 'mean_word_length': 1.60019678583142, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5374402', 'n_tokens_mistral': 1990, 'n_tokens_neox': 1894, 'n_words': 403}