using UnityEngine;
using System.Collections;

public class PlayerInteractionScript : MonoBehaviour {

	public AudioClip doorKnock1;
	public AudioClip doorKnock2;

	public AudioClip sipTea1;
	public AudioClip sipTea2;

	public AudioClip pickupPhoto;
	public AudioClip putDownPhoto;

	//public AudioClip lampSwitch;

	public AudioClip pickupGarbageA1;
	public AudioClip pickupGarbageA2;
	public AudioClip pickupGarbageB1;
	public AudioClip pickupGarbageB2;

	//public AudioClip garbageCan;


	private float interactionRange = 2.0f;

	private string currentInteractionString;

	public GameObject currentInteractionObject;
	private string currentInteractionTag;

	private bool haveGarbageInHand = false;

	private GameObject trainCarManager;

	private int currentCarLocation = 0;

	// Stool Sitting Stuff
	private bool isSittingOnStool = false;
	private Vector3 preSitPosition = Vector3.zero;
	private GameObject thePlayer;

	//Photo viewing stuff
	private bool viewingPhoto = false;
	public Texture familyPhoto;

	// Train Stops Stuff
	private string[] stopLabels;
	private int currentStop = 0;

	// Emotional Mana and what have you
	//TODO: consume gruffness when banging on doors, replenish when sitting in cabin alone looking at picture, crying.
	// viewing photo increases fear and gruffness
	private float gruffness = 100.0f;
	//TODO: add fear points for every other item in train halls (garbage, windows down, benches down). 
	// Reduce fear when in cabin sipping tea. 
	// Reduce fear when you fix window, bench, throw away garbage
	// Add fear when you do things like knock on quiet doors and knock on occupied WC doors
	// Add fear when viewing photo (but add it super slowly)
	private float fear = 10.0f;
	// TODO: At stops, items are tallied in the train cars. Punishment/Penalty points are added for each item that is out of place (noisy cars, windows down, benches down, garbage found)
	// TODO: When leaving stop for next leg, all out of place items are fixed automatically
	private int penaltyPoints = 0;
	private int maxPenaltyPoints = 10;

	// Costs and Things
	private float gruffnessDecreaseNoisyDoor = 16.0f;
	private float gruffnessIncreaseFactorPhoto = 2.5f;
	private float gruffnessIncreaseSpecialWindow = 1.0f;

	private float fearIncreaseFactorPhoto = 1.5f;
	private float fearDecreaseSpecialWindow = 2.0f;
	private float fearIncreaseBangOnQuietDoor = 18.0f;
	private float fearIncreaseBangOnOccupiedWC = 8.0f;
	private float fearDecreaseSippingTea = 5.0f;

	private float fearDecreaseGarbageDisposal = 1.0f;
	private float fearDecreaseCloseWindow = 1.0f;
	private float fearDecreaseCloseBench = 1.0f;

	// Cooldowns
	private float sippingTeaCooldownTime = 4.5f;
	private float sippingTeaCooldownCounter = 0.0f;

	// Inspection related things
	private GameObject cabinDetector;
	private bool isTrainLadyInHerCabin = false;
	private GameObject cabinQuartersDoor;

	private bool showInspectionSummary = false;

	private bool isGameOver = false;
	private string gameOverReasonString;
	public Texture inspectionPaper;

	// Banging on Doors stuff
	private bool isBangingOnDoor = false;
	private float bangingOnDoorCounter = 0.0f;
	//TODO: tweak based on sound
	private float bangingOnDoorTime = 1.5f;

	// GUI progress bars
	public Texture progressBarBackground;
	public Texture gruffnessProgressBarForeground;
	public Texture fearProgressBarForeground;
	public Texture gruffnessIcon;
	public Texture fearIcon;

	public Texture emptyHandIcon;
	public Texture garbageInHandIcon;

	public Vector2 gruffnessBarPosition;
	public Vector2 fearBarPosition;
	public Vector2 progressBarSize;
	public Vector2 garbageHandIconPosition;
	public Vector2 currentInteractionStringLocation;
	public Texture interactionBackground;

	public Texture carLocationIcon1;
	public Texture carLocationIcon2;
	public Texture carLocationIcon3;
	public Vector2 carLocationIconPosition;

