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

public enum FeedbackType
{
    Victim,
    VictimNext,
    VictimDamage,
    Executioner,
    ExecutionerMental
}

public class Feedback : MonoBehaviour 
{
    public FeedbackType m_type;
    public string[] m_texts;
    public int m_curText;
    public Text m_textObj;
    public int m_curSound;
    public AudioSource[] m_sounds;
    public bool m_isActive = false;
    public bool m_isDone = false;
    public TortureManager m_manager;
	void Start () 
    {
        m_manager = GameObject.FindGameObjectWithTag("TortureManager").GetComponent<TortureManager>();
	}
	
	// Update is called once per frame
	void Update () 
    {
	    if(m_isActive)
        {
            if(m_curSound != -1)
            {
                if(m_sounds[m_curSound].isPlaying==false)
                {
                    if(m_isDone == false)
                    {
                        m_isDone = true;
                        m_manager.OnFeedbackEnd(this);
                        Activate(false);
                    }
                }
            }
            else
            {
                m_isDone = true;
                m_manager.OnFeedbackEnd(this);
                Activate(false);
            }
        }
	}

    public void GenerateFeedback()
    {
        m_curText = Random.Range(0, m_texts.Length);

        m_curSound = -1;
        if(m_sounds.Length > 0)
        {
            m_curSound = Random.Range(0, m_sounds.Length);
        }
    }

    public void Activate(bool _b)
    {
        m_isActive = _b;
        m_isDone = false;
        if(_b)
        {
            if(m_curText != -1)
            {
                m_textObj.text = m_texts[m_curText];
            }
            if (m_curSound != -1)
            {
                m_sounds[m_curSound].Play();
            }
            m_textObj.gameObject.SetActive(true);
        }
        else
        {
            if (m_curText != -1)
            {

            }
            if (m_curSound != -1)
            {
                m_sounds[m_curSound].Stop();
            }
            //m_textObj.gameObject.SetActive(false);
        }
    }

}
