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

public class LobbySceneManager : UnityEngine.MonoBehaviour {
	public Persistence persistence;

	public Text playerListText;
	public Text loadingGenerationText;
	public GameObject playButton;

	void Awake () {
		this.persistence = GameObject.FindObjectOfType<Persistence> ();
	}

	void OnGUI()
	{
		string playerList = "Player List (" + PhotonNetwork.playerList.Length + ")\n";
		foreach (PhotonPlayer player in PhotonNetwork.playerList) {
			playerList += player.ID + "    ";
			playerList += player.NickName;
			playerList += player.IsMasterClient ? "*" : "";
			playerList += player.IsLocal ? " (You)\n" : "\n";
		}
		playerListText.text = playerList;

		if (PhotonNetwork.inRoom && this.persistence.levelManager.finishedGenerating && PhotonNetwork.isMasterClient) {
			this.playButton.gameObject.SetActive (true);
		}

		loadingGenerationText.text = this.persistence.levelManager.percentageComplete + "%";
	}

	// Use this for initialization
	void Start () {
		this.playButton.gameObject.SetActive (false);
	}
	
	// Update is called once per frame
	void Update () {
		
	}
}
