using UnityEngine;
using System.Collections;

public class MenuController : MonoBehaviour {

	public UIWidget joinWidget; // inspector

	public UIInput ipInput; // inspector

	public static string ip = "";
	public static bool hosting = true;

	public void Start() {
		string prevIp = PlayerPrefs.GetString ("prevIp");
		if (prevIp != null && prevIp.Length > 0) {
			ipInput.value = prevIp;
		}
		else {
			ipInput.value = "localhost";
		}
		joinWidget.gameObject.SetActive (false);
	}

	public void OnHost() {
		hosting = true;
		Application.LoadLevel ("game");
	}

	public void OnJoin() {
		joinWidget.gameObject.SetActive (true);
	}

	public void OnClickJoin() {
		hosting = false;
		ip = ipInput.value;
		PlayerPrefs.SetString ("prevIp", ip);
		Application.LoadLevel ("game");
	}

	public void OnClickBack() {
		joinWidget.gameObject.SetActive (false);
		
	}
}
