using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;

public class ButtonListener : MonoBehaviour {

    public bool alertButton = false;
    Disparador disparador;

    public void OnButtonClicked(int indice) {
        //TODO DO SHIT
        switch (indice) {
            case 0:
                disparador.Shoot();
                break;
            default:
                break;
        }
    }

    void Start() {
        if (alertButton) {
            GameObject disp = GameObject.FindGameObjectWithTag("Shooter");
            disparador = disp.GetComponentInChildren<Disparador>();
        }
    }

    void Update() {
        if (alertButton && Input.GetKeyDown(KeyCode.Space)) {
            Button butt = gameObject.GetComponentInChildren<Button>();

            var pointer = new PointerEventData(EventSystem.current); // pointer event for Execute
            ExecuteEvents.Execute<ISubmitHandler>(butt.gameObject, pointer, ExecuteEvents.submitHandler);
        }
    }

    public void NewGame() {
        SceneManager.LoadScene(2);
    }

    public void Continue() {
        //TODO mandar carregar última fase
        SceneManager.LoadScene(2);
    }

    public void MainMenu() {
        SceneManager.LoadScene(1);
    }

    public void LevelEditor() {

    }

    public void Instructions() {

    }

    public void Credits() {
        SceneManager.LoadScene(3);
    }
}
