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

public class PauseMenu : MonoBehaviour {
    public static bool paused = false;
    public static string log = "";
    public CanvasGroup pauseBlack;
    private bool wasPaused;

    // Start is called before the first frame update
    void Start() {
    }

    void OnDestroy() {
    }

    // Update is called once per frame
    void Update() {
        if (paused) {
            pauseBlack.alpha = Mathf.Lerp(pauseBlack.alpha, 1.0f, Time.unscaledDeltaTime * 3.0f);
            if (!wasPaused) {
                Time.timeScale = 0.0f;
                Cursor.lockState = CursorLockMode.None;
            }
        }
        else {
            pauseBlack.alpha = Mathf.Lerp(pauseBlack.alpha, 0.0f, Time.unscaledDeltaTime * 3.0f);
            if (wasPaused) {
                Time.timeScale = 1.0f;
                Cursor.lockState = CursorLockMode.Locked;
            }
        }
        wasPaused = paused;
    }

    public static void AddToLog(string s, string w = "") {
        if (w == "%y" && ThirdPersonController.main!=null) {
            log += "\n\n<i>" + ThirdPersonController.main.entity.charName + ":</i>\n" + s;
        }
        else if (w != "") {
            log += "\n\n<i>" + w + ":</i>\n" + s;
        }
        else {
            log += "\n\n" + s;
        }
        if (log.Length > 1500) {
            int f = log.IndexOf("</i>");
            if (f > 0) {
                log = log.Substring(f + 4);
            }
        }
    }
}
