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

public class UIController : MonoBehaviour {

    public static UIController Instance;

    public bool paused = false;

    public Text timeText;
    public ActionsRadial actionsRadial;
    public ActionAsset actionToTargetSelect;
    public GameObject menu;
    public Button startButton;
    public Button resumeButton;
    public GameObject endScreen;
    public Button skipToFlood;

    public ComplexBar moneyBar;
    public ComplexBar energyBar;
    public ComplexBar peopleBar;
    public ComplexBar buildingBar;

    public static int time {
        get {
            return int.Parse(Instance.timeText.text);
        }
        set {
            Instance.timeText.text = value.ToString();
        }
    }

    void Awake()
    {
        Instance = this;
        endScreen.gameObject.SetActive(false);
    }

    void Start()
    {
        Pause(true);
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (!paused)
                Pause(true);
            else
                QuitGame();
        }
    }

    public void Pause(bool value)
    {
        paused = value;
        if (value)
        {
            startButton.gameObject.SetActive(!GameController.Instance.gameStarted);
            resumeButton.gameObject.SetActive(GameController.Instance.gameStarted);              
        } else
        {
            GameController.Instance.gameStarted = true;
        }
        GameController.Instance.enabled = !paused;
        TileManager.Instance.enabled = !paused;
        menu.SetActive(paused);
    }

    public void QuitGame()
    {
        Application.Quit();
    }

    public void Restart()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }

    public void SkipToFlood()
    {
        GameController.Instance.FloodStart();
    }
        
}