	public Texture teaCupIcon;
	public Vector2 teaCupIconPosition;

	public Texture nextStopBackground;
	public Vector2 nextStopPosition;

	// exit to main menu
	private bool hasPressedEscapeOnce = false;


	// Use this for initialization
	void Start () {
	
		gameOverReasonString = "[none]";

		currentInteractionString = "[none]";

		trainCarManager = GameObject.FindGameObjectWithTag("TrainCarManager");

		if(!trainCarManager){
			Debug.LogError ("Cannot find TrainCarManager!");
		}

		thePlayer = GameObject.FindGameObjectWithTag("Player");
		if(!thePlayer){
			Debug.LogError("InteractionScript:: Cannot find Player!");
		}

		stopLabels = new string[3];
		//Celjabinsk Ekaterinburg Kazan Moskva
		stopLabels[0] = "Celjabinsk -> Ekaterinburg";
		stopLabels[1] = "Ekaterinburg -> Kazan";
		stopLabels[2] = "Kazan -> Moskva";

		cabinDetector = GameObject.FindGameObjectWithTag("CabinDetector");
		if(!cabinDetector){
			Debug.LogError("InteractionScript:: Cannot find Cabin Detector!");
		}

		GameObject[] cabinQuartersDoors = GameObject.FindGameObjectsWithTag("CabinDoor");
		foreach(GameObject cabinDoor in cabinQuartersDoors){
			if(cabinDoor.GetComponent<CabinDoorScript>().isTrainLadysDoor){
				cabinQuartersDoor = cabinDoor;
			}
		}

		if(!cabinQuartersDoor){
			Debug.LogError("InteractionScript:: Cannot find Cabin Quarters Door!");
		}

	}
	
	// Update is called once per frame
	void Update () {
	
		currentCarLocation = trainCarManager.GetComponent<TrainCarManagerScript>().getTrainLadyLocation();

		isTrainLadyInHerCabin = cabinDetector.GetComponent<CabinDetectorScript>().isTrainLadyInCabin();

		//currentInteractionString = "< None >";
		currentInteractionString = "";

		Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
		RaycastHit hit;

		if (Physics.Raycast(ray, out hit, interactionRange)){

			if(hit.transform.tag != "Untagged"){
				currentInteractionString = hit.transform.tag;
			}

			if(hit.transform.CompareTag("CabinBench") || hit.transform.CompareTag("CabinDoor") || hit.transform.CompareTag("RoomDoor") || hit.transform.CompareTag("WCDoor") || hit.transform.CompareTag("CarDoor") || hit.transform.CompareTag("CarDoorNoEntry") || hit.transform.CompareTag("CabinWindow") || hit.transform.CompareTag("Garbage") || hit.transform.CompareTag("GarbageCan") || hit.transform.CompareTag("CabinStool") || hit.transform.CompareTag("SpecialCabinWindow") || hit.transform.CompareTag("Mug") || hit.transform.CompareTag("Photo") || hit.transform.CompareTag("CabinLamp")){

				hit.transform.GetComponent<InteractableObjectScript>().highlightObject();
				currentInteractionObject = hit.transform.gameObject;

			}else{

				currentInteractionObject = null;

			}

		}else{

			currentInteractionObject = null;

		}

		// Interact with current object
		if(Input.GetKeyUp(KeyCode.Space) || Input.GetKeyUp(KeyCode.E)){

			hasPressedEscapeOnce = false;

			if(currentInteractionObject && !viewingPhoto && !showInspectionSummary && !isBangingOnDoor){
					performInteraction();
			}

		}

		// Get up from stool
		if(Input.GetKeyUp(KeyCode.X)){

			hasPressedEscapeOnce = false;

			if(viewingPhoto){

				audio.clip = putDownPhoto;
				audio.Play();

				viewingPhoto = false;

				thePlayer.GetComponent<CharacterMotor>().canControl = true;

			}else if(isSittingOnStool){

				thePlayer.transform.position = preSitPosition;
				isSittingOnStool = false;
				thePlayer.GetComponent<CharacterMotor>().canControl = true;

			}

		}

		//DEBUG
		/*
		if(Input.GetKeyUp (KeyCode.T)){
			resetForNextLeg();
		}
		*/

		if(Input.GetKeyUp (KeyCode.Escape)){
			if(hasPressedEscapeOnce){
				Application.LoadLevel("mainMenu");
			}else{
				hasPressedEscapeOnce = true;
			}
		}


		// TODO: Some kind of visual warning if fear >= 100

		// Increase fear per update if we're looking at photo
		if(viewingPhoto){
			fear = Mathf.Min(100.0f, fear + Time.deltaTime * fearIncreaseFactorPhoto);
			gruffness = Mathf.Min(100.0f, gruffness + Time.deltaTime * gruffnessIncreaseFactorPhoto);
		}

		// Manage cooldowns
		sippingTeaCooldownCounter -= Time.deltaTime;

		// Special bonus for looking "at" (read: out) special cabin window when seated (it calms you down) - but can't double up with photo and special window
		if(currentInteractionObject){

			if(!viewingPhoto && isSittingOnStool && currentInteractionObject.CompareTag("SpecialCabinWindow")){
				fear = Mathf.Max(0.0f, fear - Time.deltaTime * fearDecreaseSpecialWindow);
				gruffness = Mathf.Min(100.0f, gruffness + Time.deltaTime * gruffnessIncreaseSpecialWindow);
			}

		}

		// Check if timer is expired. If it is, we need to do an inspection
		if(trainCarManager.GetComponent<CountdownTimerScript>().isTimerExpired() && !showInspectionSummary){
			doInspection();
		}

		if(isBangingOnDoor){

			bangingOnDoorCounter -= Time.deltaTime;

			if(bangingOnDoorCounter <= 0.0f){
				isBangingOnDoor = false;
				thePlayer.GetComponent<CharacterMotor>().canControl = true;
			}

		}

	}

