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

public class ChangeBoxColorUI : MonoBehaviour {

    public List<Image> combo_BG = new List<Image>();
    public ComboChecker comboChecker;

    void OnEnable() 
    {
        EventManager.StartListening(Constants.CorrectInput, ChangeSpriteToGreen);
        EventManager.StartListening(Constants.IncorrectInput, ChangeSpriteToRed);
        EventManager.StartListening(Constants.UpdateCombo, ChangeSpriteToWhite);
    }

    void OnDisable() 
    {
        EventManager.StopListening(Constants.CorrectInput, ChangeSpriteToGreen);
        EventManager.StopListening(Constants.IncorrectInput, ChangeSpriteToRed);
        EventManager.StopListening(Constants.UpdateCombo, ChangeSpriteToWhite);
    }

    void ChangeSpriteToGreen() 
    {
        combo_BG[comboChecker.inputCounter - 1].color = new Color32(94, 255, 88, 255);
    }

    void ChangeSpriteToRed() 
    {
        combo_BG[comboChecker.inputCounter - 1].color = new Color32(255, 143, 143, 255);
    }

    void ChangeSpriteToWhite() 
    {
        //Change all boxes to white after pressing wrong number
        for (int i = 0; i < 4; i++) 
        {
            combo_BG[i].color = Color.white;
        }
    }
}
