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

public class SymbolKeyBehavior : MonoBehaviour {

	private GameObject display;
    public AudioClip pressSymbolKeySound;

    // Use this for initialization
    void Start () {
		display = GameObject.Find("display");
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	public void onClick()
	{
        if(Dictionaries.dictionaries.currentDictionary != '\0')
        {
            GetComponent<AudioSource>().PlayOneShot(pressSymbolKeySound);

            int currentDisplayLength = Dictionaries.dictionaries.currentDisplaySymbols.Count;

            if (currentDisplayLength < 4)
            {
                for (int i = 0; i < Dictionaries.dictionaries.currentDisplaySymbols.Count; i++)
                {
                    ((GameObject)Dictionaries.dictionaries.currentDisplaySymbols[i]).transform.position += Vector3.left * 30.0f;
                }

                GameObject newDisplaySymbol = Instantiate(Resources.Load("Prefabs/displaySymbol", typeof(GameObject)), display.transform.position +
                                                 new Vector3(40.0f, 0, 0), Quaternion.identity) as GameObject;
                newDisplaySymbol.transform.SetParent(display.transform);
                newDisplaySymbol.GetComponentInChildren<Image>().sprite = Resources.Load<Sprite>("Symbols/screen_" + Dictionaries.dictionaries.currentDictionary + name);
                Dictionaries.dictionaries.currentDisplaySymbols.Add(newDisplaySymbol);
            }

            Dictionaries.dictionaries.messageToSend += name;
        }		
	}

}