using UnityEngine;
using UnityEngine.UI;
using TMPro;

public class GameManager : MonoBehaviour
{
    public static GameManager gameManager;
    public GameObject playerPrefab;
    public GameObject player;
    public GameObject uiPanel;
    public GameObject textPanel;
    public TMP_Text tmp_headline;
    public TMP_Text tmp_content;
    public bool isRunning;
    
    private void Awake()
    {
        // Singleton:
        // If there is an instance, and it's not me, delete myself.
        if (gameManager != null && gameManager != this)
        {
            Destroy(this);
        }
        else
        {
            gameManager = this;
        }
    }

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        isRunning = false;
        TurnUIOn();
        Time.timeScale = 1;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            ToggleUI();
        }
    }

    public void StartGame()
    {
        TurnUIOff();
        isRunning = true;
        player = Instantiate(playerPrefab);
    }

    public void ToggleUI()
    {
        if (uiPanel.activeInHierarchy)
        {
            TurnUIOff();
        }
        else
        {
            TurnUIOn();
        }
    }
    public void TurnUIOn()
    {
        uiPanel.SetActive(true);
        Time.timeScale = 0;
    }
    public void TurnUIOff()
    {
        uiPanel.SetActive(false);
        Time.timeScale = 1;
    }

    public void ShowText(string headline, string content) 
    {
        tmp_headline.text = headline;
        tmp_content.text = content;
        textPanel.SetActive(true);
    }
    public void HideText()
    {
        textPanel.SetActive(false);
    }

}
