using UnityEngine;
using System.Collections;
public class MinimapCamera : MonoBehaviour
{
	public GameObject masterObject;
	public Transform target;
	public Transform playerMarker;
	public Transform elevatorMarker;
	public Font customFont;
	private float cameraHeight = 0.35f;
	public void setMinimapCamera (PlayerControl.Direction facing, int xIndex, int yIndex)
	{
		transform.position = target.position + new Vector3(0.0f, cameraHeight, 0.0f);
		playerMarker.position = transform.position;
		playerMarker.renderer.material.color = Color.green;
		setElevatorMarker();
		switch (facing)
		{
			case PlayerControl.Direction.North:
				transform.rotation = Quaternion.Euler(new Vector3(90.0f, 180.0f, 0.0f));
				break;
			case PlayerControl.Direction.South:
				transform.rotation = Quaternion.Euler(new Vector3(90.0f, 0.0f, 0.0f));
				break;
			case PlayerControl.Direction.East:
				transform.rotation = Quaternion.Euler(new Vector3(90.0f, 270.0f, 0.0f));
				break;
			case PlayerControl.Direction.West:
				transform.rotation = Quaternion.Euler(new Vector3(90.0f, 90.0f, 0.0f));
				break;
		}
	}
	public void setElevatorMarker ()
	{
		DungeonGenerator dg = masterObject.GetComponent<DungeonGenerator>();
		elevatorMarker.position = new Vector3(dg.elevatorXIndex * DungeonGenerator.tileSize, cameraHeight, dg.elevatorYIndex * DungeonGenerator.tileSize);
		elevatorMarker.renderer.material.color = Color.yellow;
	}
	public void setEnemyMarkers ()
	{
		for (int i = 0; i < (masterObject.GetComponent<EnemyGenerator>()).enemyList.Count; i++)
		{
			GameObject go = (masterObject.GetComponent<EnemyGenerator>()).enemyList[i];
			EnemyAI eai = go.GetComponent<EnemyAI>();
			eai.enemyMarker.transform.position = go.transform.position + new Vector3(0.0f, cameraHeight * 1.4f, 0.0f);
			eai.enemyMarker.transform.rotation = Quaternion.Euler(new Vector3(0.0f, 0.0f, 0.0f));
		}
	}
	public void OnGUI ()
	{
		GUI.matrix = Matrix4x4.TRS(new Vector3(0.0f, 0.0f, 0.0f), Quaternion.identity, new Vector3(1.0f, 1.0f, 1.0f));
		GUIStyle compassGuiStyle = new GUIStyle();
		compassGuiStyle.font = customFont;
		compassGuiStyle.fontSize = 16;
		compassGuiStyle.normal.textColor = Color.yellow;
		float xPadding = 0.0f;
		float yPadding = 0.0f;
		PlayerControl.Direction facing = GameObject.Find("_Player").GetComponent<PlayerControl>().playerFacing;
		// Places NSEW at the four sides of the minimap.
		/*switch (facing)
		{
			case PlayerControl.Direction.North:
				xPadding = -22.0f;
				yPadding = 0.0f;
				break;
			case PlayerControl.Direction.South:
				xPadding = -24.0f;
				yPadding = 184.0f;
				break;
			case PlayerControl.Direction.East:
				xPadding = 96.0f;
				yPadding = 92.0f;
				break;
			case PlayerControl.Direction.West:
				xPadding = -128.0f;
				yPadding = 92.0f;
				break;
		}*/
		// Places NSEW at the top/center of the minimap (since the minimap rotates relative to the player facing).
		switch (facing)
		{
			case PlayerControl.Direction.North:
				xPadding = -22.0f;
				yPadding = 0.0f;
				break;
			case PlayerControl.Direction.South:
				xPadding = -22.0f;
				yPadding = 0.0f;
				break;
			case PlayerControl.Direction.East:
				xPadding = -16.0f;
				yPadding = 0.0f;
				break;
			case PlayerControl.Direction.West:
				xPadding = -18.0f;
				yPadding = 0.0f;
				break;
		}
		GUI.Label(new Rect(this.gameObject.camera.pixelRect.x + this.gameObject.camera.pixelRect.width / 2.0f + xPadding,
						   yPadding,
						   this.gameObject.camera.pixelRect.width, this.gameObject.camera.pixelRect.height), facing + "", compassGuiStyle);
	}
}