using UnityEngine;
using System.Collections;

public class Menu : MonoBehaviour 
{
	public GUIStyle jouerStyle;					// Pour changer la texture des etats du bouton "A l'abordage!"
	public GUIStyle reglesStyle;				// Pour changer la texture des etats du bouton "Code Pirate"
	public GUIStyle commandesStyle;				// Pour changer la texture des etats du bouton "Tactiques d'abordage"
	public GUIStyle retourStyle;				// Pour changer la texture des etats du bouton "Retour"
	public GUIStyle tonPseudoBouton;			// Pour changer la texture des etats du bouton "ARRRH!"
	public GUIStyle affichageScoreStyle;		// Pour changer la police des scores affichés dans "Pirates Celebres"
	public GUIStyle tonPseudoString;			// Pour changer la police d'ecriture du pseudo du joueur dans "A l'abordage!"
	private string pseudo;						// Permet de stocker le pseudo du joueur

	int etat = 0;
	
	// Use this for initialization
	void Start () 
	{
		pseudo = "Efface moi et\necris ton pseudo :)";
	}
	
	// Update is called once per frame
	void Update () 
	{
		
	}
	
	void OnGUI()
	{
		switch (etat)
		{
			//Interface de depart du menu
			case 0:
				Texture2D titreJeu = (Texture2D) Resources.Load("Textures/Interface/Menu/Drunken Pirates", typeof(Texture2D));
				GUI.DrawTexture(new Rect(0,0, Screen.width, Screen.height),titreJeu);
				if (GUI.Button(new Rect(Screen.width/1.5f, Screen.height/2.9f, Screen.width/8, Screen.height/8), "",jouerStyle))
				{
					GUIManager.clicClic = true;
					etat = 1;
				}
				if (GUI.Button(new Rect(Screen.width/1.5f, Screen.height/2, Screen.width/8, Screen.height/8), "", reglesStyle))
				{
					GUIManager.clicClic = true;
					etat = 2;
				}
				if (GUI.Button(new Rect(Screen.width/1.5f, Screen.height/1.5f, Screen.width/8, Screen.height/8), "", commandesStyle))
				{
					GUIManager.clicClic = true;
					etat = 3;
				}
				if (GUI.Button(new Rect(Screen.width/1.5f, Screen.height/1.2f, Screen.width/8, Screen.height/8), "", affichageScoreStyle))
				{
					GUIManager.clicClic = true;
					etat = 4;
				}
				break;
			
			//Interface ou l'on entre le pseudo
			case 1: 
				Texture2D tonPseudoTexture = (Texture2D) Resources.Load("Textures/Interface/Fond/TonPseudo", typeof(Texture2D));				
				GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),tonPseudoTexture);
				pseudo = GUI.TextField(new Rect (Screen.width*0.18f,Screen.height*0.715f,Screen.width*0.275f,Screen.height*0.255f),pseudo,tonPseudoString);
				
				if(GUI.Button(new Rect (Screen.width*0.52f,Screen.height*0.715f,Screen.width*0.275f,Screen.height*0.255f),"",tonPseudoBouton))
				{
					GUIManager.clicClic = true;
					PlayerPrefs.SetString("PlayerName",pseudo);
					PlayerPrefs.Save ();
					Application.LoadLevel("Drunken Pirates");
				}	
				break;
			
			//Interface des regles du jeu
			case 2: 
				Texture2D reglesTexture = (Texture2D) Resources.Load("Textures/Interface/Fond/Regles", typeof(Texture2D));
				GUI.DrawTexture(new Rect(0,0, Screen.width, Screen.height),reglesTexture);
				break;
			
			//Interface des commandes
			case 3: 
				Texture2D commandesTexture = (Texture2D) Resources.Load("Textures/Interface/Fond/Commandes", typeof(Texture2D));
				GUI.DrawTexture(new Rect(0,0, Screen.width, Screen.height),commandesTexture);
				break;
			
			//Interface d'affichage des scores
			case 4: 
				Texture2D affichageScoreTexture = (Texture2D) Resources.Load("Textures/Interface/Fond/AffichageScores", typeof(Texture2D));
				GUI.DrawTexture(new Rect(0,0, Screen.width, Screen.height),affichageScoreTexture);
			
				GUI.Label(new Rect (Screen.width*0.15f,Screen.height*0.2f,Screen.width*0.275f,Screen.height*0.255f),PlayerPrefs.GetString("PlayerName"),tonPseudoString);
				GUI.Label(new Rect (Screen.width*0.5f,Screen.height*0.2f,Screen.width*0.275f,Screen.height*0.255f),""+PlayerPrefs.GetInt("score1"),tonPseudoString);
				break;	
		}
		//affichage du bouton "retour"
		if (etat >= 2 && etat<=4)
		{
			if (GUI.Button(new Rect(Screen.width*0.8f, Screen.height*0.8f, Screen.width/8, Screen.height/8), "", retourStyle))
			{		
				GUIManager.clicClic = true;
				etat = 0;
			}
		}
	}
}
