2020-05-31 17:07:22 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using SanAndreasUnity.Behaviours;
|
|
|
|
|
using System.Linq;
|
2019-11-15 16:02:45 +00:00
|
|
|
|
using SanAndreasUnity.Utilities;
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
|
|
namespace SanAndreasUnity.UI {
|
|
|
|
|
|
|
|
|
|
public class PauseMenu : MonoBehaviour {
|
|
|
|
|
|
2019-07-09 19:41:58 +00:00
|
|
|
|
public static PauseMenu Instance { get; private set; }
|
|
|
|
|
|
2020-04-20 19:28:56 +00:00
|
|
|
|
private static bool s_isOpened = false;
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
|
|
public static bool IsOpened
|
|
|
|
|
{
|
|
|
|
|
get {
|
2020-04-20 19:28:56 +00:00
|
|
|
|
return s_isOpened;
|
2020-05-31 17:07:22 +00:00
|
|
|
|
}
|
|
|
|
|
set {
|
2020-04-20 19:28:56 +00:00
|
|
|
|
if (s_isOpened == value)
|
2020-04-19 22:42:48 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-04-20 19:28:56 +00:00
|
|
|
|
s_isOpened = value;
|
2020-04-19 22:42:48 +00:00
|
|
|
|
|
2020-04-20 19:28:56 +00:00
|
|
|
|
Instance.canvas.enabled = s_isOpened;
|
2020-05-31 17:07:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-19 22:42:48 +00:00
|
|
|
|
public MenuBar menuBar;
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
2019-07-09 19:41:58 +00:00
|
|
|
|
public Color openedWindowTextColor = Color.green;
|
2020-04-19 22:42:48 +00:00
|
|
|
|
public Color ClosedWindowTextColor => this.menuBar.DefaultMenuEntryTextColor;
|
2019-07-09 19:41:58 +00:00
|
|
|
|
|
2020-04-19 22:42:48 +00:00
|
|
|
|
public Canvas canvas;
|
|
|
|
|
|
2020-05-31 17:07:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Awake () {
|
|
|
|
|
|
2019-07-09 19:41:58 +00:00
|
|
|
|
if (null == Instance)
|
|
|
|
|
Instance = this;
|
|
|
|
|
|
2020-05-31 17:07:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Start () {
|
2020-04-19 22:47:40 +00:00
|
|
|
|
|
2020-04-19 23:43:54 +00:00
|
|
|
|
this.menuBar.RegisterMenuEntry("Resume", int.MinValue, () => IsOpened = false);
|
|
|
|
|
this.menuBar.RegisterMenuEntry("Exit", int.MaxValue, () => GameManager.ExitApplication());
|
2020-04-19 22:47:40 +00:00
|
|
|
|
|
2020-04-19 22:48:52 +00:00
|
|
|
|
this.canvas.enabled = IsOpened;
|
|
|
|
|
|
2020-05-31 17:07:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static PauseMenuWindow[] GetAllWindows() {
|
|
|
|
|
return FindObjectsOfType<PauseMenuWindow> ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Update () {
|
|
|
|
|
|
|
|
|
|
// toggle pause menu
|
|
|
|
|
if (Loader.HasLoaded && Input.GetButtonDown ("Start")) {
|
|
|
|
|
|
|
|
|
|
if (IsOpened) {
|
|
|
|
|
// if there is a modal window, close it, otherwise close pause menu
|
|
|
|
|
var window = GetAllWindows ().FirstOrDefault (w => w.IsOpened && w.IsModal);
|
|
|
|
|
if (window != null) {
|
|
|
|
|
window.IsOpened = false;
|
|
|
|
|
} else {
|
|
|
|
|
IsOpened = !IsOpened;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
IsOpened = !IsOpened;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if (IsOpened && Input.GetKeyDown(KeyCode.M))
|
|
|
|
|
// IsOpened = false;
|
|
|
|
|
|
|
|
|
|
// if (MiniMap.toggleMap && Input.GetKeyDown(KeyCode.Escape))
|
|
|
|
|
// MiniMap.toggleMap = false;
|
|
|
|
|
|
|
|
|
|
// bool isConsoleStateChanged = Console.Instance.m_openKey != Console.Instance.m_closeKey ?
|
|
|
|
|
// Input.GetKeyDown(Console.Instance.m_openKey) || Input.GetKeyDown(Console.Instance.m_closeKey) :
|
|
|
|
|
// Input.GetKeyDown(Console.Instance.m_openKey);
|
|
|
|
|
//
|
|
|
|
|
// if (m_playerController != null) {
|
|
|
|
|
// // WTF is this ?!
|
|
|
|
|
//
|
|
|
|
|
// // Fixed: If Escape is pressed, map isn't available
|
|
|
|
|
// if (!IsOpened && (Input.GetKeyDown (KeyCode.Escape) || isConsoleStateChanged || Input.GetKeyDown (KeyCode.F1) || (m_playerController.CursorLocked && Input.GetKeyDown (KeyCode.M))))
|
|
|
|
|
// m_playerController.ChangeCursorState (!m_playerController.CursorLocked);
|
|
|
|
|
// }
|
|
|
|
|
|
2019-07-27 15:07:35 +00:00
|
|
|
|
// update cursor lock state and visibility
|
|
|
|
|
if (Loader.HasLoaded)
|
|
|
|
|
{
|
|
|
|
|
if (UIManager.Instance.UseTouchInput)
|
|
|
|
|
{
|
|
|
|
|
// unlock the cursor
|
|
|
|
|
GameManager.ChangeCursorState (false, false);
|
|
|
|
|
// make it visible while pause menu is opened
|
|
|
|
|
Cursor.visible = IsOpened;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bool shouldBeLocked = !IsOpened;
|
|
|
|
|
if (GameManager.CursorLocked != shouldBeLocked)
|
|
|
|
|
GameManager.ChangeCursorState (shouldBeLocked);
|
|
|
|
|
}
|
2020-05-31 17:07:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|