2023-05-07 20:33:15 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using TMPro;
|
|
|
|
|
|
|
|
using HeavenStudio.Util;
|
|
|
|
using HeavenStudio.InputSystem;
|
|
|
|
|
|
|
|
namespace HeavenStudio.Common
|
|
|
|
{
|
|
|
|
public class PauseMenu : MonoBehaviour
|
|
|
|
{
|
|
|
|
public enum Options
|
|
|
|
{
|
|
|
|
Continue,
|
|
|
|
StartOver,
|
|
|
|
Settings,
|
|
|
|
Quit
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// MAKE OPTIONS ACCEPT MOUSE INPUT
|
|
|
|
|
|
|
|
[SerializeField] float patternSpeed = 1f;
|
|
|
|
[SerializeField] SettingsDialog settingsDialog;
|
|
|
|
[SerializeField] Animator animator;
|
|
|
|
[SerializeField] TMP_Text chartTitleText;
|
|
|
|
[SerializeField] TMP_Text chartArtistText;
|
|
|
|
[SerializeField] GameObject optionArrow;
|
|
|
|
[SerializeField] GameObject optionHolder;
|
|
|
|
|
|
|
|
[SerializeField] RectTransform patternL;
|
|
|
|
[SerializeField] RectTransform patternR;
|
|
|
|
|
|
|
|
public static bool IsPaused { get { return isPaused; } }
|
|
|
|
|
|
|
|
private static bool isPaused = false;
|
|
|
|
private double pauseBeat;
|
|
|
|
private bool canPick = false;
|
|
|
|
private bool isQuitting = false;
|
|
|
|
private int optionSelected = 0;
|
|
|
|
|
|
|
|
void Pause()
|
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
if (!Conductor.instance.isPlaying) return;
|
2023-05-07 20:33:15 +00:00
|
|
|
Conductor.instance.Pause();
|
|
|
|
pauseBeat = Conductor.instance.songPositionInBeatsAsDouble;
|
|
|
|
chartTitleText.text = GameManager.instance.Beatmap["remixtitle"];
|
|
|
|
chartArtistText.text = GameManager.instance.Beatmap["remixauthor"];
|
|
|
|
animator.Play("PauseShow");
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShot("ui/PauseIn");
|
2023-05-07 20:33:15 +00:00
|
|
|
|
|
|
|
isPaused = true;
|
|
|
|
canPick = false;
|
|
|
|
optionSelected = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UnPause(bool instant = false)
|
|
|
|
{
|
2023-06-10 19:13:29 +00:00
|
|
|
if ((!instant) && (!Conductor.instance.isPaused)) return;
|
2023-05-07 20:33:15 +00:00
|
|
|
Conductor.instance.Play(pauseBeat);
|
|
|
|
if (instant)
|
|
|
|
{
|
|
|
|
animator.Play("NoPose");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
animator.Play("PauseHide");
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShot("ui/PauseOut");
|
2023-05-07 20:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isPaused = false;
|
|
|
|
canPick = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
isPaused = false;
|
|
|
|
isQuitting = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
if (isQuitting) return;
|
|
|
|
if (PlayerInput.GetInputController(1).GetButtonDown((int) InputController.ButtonsPad.PadPause))
|
|
|
|
{
|
|
|
|
if (isPaused)
|
|
|
|
{
|
|
|
|
UnPause();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Pause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (isPaused && canPick && !settingsDialog.IsOpen)
|
|
|
|
{
|
|
|
|
if (Input.GetKeyDown(KeyCode.UpArrow) || PlayerInput.GetInputController(1).GetButtonDown((int)InputController.ButtonsPad.PadUp))
|
|
|
|
{
|
|
|
|
optionSelected--;
|
|
|
|
if (optionSelected < 0)
|
|
|
|
{
|
|
|
|
optionSelected = optionHolder.transform.childCount - 1;
|
|
|
|
}
|
|
|
|
ChooseOption((Options) optionSelected);
|
|
|
|
}
|
|
|
|
else if (Input.GetKeyDown(KeyCode.DownArrow) || PlayerInput.GetInputController(1).GetButtonDown((int)InputController.ButtonsPad.PadDown))
|
|
|
|
{
|
|
|
|
optionSelected++;
|
|
|
|
if (optionSelected > optionHolder.transform.childCount - 1)
|
|
|
|
{
|
|
|
|
optionSelected = 0;
|
|
|
|
}
|
|
|
|
ChooseOption((Options) optionSelected);
|
|
|
|
}
|
|
|
|
else if (Input.GetKeyDown(KeyCode.Return) || PlayerInput.GetInputController(1).GetButtonDown((int)InputController.ButtonsPad.PadE))
|
|
|
|
{
|
|
|
|
UseOption((Options) optionSelected);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isPaused)
|
|
|
|
{
|
|
|
|
patternL.anchoredPosition = new Vector2((Time.realtimeSinceStartup * patternSpeed) % 13, patternL.anchoredPosition.y);
|
|
|
|
patternR.anchoredPosition = new Vector2(-(Time.realtimeSinceStartup * patternSpeed) % 13, patternR.anchoredPosition.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ChooseCurrentOption()
|
|
|
|
{
|
|
|
|
ChooseOption((Options) optionSelected, false);
|
|
|
|
canPick = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void ChooseOption(Options option, bool sound = true)
|
|
|
|
{
|
|
|
|
optionArrow.transform.position = new Vector3(optionArrow.transform.position.x, optionHolder.transform.GetChild((int) option).position.y, optionArrow.transform.position.z);
|
|
|
|
foreach (Transform child in optionHolder.transform)
|
|
|
|
{
|
|
|
|
child.transform.localScale = new Vector3(1f, 1f, 1f);
|
|
|
|
}
|
|
|
|
optionHolder.transform.GetChild((int) option).transform.localScale = new Vector3(1.2f, 1.2f, 1.2f);
|
|
|
|
if (sound)
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShot("ui/UIOption");
|
2023-05-07 20:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void UseOption(Options option)
|
|
|
|
{
|
|
|
|
switch (option)
|
|
|
|
{
|
|
|
|
case Options.Continue:
|
|
|
|
OnContinue();
|
|
|
|
break;
|
|
|
|
case Options.StartOver:
|
|
|
|
OnRestart();
|
|
|
|
break;
|
|
|
|
case Options.Settings:
|
|
|
|
OnSettings();
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShot("ui/UISelect");
|
2023-05-07 20:33:15 +00:00
|
|
|
break;
|
|
|
|
case Options.Quit:
|
|
|
|
OnQuit();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnContinue()
|
|
|
|
{
|
|
|
|
UnPause();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnRestart()
|
|
|
|
{
|
|
|
|
UnPause(true);
|
|
|
|
GlobalGameManager.ForceFade(0, 1f, 0.5f);
|
|
|
|
GameManager.instance.Stop(0, true, 1.5f);
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShot("ui/UIEnter");
|
2023-05-07 20:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OnQuit()
|
|
|
|
{
|
|
|
|
isQuitting = true;
|
2023-06-10 19:13:29 +00:00
|
|
|
SoundByte.PlayOneShot("ui/PauseQuit");
|
2023-05-07 20:33:15 +00:00
|
|
|
GlobalGameManager.LoadScene("Editor", 0, 0.1f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnSettings()
|
|
|
|
{
|
|
|
|
settingsDialog.SwitchSettingsDialog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|