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


public class Controller : MonoBehaviour {



	public List<string> textForEnd = new List<string>();

	public InputField nameField;
	public Text whatPlayerisTyping1;
	public Text whatPlayerisTyping2;
	public Text whatPlayerisTyping3;
	public Text whatPlayerisTyping4;
	public string play1Text;
	public int playerTurn = 1;
	public string endText; 
	bool didSubmit = false;


	void Update()
	{
		
		if (GameManager.GM.GetState () == GS.CharSelect){
			//Text sets your text to say this message
			if (playerTurn == 1) {
				whatPlayerisTyping1.text = "Player One Type your Text";
				if (didSubmit) {
					didSubmit = false;
					textForEnd.Add (play1Text);
					nameField.text = "";
					playerTurn++;
				}
			}
			if (playerTurn == 2) {
				whatPlayerisTyping2.text = "Player Two Type your Text";
				if (didSubmit) {
					didSubmit = false;
					textForEnd.Add (play1Text);
					nameField.text = "";
					if (GameManager.GM.GetNumPlayers () > 2) {
						playerTurn++;
					} else {
						// Change to start
						GameManager.GM.getDatafromList (textForEnd);
						GameManager.GM.GetReady ();
					}
				}
			}
			if (playerTurn == 3) {
				whatPlayerisTyping3.text = "Player Three Type your Text";
				if (didSubmit) {
					didSubmit = false;
					textForEnd.Add (play1Text);
					nameField.text = "";
					if (GameManager.GM.GetNumPlayers () > 3) {
						playerTurn++;
					} else {
						// Change to start
						GameManager.GM.getDatafromList (textForEnd);
						GameManager.GM.GetReady ();
					}
				}
			}
			if (playerTurn == 4) {
				whatPlayerisTyping4.text = "Player Four Type your Text";
				if (didSubmit) {
					didSubmit = false;
					textForEnd.Add (play1Text);
					nameField.text = "";

					/*
				for (var i = 0; i < 4; i++) {
					Debug.Log (textForEnd[i]);
				}
				*/
					// Change to start
					GameManager.GM.getDatafromList (textForEnd);
					GameManager.GM.GetReady ();
				}
			}
		}
			
	}


	public void onSubmit(){
		didSubmit = true;
		play1Text = nameField.text;
		Debug.Log ("player " + playerTurn + " text" + play1Text);
	}

	public void LoadScene(int level){
		Application.LoadLevel (level);
	}


}
