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

public class Immortal : MonoBehaviour {

	private static List<Tuple<string, int>> serverList = new List<Tuple<string, int>>();

	private static bool onClientStart = false;

	private static int country = 1;

	// Use this for initialization
	void Start () {
		NetworkManager.initConnection();
		DontDestroyOnLoad(this);
	}
	
	// Update is called once per frame
	void Update () {
		NetworkManager.manageNetworkInputs();
	}

	public void startClient() {
		if (NetworkManager.isConnectedToMasterServer()) {
			SceneManager.LoadScene("ClientStart", LoadSceneMode.Single);
			NetworkManager.indicateIsServer(false);
			onClientStart = true;
		}
	}

	public static void addServerToList(string ip, int port) {
		serverList.Add(new Tuple<string, int>(ip, port));

		GameObject newServerInfo = GameObject.Instantiate(GameObject.Find("ServerInfo"), GameObject.Find("Canvas").transform.FindChild("Panel/List"));

		newServerInfo.transform.FindChild("IP").GetComponent<Text>().text = ip;
		newServerInfo.transform.FindChild("Port").GetComponent<Text>().text = "" + port;
		newServerInfo.GetComponent<ServerInfo>().info = serverList[serverList.Count - 1];
	}

	public void startServer() {
		if (true || NetworkManager.isConnectedToMasterServer()) {
			NetworkManager.indicateIsServer(true);
			startGame();
		}
	}

	public static void startGame() {
		onClientStart = false;
		SceneManager.LoadScene("Game", LoadSceneMode.Single);
	}

	public static int getCountry() {
		return country;
	}

	public static void setCountry(int newCountry) {
		country = newCountry;
	}
}
