using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine.UI;

public class PauseAndQuit : MonoBehaviour {

	public GameObject pauseMenu;
	bool canPause = true;

    public bool paused;

    public RoundOverDisplay roundOverDisplay;

    void Start() {
#if UNITY_EDITOR
        if (EditorApplication.isPlayingOrWillChangePlaymode) {
            canPause = false;
        }
#endif
        GameObject obj = GameObject.FindGameObjectWithTag("Game Manager");
        if (obj)
            roundOverDisplay = obj.GetComponent<RoundOverDisplay>();

        paused = false;
    }


    // Update is called once per frame
    void Update () {
		if (Input.GetKeyDown (KeyCode.Escape) && canPause) {
			if (!pauseMenu.activeInHierarchy) {
				OpenPause ();
			} else {
				ClosePause ();
			}
		}
	}

	void OpenPause () {
        paused = true;
		pauseMenu.SetActive (true);
	}

	public void ClosePause () {
        paused = false;
		pauseMenu.SetActive(false);
        if (PlayerBase.GetLocalPlayer() != null && !(roundOverDisplay && roundOverDisplay.IsRoundOver())) {
            Cursor.visible = false;
            Cursor.lockState = CursorLockMode.Locked;
        }
    }

	public void ExitBattleRoyale () {
		Application.Quit ();
	}
}
