using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UI_Attract : TM_UI_Base
{

    public AudioClip clip_StartGame;
    public AudioClip clip_ClearPrefs;

    private GameManager theGame;

    public GameObject btnClearHighScoreName;

    private float fDelay = 3.0f;

    public override void TurnOn()
    {
        base.TurnOn();
        theGame = GameManager.GetGame();
        fDelay = 3.0f;

        if (string.IsNullOrEmpty(PlayerPrefs.GetString("highscorename")))
        {
            btnClearHighScoreName.SetActive(false);
        }
        else
        {
            btnClearHighScoreName.SetActive(true);
        }
    }

    public override void Update()
    {
        if (bFirstUpdate)
        {
            bFirstUpdate = false;
        }

        if (fDelay > 0f)
        {
            fDelay -= Time.deltaTime;
        }
        else
        {
            if (theGame.thePlayer.myRewiredPlayer.GetButton("FireWeapon") ||
                theGame.thePlayer.myRewiredPlayer.GetAxis2D("AimVertical", "AimHorizontal").sqrMagnitude > 0.1f)
            {
                TM_AudioManager.PlayClip(clip_StartGame);
                theGame.StartNewGame();
            }
        }

    }

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

    public void OnClick_Reset()
    {
        PlayerPrefs.DeleteAll();
        TM_AudioManager.PlayClip(clip_ClearPrefs);
        TurnOn();
    }
}
