using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class GameOverSpeechBubbleController : MonoBehaviour
{
	//Editor variables
	float textTypeSpeed;

	//Working variables
	public static GameOverSpeechBubbleController instance;
	int characterPointer;
	string gameOverText = "Hey, I just came to check up... Whoa!!! The whole village is on fire?? What did you do?! I'm sorry, you're clearly not the Trainee Deity Appeasement Admin we're looking for. ";
	Text textRef;
	float lastCharTypeTime;

	void Reset()
	{
		textTypeSpeed = 0.3f;
	}

	void Awake()
	{
		instance = this;
		textRef = transform.GetComponentInChildren<Text>();
	}

	void Start()
	{
		characterPointer = 0;
	}

	void startTypingOutNewPage()
	{
		characterPointer = 0;
		AudioController.instance.playSFX(AudioController.audioClips.mumble);
	}

	void Update()
	{
		CanvasGroup grp = transform.parent.GetComponent<CanvasGroup>();
		if (!grp.interactable || Time.time - lastCharTypeTime < textTypeSpeed) { return; }

		if (characterPointer < gameOverText.Length-1)
		{
			characterPointer++;
			textRef.text = gameOverText.Substring(0, characterPointer);
			lastCharTypeTime = Time.time;
		}
	}
}