	void performInteraction(){

		if(currentInteractionObject.CompareTag("CabinBench")){

			// If bench was lowered, decrease fear because we're putting it back up
			// But if we just put it down and it wasn't already, then increase fear by the same amount
			if(currentInteractionObject.GetComponent<CabinBenchScript>().isBenchLowered()){
				fear = Mathf.Max(0.0f, fear - fearDecreaseCloseBench);
			}else{
				fear = Mathf.Min(100.0f, fear + fearDecreaseCloseBench);
			}

			currentInteractionObject.GetComponent<CabinBenchScript>().interactWithBench();

		}else if(currentInteractionObject.CompareTag("CabinDoor")){

			currentInteractionObject.GetComponent<CabinDoorScript>().interactWithDoor();

		}else if(currentInteractionObject.CompareTag("RoomDoor")){

			// If i have gruffness left, spend it
			if(gruffness >= gruffnessDecreaseNoisyDoor && fear < 100.0f){

				gruffness -= gruffnessDecreaseNoisyDoor;

				// if the cabin wasn't being noisy, increase fear
				if(!currentInteractionObject.GetComponent<RoomDoorScript>().isDoorNoisy()){
					fear = Mathf.Min(100.0f, fear + fearIncreaseBangOnQuietDoor);
				}

				currentInteractionObject.GetComponent<RoomDoorScript>().interactWithDoor();

				// Play random sound
				if(Random.Range (0,2) == 1){
					audio.clip = doorKnock1;
				}else{
					audio.clip = doorKnock2;
				}
				audio.Play();

				isBangingOnDoor = true;
				bangingOnDoorCounter = bangingOnDoorTime;
				thePlayer.GetComponent<CharacterMotor>().canControl = false;



			}

		}else if(currentInteractionObject.CompareTag("WCDoor")){

			// If i have gruffness left, spend it
			if(gruffness >= gruffnessDecreaseNoisyDoor){
				
				gruffness -= gruffnessDecreaseNoisyDoor;

				// If WC was occupied, increase fear
				if(!currentInteractionObject.GetComponent<WaterClosetDoorScript>().isWCVacant()){
					fear = Mathf.Min (100.0f, fear + fearIncreaseBangOnOccupiedWC);
				}

				currentInteractionObject.GetComponent<WaterClosetDoorScript>().interactWithDoor();

				// Play random sound
				if(Random.Range (0,2) == 1){
					audio.clip = doorKnock1;
				}else{
					audio.clip = doorKnock2;
				}
				audio.Play();

				isBangingOnDoor = true;
				bangingOnDoorCounter = bangingOnDoorTime;
				thePlayer.GetComponent<CharacterMotor>().canControl = false;

			}

		}else if(currentInteractionObject.CompareTag("CarDoor")){

			currentInteractionObject.GetComponent<TrainCarDoorScript>().interactWithDoor();

		}else if(currentInteractionObject.CompareTag("CarDoorNoEntry")){

			// TODO: play locked door sound

		}else if(currentInteractionObject.CompareTag("CabinWindow")){

			// If window was down, decrease fear because we're putting it back up
			// But if we just put it down and it wasn't already, then increase fear by the same amount
			if(currentInteractionObject.GetComponent<TrainCarWindowScript>().isWindowDown()){
				fear = Mathf.Max(0.0f, fear - fearDecreaseCloseWindow);
			}else{
				fear = Mathf.Min(100.0f, fear + fearDecreaseCloseWindow);
			}

			currentInteractionObject.GetComponent<TrainCarWindowScript>().interactWithWindow();

		}else if(currentInteractionObject.CompareTag("Garbage")){

			if(!haveGarbageInHand){

				haveGarbageInHand = true;

				// TODO: play correct sound based on garbage type
				if(currentInteractionObject.name == "GarbageA(Clone)"){

					//Debug.Log ("pickup garbage A (paper)");

					// Play random sound
					if(Random.Range (0,2) == 1){
						audio.clip = pickupGarbageA1;
					}else{
						audio.clip = pickupGarbageA2;
					}
					audio.Play();

				}else{
					//Debug.Log ("pickup garbage B (can)");
					// Play random sound
					if(Random.Range (0,2) == 1){
						audio.clip = pickupGarbageB1;
					}else{
						audio.clip = pickupGarbageB2;
					}
					audio.Play();
				}


				DestroyObject(currentInteractionObject);

			}else{

				Debug.Log("Already have garbage in hand");

			}

		}else if(currentInteractionObject.CompareTag("GarbageCan")){

			if(haveGarbageInHand && currentInteractionObject.GetComponent<GarbageCanScript>().canInteract()){

				currentInteractionObject.GetComponent<GarbageCanScript>().throwAwayGarbage();
				haveGarbageInHand = false;

				//audio.clip = garbageCan;
				//audio.Play();

				// Decrease fear because we're putting garbage away
				fear = Mathf.Max(0.0f, fear - fearDecreaseGarbageDisposal);

			}

		}else if(currentInteractionObject.CompareTag("CabinStool")){

			// If player is not sitting on stool, remember where they were and sit them down
			if(!isSittingOnStool){

				GameObject cabinStoolSittingTransform = GameObject.FindGameObjectWithTag("CabinStoolSittingTransform");
				if(!cabinStoolSittingTransform){
					Debug.LogError("Can't find cabin stool sitting transform!");
				}

				preSitPosition = thePlayer.transform.position;

				Vector3 sittingPosition = thePlayer.transform.position;
				sittingPosition.x = cabinStoolSittingTransform.transform.position.x;
				sittingPosition.z = cabinStoolSittingTransform.transform.position.z;

				thePlayer.transform.position = sittingPosition;

				thePlayer.GetComponent<CharacterMotor>().canControl = false;

				isSittingOnStool = true;

			}

		}else if(currentInteractionObject.CompareTag("SpecialCabinWindow")){

			currentInteractionObject.GetComponent<TrainCarWindowScript>().interactWithWindow();

		}else if(currentInteractionObject.CompareTag("Mug")){
			
			// TODO: sipping tea sound
			if(sippingTeaCooldownCounter <= 0.0f){

				if(Random.Range (0,2) == 1){
					audio.clip = sipTea1;
				}else{
					audio.clip = sipTea2;
				}
				audio.Play();

				fear = Mathf.Max(0.0f, fear - fearDecreaseSippingTea);
				sippingTeaCooldownCounter = sippingTeaCooldownTime;
			}
			
		}else if(currentInteractionObject.CompareTag("Photo")){
			
			//currentInteractionObject.GetComponent<CabinLampScript>().interactWithLamp();
			viewingPhoto = true;

			thePlayer.GetComponent<CharacterMotor>().canControl = false;

			audio.clip = pickupPhoto;
			audio.Play();
			
		}else if(currentInteractionObject.CompareTag("CabinLamp")){

			currentInteractionObject.GetComponent<CabinLampScript>().interactWithLamp();

			//audio.clip = lampSwitch;
			//audio.Play();

		}

	}

