using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class Freq_script : MonoBehaviour 
{
	public float minFreq, maxFreq;
	public GameObject RightArrowBtnPressed, LeftArrowBtnPressed;
	public TMP_Text txtFreq;
	public GameObject emojiFace;

	// Use this for initialization
	void Start () 
	{
		
	}
	
	// Update is called once per frame
	void Update () 
	{
		if (Input.GetKey (KeyCode.RightArrow)) 
		{
			RightArrowBtnPressed.SetActive (true);

			if (SharedValues_script.freq < maxFreq) 
			{
				SharedValues_script.freq += 0.1f;
				SharedValues_script.freq = System.Math.Round (SharedValues_script.freq,1);
				txtFreq.text = SharedValues_script.freq.ToString ("000.00");
				CheckFreq ();
			}
		} 
		else if (Input.GetKeyUp (KeyCode.RightArrow)) 
		{
			RightArrowBtnPressed.SetActive (false);
		}


		if (Input.GetKey (KeyCode.LeftArrow)) 
		{
			LeftArrowBtnPressed.SetActive (true);

			if (SharedValues_script.freq > minFreq) 
			{
				SharedValues_script.freq -= 0.1f;
				SharedValues_script.freq = System.Math.Round (SharedValues_script.freq,1);
				txtFreq.text = SharedValues_script.freq.ToString ("000.00");
				CheckFreq ();
			}
		} 
		else if (Input.GetKeyUp (KeyCode.LeftArrow)) 
		{
			LeftArrowBtnPressed.SetActive (false);
		}


		if (Input.GetKeyDown (KeyCode.UpArrow)) 
		{
			if (SharedValues_script.freq < maxFreq) 
			{
				SharedValues_script.freq += 0.1f;
				SharedValues_script.freq = System.Math.Round (SharedValues_script.freq,1);
				txtFreq.text = SharedValues_script.freq.ToString ("000.00");
				CheckFreq ();
			}
		}

		if (Input.GetKeyDown (KeyCode.DownArrow)) 
		{
			if (SharedValues_script.freq > minFreq) 
			{
				SharedValues_script.freq -= 0.1f;
				SharedValues_script.freq = System.Math.Round (SharedValues_script.freq,1);
				txtFreq.text = SharedValues_script.freq.ToString ("000.00");
				CheckFreq ();
			}
		}
	}

	void CheckFreq()
	{
		SharedValues_script.foundScenarioFreq = false;
		foreach (Scenarioes sc in gameObject.GetComponent<DialogueInteraction_script>().scenarioes) 
		{
			if (SharedValues_script.freq.ToString ("000.00") == sc.ScenarioFreq) 
			{
				emojiFace.SetActive (true);
				SharedValues_script.foundScenarioFreq = true;
			}
		}

		if(!SharedValues_script.foundScenarioFreq)
			emojiFace.SetActive (false);
	}
}
