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

public class MainMenuGUIState : GuiState {
   
    private GameObject mainMenuContainer;

    private Button playButton;

    public override void Initialize() {
 	    base.Initialize();

        if (GameObject.Find("r_MainMenuContainer")) {
            mainMenuContainer = GameObject.Find("r_MainMenuContainer");
        } else {
            GameObject tmpGO = (GameObject)Resources.Load(guiRootPath + "r_MainMenuContainer");
            mainMenuContainer = (GameObject)Object.Instantiate(tmpGO);
        }

        mainMenuContainer.transform.SetParent(uiRoot, false);

        if (GameObject.Find("r_PlayButton")) {
            playButton = GameObject.Find("r_PlayButton").GetComponent<Button>();
            playButton.onClick.AddListener(() => Play());
        }
    }

    public void Dispose() {
        Object.Destroy(mainMenuContainer);
    }

    public void UpdateGameTime() {
        if (UnityEngine.Input.GetButtonDown("ButtonA1")) {
            Play();
        }
    }

    private void Play() {
        StateManager.Instance.SetGameState(GameObject.FindObjectOfType<TRexGameState>());
    }
}