	// Ensure player is in car, tally penalty points, and reset car and timer for next round
	void doInspection(){

		// Check if train lady is in her cabin with the door closed. If not, game over
		if(!isTrainLadyInHerCabin || cabinQuartersDoor.GetComponent<CabinDoorScript>().isDoorCurrentlyOpen()){
			//gameOver();
			isGameOver = true;
			gameOverReasonString = "You failed to sit inside your cabin with the door closed quarters during inspection.";
		}else{
			// if she was, lock the door
			cabinQuartersDoor.GetComponent<CabinDoorScript>().lockDoor();
		}

		// Count up messy things
		penaltyPoints += trainCarManager.GetComponent<TrainCarManagerScript>().getGarbageCount();
		penaltyPoints += trainCarManager.GetComponent<TrainCarManagerScript>().getOpenWindowsCount();
		penaltyPoints += trainCarManager.GetComponent<TrainCarManagerScript>().getLoweredBenchesCount();
		penaltyPoints += trainCarManager.GetComponent<TrainCarManagerScript>().getNoisyCabinCount();
		penaltyPoints += trainCarManager.GetComponent<TrainCarManagerScript>().getOpenTrainCarDoorsCount();

		//Debug.Log("Penalty Points = " + penaltyPoints);

		if(penaltyPoints >= maxPenaltyPoints){
			//gameOver();
			isGameOver = true;
			gameOverReasonString = "You did not tend to your train cars well, and have incurred too many penalties.";
		}

		showInspectionSummary = true;

	}

