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

public class MenuFunctions : MonoBehaviour
{
    public Slider sensXSlider = null;
    public TextMeshProUGUI multiplierText = null;
    public float multiplier = 100f;
    public float fov = 60f;
    public Slider fovSlider = null;
    public TextMeshProUGUI fovText = null;
    public bool IsInMainMenu = false;
    public void QuitGame()
    {
        Application.Quit();
    }
    public void Start()
    {
        if (IsInMainMenu)
        {
            if (!PlayerPrefs.HasKey("GameInitialized"))
            {
                SetDefaultPreferences();
                PlayerPrefs.SetInt("GameInitialized", 1);
                PlayerPrefs.Save();
            }
            Cursor.lockState = CursorLockMode.None;
            Cursor.visible = true;
            if (sensXSlider != null)
            {
                sensXSlider.value = PlayerPrefs.GetInt("multiplier", 0);
            }
            if (fovSlider != null)
            {
                fovSlider.value = PlayerPrefs.GetInt("fov", 0);
            }
        }
    }
    void SetDefaultPreferences()
    {
        PlayerPrefs.SetInt("multiplier", 100);
        PlayerPrefs.SetInt("fov", 60);
    }
    public void SetSens()
    {
        PlayerPrefs.SetInt("multiplier", (int)sensXSlider.value);
        multiplier = PlayerPrefs.GetInt("multiplier", 0);
        multiplierText.text = "Multiplier: " + multiplier.ToString();
    }
    public void SetFov()
    {
        PlayerPrefs.SetInt("fov", (int)fovSlider.value);
        fov = PlayerPrefs.GetInt("fov", 0);
        fovText.text = "Fov: " + fov.ToString();
    }
    public void Update()
    {
        if (sensXSlider != null)
        {
            SetSens();
        }
        if (fovSlider != null)
        {
            SetFov();
        }
    }
    public void play(int value)
    {
        SceneManager.LoadScene(value);
    }
    public void retry()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    }
    public void MainMenuButton()
    {
        SceneManager.LoadScene(0);
    }
    public void nextlevel()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
    }

}
