using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class LevelManager : MonoBehaviour
{

	public static LevelManager instance;

	public GameObject BacktoMenu;
	public GameObject Continue;
	public GameObject Continue2;
	public GameObject GameOverBtn;
	public GameObject Panel;
	public GameObject creditText;
	public GameObject playButton;
	public GameObject ExitButton;
	public GameObject TitleImage;
	public GameObject creditButton;
	public GameObject closeCreditButton;
	void Start()
	{
		if(BacktoMenu != null)
			BacktoMenu.SetActive (false);
		if(Continue != null)
			Continue.SetActive(false);
		if(Continue2 != null)
			Continue2.SetActive(false);
		if (GameOverBtn != null)
			GameOverBtn.SetActive (false);
		if (Panel != null)
			Panel.SetActive (false);
		if (creditText != null)
			creditText.SetActive (false);
		if(closeCreditButton != null)
			closeCreditButton.SetActive (false);
		if(instance == null) {
			instance = this;
		}
	}
	public void NewGameButton(int sceneNumber)
	{
		SceneManager.LoadScene(sceneNumber);
	}

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

	public void PauseButton()
	{
		Time.timeScale = 0;
		if(Panel != null)
			Panel.SetActive (true);
		BacktoMenu.SetActive (true);
		Continue.SetActive(true);
		AudioMgr.instance.onPause();
	}

	public void ContinueButton()
	{
		Time.timeScale = 1;
		if(Panel != null)
			Panel.SetActive (false);
		BacktoMenu.SetActive (false);
		Continue.SetActive(false);
		AudioMgr.instance.onGame();
	}

	public void BackToMenuButton()
	{
		SceneManager.UnloadScene (1);
		SceneManager.LoadScene(0);
		Time.timeScale = 1;
	}

	public void GameOverMenu()
	{
		//if(death == true)
		Time.timeScale = 0;
		Panel.SetActive (true);
		GameOverBtn.SetActive (true);
		GameObject.Find("SCORE").GetComponent<Text>().text = (RideWave.instance.score + 1).ToString(); //easy fix
		GameObject.Find("Pause").SetActive(false);
	}

	public void GameOverButton()
	{
		SceneManager.UnloadScene (1);
		SceneManager.LoadScene (0);
		Time.timeScale = 1;
		AudioMgr.instance.onPause();
	}

	public void ContinueButton2()
	{
		SceneManager.LoadScene (1);
		Time.timeScale = 1;
	}

	public void CreditsButton()
	{	
		playButton.SetActive (false);
		creditButton.SetActive (false);
		ExitButton.SetActive (false);
		TitleImage.SetActive (false);
		creditText.SetActive (true);
		closeCreditButton.SetActive (true);
	}

	public void CloseCredits()
	{
		playButton.SetActive (true);
		creditButton.SetActive (true);
		TitleImage.SetActive (true);
		ExitButton.SetActive (true);
		creditText.SetActive (false);
		closeCreditButton.SetActive (false);
	}
}