	// Lose scenario
	void gameOver(){
		//Debug.Log("Game Over: You were removed from your post.");
		Application.LoadLevel("gameOver");
	}

	void gameEnding(){
		//Debug.Log("You did it.");
		Application.LoadLevel("gameEnd");
	}

	void resetForNextLeg(){

		// reset all train cars
		trainCarManager.GetComponent<TrainCarManagerScript>().resetTrainCarsForNextLeg();

		// reset mana
		fear = 5.0f;
		gruffness = 100.0f;

		// unlock cabin door
		cabinQuartersDoor.GetComponent<CabinDoorScript>().unlockDoor();

		// start next leg of the journey
		//currentStop += 1;

		if((currentStop + 1)  >= stopLabels.Length){
			gameEnding();
		}else{
			currentStop += 1;
		}

		/*
		if(currentStop >= stopLabels.Length){
			gameEnding();
		}
		*/

		// reset leg timer
		trainCarManager.GetComponent<CountdownTimerScript>().resetTimer();

		showInspectionSummary = false;

	}


	void OnGUI(){


		if(showInspectionSummary){

			GUI.DrawTextureWithTexCoords(new Rect(Screen.width/2 - Screen.width/4, 0, Screen.width/2, Screen.height/2), inspectionPaper, new Rect(0.0f,0.0f,3.0f,1.0f), true);

			GUI.color = Color.black;

			float inspectionTextOffsetX = Screen.width/2-256;
			float inspectionTextOffsetY = 24.0f;

			GUI.Label(new Rect(Screen.width/2-128,4,512,20), "***** INSPECTION SUMMARY *****");

			GUI.Label(new Rect(inspectionTextOffsetX,inspectionTextOffsetY*12, 256, 20), "Press 'X' to Continue");

			if(isGameOver){

				GUI.color = Color.red;
				GUI.Label(new Rect(inspectionTextOffsetX,inspectionTextOffsetY, 256, 20), "Inspection Failed.");
				GUI.color = Color.black;
				GUI.Label(new Rect(inspectionTextOffsetX,inspectionTextOffsetY*2,Screen.width-10, 20), gameOverReasonString);

				//GUI.Label(new Rect(inspectionTextOffsetX,inspectionTextOffsetY, 256, 20), "Press 'X' to Continue");

				//if(GUI.Button(new Rect(10, 160, 256, 30), "Press 'X' to Continue") || Input.GetKeyUp(KeyCode.X)){
				if(Input.GetKeyUp(KeyCode.X)){
					Application.LoadLevel("gameOver");
				}

			}else{

				GUI.color = Color.green;
				GUI.Label(new Rect(inspectionTextOffsetX,inspectionTextOffsetY, 256, 20), "Inspection Passed.");
				GUI.color = Color.black;

				//GUI.Label(new Rect(inspectionTextOffsetX,inspectionTextOffsetY, 256, 20), "Press 'X' to Continue");

				//if(GUI.Button(new Rect(10, 160, 256, 30), "Press 'X' to Start Next Leg") || Input.GetKeyUp(KeyCode.X)){
				if(Input.GetKeyUp(KeyCode.X)){
					//Debug.Log("Time for next leg");
					resetForNextLeg();
				}

			}

			GUI.Label(new Rect(inspectionTextOffsetX, inspectionTextOffsetY*4, 256, 20),"Garbage Found  ....." + trainCarManager.GetComponent<TrainCarManagerScript>().getGarbageCount());
			GUI.Label(new Rect(inspectionTextOffsetX, inspectionTextOffsetY*5, 256, 20),"Windows Left Open  ....." + trainCarManager.GetComponent<TrainCarManagerScript>().getOpenWindowsCount());
			GUI.Label(new Rect(inspectionTextOffsetX, inspectionTextOffsetY*6, 256, 20),"Benches Left Down  ....." + trainCarManager.GetComponent<TrainCarManagerScript>().getLoweredBenchesCount());
			GUI.Label(new Rect(inspectionTextOffsetX, inspectionTextOffsetY*7, 256, 20),"Noisy Cabins  ....." + trainCarManager.GetComponent<TrainCarManagerScript>().getNoisyCabinCount());
			GUI.Label(new Rect(inspectionTextOffsetX, inspectionTextOffsetY*8, 256, 20),"Open Train Car Doors  ....." + trainCarManager.GetComponent<TrainCarManagerScript>().getOpenTrainCarDoorsCount());
			GUI.Label(new Rect(inspectionTextOffsetX, inspectionTextOffsetY*9, 256, 20),"- - - - - - - - - - - - - - - - - - - -");
			GUI.Label(new Rect(inspectionTextOffsetX, inspectionTextOffsetY*10, 256, 20),"Total Penalties  ....." + penaltyPoints);


		}else{

			//////////////////////////
			/// TIME AND NEXT STOP ///
			//////////////////////////

			GUI.color = Color.white;

			// Draw fancy timer and next stop label

			nextStopPosition.x = 0;
			nextStopPosition.y = Screen.height - 86.0f;

			GUI.DrawTextureWithTexCoords(new Rect(nextStopPosition.x,nextStopPosition.y,259,83), nextStopBackground, new Rect(0.0f,0.0f,1.0f,1.0f));

			int remainingSeconds = trainCarManager.GetComponent<CountdownTimerScript>().getSecondsRemaining();
			int remainingSecondsRounded = Mathf.CeilToInt(remainingSeconds);
			
			if(remainingSeconds <= 60){
				GUI.color = Color.red;
			}else{
				GUI.color = Color.white;
			}
			
			int displaySeconds = (remainingSecondsRounded % 60);
			int displayMinutes = (remainingSecondsRounded / 60);
			string timerText = string.Format("{0:00}:{1:00}", displayMinutes, displaySeconds);
			//GUI.Label(new Rect(0,Screen.height-24, 128, 20), "Next Stop: " + timerText);
			
			//TODO: actual countdown to time left
			//GUI.TextArea(new Rect(0,Screen.height-24, 128, 20), "Next Stop: 00:00");

			//Time
			GUI.Label(new Rect(nextStopPosition.x + 8, nextStopPosition.y + 16, 64, 24), timerText);

			GUI.color = Color.white;

			// Next stop
			GUI.Label(new Rect(nextStopPosition.x + 8, nextStopPosition.y + 58, 256, 24), stopLabels[currentStop]);

			//////////////////////////



			// DEBUG - Show totals of each messed up item in train cars:
			// Garbage, Windows, Benches, Noisy Cabins
			/*
			GUI.TextArea(new Rect(Screen.width - 128, 0, 128, 20),"G=" + trainCarManager.GetComponent<TrainCarManagerScript>().getGarbageCount());
			GUI.TextArea(new Rect(Screen.width - 128, 24, 128, 20),"W=" + trainCarManager.GetComponent<TrainCarManagerScript>().getOpenWindowsCount());
			GUI.TextArea(new Rect(Screen.width - 128, 48, 128, 20),"B=" + trainCarManager.GetComponent<TrainCarManagerScript>().getLoweredBenchesCount());
			GUI.TextArea(new Rect(Screen.width - 128, 72, 128, 20),"N=" + trainCarManager.GetComponent<TrainCarManagerScript>().getNoisyCabinCount());
			GUI.TextArea(new Rect(Screen.width - 128, 99, 128, 20),"TCD=" + trainCarManager.GetComponent<TrainCarManagerScript>().getOpenTrainCarDoorsCount());
			*/

			// Current Interaction
			GUI.DrawTexture(new Rect(currentInteractionStringLocation.x,currentInteractionStringLocation.y,256,32), interactionBackground);
			GUI.Label(new Rect(currentInteractionStringLocation.x+4,currentInteractionStringLocation.y+4,256,32), currentInteractionString);


			//TODO: fancy train car graphical map thinger
			//GUI.TextArea(new Rect(0,48,128,20), "Train Car Location: " + currentCarLocation);
			if(currentCarLocation == 1){
				GUI.DrawTexture (new Rect(carLocationIconPosition.x,carLocationIconPosition.y, 232, 24), carLocationIcon1);
			}else if(currentCarLocation == 2){
				GUI.DrawTexture (new Rect(carLocationIconPosition.x,carLocationIconPosition.y, 232, 24), carLocationIcon2);
			}else if(currentCarLocation == 3){
				GUI.DrawTexture (new Rect(carLocationIconPosition.x,carLocationIconPosition.y, 232, 24), carLocationIcon3);
			}

			//DEBUG
			//GUI.TextArea(new Rect(128,48,128,20), "In Cabin: " + isTrainLadyInHerCabin);














			//TODO: icon for garbage in hand or not
			//GUI.TextArea(new Rect(0,24,128,20), "Garbage: " + haveGarbageInHand);

			// Garbage in hand icons
			if(haveGarbageInHand){
				GUI.DrawTextureWithTexCoords(new Rect(garbageHandIconPosition.x, garbageHandIconPosition.y, 48, 48), garbageInHandIcon, new Rect(0.0f,0.0f,1.0f,1.0f));
			}else{
				GUI.DrawTextureWithTexCoords(new Rect(garbageHandIconPosition.x, garbageHandIconPosition.y, 48, 48), emptyHandIcon, new Rect(0.0f,0.0f,1.0f,1.0f));
			}





			// Emotional Mana
			if(gruffness < gruffnessDecreaseNoisyDoor){
				GUI.color = Color.red;
			}else if(gruffness <= gruffnessDecreaseNoisyDoor*2){
				GUI.color = Color.yellow;
			}else{
				GUI.color = Color.white;
			}
			//GUI.TextArea(new Rect(0, 72, 128, 20), "GRRuffness:" + gruffness.ToString("F2"));
			


			// Gruffness Bar
			GUI.DrawTextureWithTexCoords(new Rect(gruffnessBarPosition.x - 40, gruffnessBarPosition.y, 32, 32), gruffnessIcon, new Rect(0.0f,0.0f,1.0f,1.0f));
			//GUI.DrawTextureWithTexCoords(new Rect(gruffnessBarPosition.x - 1, gruffnessBarPosition.y, progressBarSize.x+2, progressBarSize.y), progressBarBackground, new Rect(0.0f,0.0f,1.0f,1.0f));
			GUI.DrawTexture(new Rect(gruffnessBarPosition.x, gruffnessBarPosition.y, progressBarSize.x, progressBarSize.y), progressBarBackground);
			GUI.DrawTextureWithTexCoords(new Rect(gruffnessBarPosition.x+2, gruffnessBarPosition.y+2, (progressBarSize.x * gruffness/100.0f)-4, progressBarSize.y-4), gruffnessProgressBarForeground, new Rect(0.0f,0.0f,1.0f,1.0f));
			GUI.color = Color.white;
			//GUI.Label(new Rect(gruffnessBarPosition.x + progressBarSize.x/2, gruffnessBarPosition.y, progressBarSize.x, progressBarSize.y), gruffness.ToString("F2"));
			GUI.Label(new Rect(gruffnessBarPosition.x + progressBarSize.x, gruffnessBarPosition.y+4, progressBarSize.x, progressBarSize.y), gruffness.ToString("F2"));

			if(fear == 100.0f){
				GUI.color = Color.red;
			}else if(fear >= 70.0f){
				GUI.color = Color.yellow;
			}else{
				GUI.color = Color.white;
			}
			//GUI.TextArea(new Rect(0, 96, 128, 20), "Fear:" + fear.ToString("F2"));

			// Fear Bar
			//GUI.DrawTextureWithTexCoords(new Rect(128, 192, progressBarSize.x, progressBarSize.y), progressBarBackground, new Rect(0.0f,0.0f,1.0f,1.0f));
			//GUI.DrawTextureWithTexCoords(new Rect(128, 192, progressBarSize.x * gruffness/100.0f, progressBarSize.y), gruffnessProgressBarForeground, new Rect(0.0f,0.0f,1.0f,1.0f));
			GUI.DrawTextureWithTexCoords(new Rect(fearBarPosition.x - 40, fearBarPosition.y, 32, 32), fearIcon, new Rect(0.0f,0.0f,1.0f,1.0f));
			//GUI.DrawTextureWithTexCoords(new Rect(fearBarPosition.x, fearBarPosition.y, progressBarSize.x, progressBarSize.y), progressBarBackground, new Rect(0.0f,0.0f,1.0f,1.0f));
			GUI.DrawTexture(new Rect(fearBarPosition.x, fearBarPosition.y, progressBarSize.x, progressBarSize.y), progressBarBackground);
			GUI.DrawTextureWithTexCoords(new Rect(fearBarPosition.x+2, fearBarPosition.y+2, (progressBarSize.x * fear/100.0f) - 4, progressBarSize.y-4), fearProgressBarForeground, new Rect(0.0f,0.0f,1.0f,1.0f));
			GUI.color = Color.white;
			//GUI.Label(new Rect(fearBarPosition.x + progressBarSize.x/2, fearBarPosition.y, progressBarSize.x, progressBarSize.y), fear.ToString("F2"));
			GUI.Label(new Rect(fearBarPosition.x + progressBarSize.x, fearBarPosition.y+4, progressBarSize.x, progressBarSize.y), fear.ToString("F2"));


















			


			GUI.color = Color.white;

			// DEBUG
			if(sippingTeaCooldownCounter > 0){
				GUI.DrawTextureWithTexCoords(new Rect(teaCupIconPosition.x,teaCupIconPosition.y, 48, 48), teaCupIcon, new Rect(0.0f,0.0f,1.0f,1.0f));
				GUI.color = Color.black;
				//GUI.Label(new Rect(teaCupIconPosition.x+8,teaCupIconPosition.y+16, 48,48), sippingTeaCooldownCounter.ToString("F2"));
				GUI.Label(new Rect(teaCupIconPosition.x+8,teaCupIconPosition.y+16, 48,48), sippingTeaCooldownCounter.ToString("F1"));
			}

			GUI.color = Color.white;

			//TODO: make something more easily understandable to get out of stool?
			if(isSittingOnStool && !viewingPhoto){
				GUI.Label(new Rect(Screen.width/2 - 128,Screen.height-64,256,20), "Press 'X' to stand up");
			}

			if(viewingPhoto){
				GUI.DrawTexture(new Rect(Screen.width/2 - 256,Screen.height/2 - 256, 512, 512), familyPhoto);
				GUI.Label(new Rect(Screen.width/2 - 128,Screen.height-64,256,20), "Press 'X' to set photo down");
			}

		}

	}

	public void increaseFearBy(float increaseAmount){
		fear = Mathf.Min (100.0f, fear + increaseAmount);
	}



}














