using System;
using System.Collections;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using UnityEngine.Video;

// Token: 0x020000C0 RID: 192
public class MainMenu : MonoBehaviour
{
	// Token: 0x06001227 RID: 4647 RVA: 0x00162480 File Offset: 0x00160680
	private void Start()
	{
		this.rectTransform = this.videoImg.gameObject.GetComponent<RectTransform>();
		this.canvas.worldCamera = Links.x.menuCamera;
		Time.timeScale = 1f;
		this.group.alpha = 0f;
		if (Records.x.demo)
		{
			this.newGameText.text = "Start Demo";
			this.versionTxt.text = "Demo Version " + Records.x.gameVersionDemo.ToString();
		}
		else
		{
			this.newGameText.text = "New Game";
			this.versionTxt.text = "Version " + Records.x.gameVersion.ToString();
		}
		if (Records.x.sitsNecholai != "")
		{
			this.importSerpentFiles.SetActive(false);
			this.serpentText.gameObject.SetActive(true);
			this.SetSerpentText();
		}
		else
		{
			this.importSerpentFiles.SetActive(true);
			this.serpentText.gameObject.SetActive(false);
		}
		this.UpdateSerpentNav();
		this.filesNotFound.SetActive(false);
		this.importDemotFiles.SetActive(false);
		this.demoFilesNotFound.SetActive(false);
		this.demoButton.gameObject.SetActive(false);
	}

	// Token: 0x06001228 RID: 4648 RVA: 0x001625DC File Offset: 0x001607DC
	public void StartSplash(string next)
	{
		this.animator.Play("MainMenuOut");
		if (Links.x.joy)
		{
			this.controllerText.spriteAsset = Links.x.GetSpriteSheetAsset(Links.x.gameplay.currentSpriteSheetAsset);
			int controllerSprite = Links.x.gameplay.GetControllerSprite("Action", Links.x.gameplay.controllerName);
			this.controllerText.text = "<voffset=.4em><size=40><sprite index=" + controllerSprite.ToString() + "></size></voffset>Continue";
		}
		else
		{
			this.controllerText.text = "Click to continue";
		}
		base.StartCoroutine(this.SplashScreen(next));
	}

	// Token: 0x06001229 RID: 4649 RVA: 0x0016268E File Offset: 0x0016088E
	private bool Clicked()
	{
		return (Links.x.mk && Input.GetMouseButtonUp(0)) || (Links.x.joy && Links.x.gameplay.actionStart);
	}

	// Token: 0x0600122A RID: 4650 RVA: 0x001626C4 File Offset: 0x001608C4
	private IEnumerator SplashScreen(string next)
	{
		if (!Records.x.demo)
		{
			Links.x.hudControl.JoyBox(false);
			this.group.alpha = 0f;
			this.group.interactable = true;
			float timeToLerp = 0.5f;
			float percentage = 0f;
			float startTime = Time.realtimeSinceStartup;
			while (percentage < 1f)
			{
				percentage = (Time.realtimeSinceStartup - startTime) / timeToLerp;
				this.group.alpha = percentage;
				yield return null;
			}
			Links.x.hudControl.JoyBox(false);
			while (!this.Clicked())
			{
				yield return null;
			}
			Links.x.gaia.FadeOutPlaylist(true, 0.25f);
			Links.x.gaia.FadeOutPlaylist(false, 0.25f);
			timeToLerp = 0.5f;
			percentage = 0f;
			startTime = Time.realtimeSinceStartup;
			while (percentage < 1f)
			{
				percentage = (Time.realtimeSinceStartup - startTime) / timeToLerp;
				this.group.alpha = 1f - percentage;
				yield return null;
			}
			Links.x.hudControl.JoyBox(false);
		}
		if (next == "New Game")
		{
			Links.x.gaia.NewGameFromMainMenu();
		}
		else
		{
			Links.x.gaia.LoadFromGameFiles();
		}
		yield break;
	}

	// Token: 0x0600122B RID: 4651 RVA: 0x001626DC File Offset: 0x001608DC
	public void UpdateSerpentNav()
	{
		if (this.importSerpentFiles.activeSelf)
		{
			Navigation navigation = this.quitButton.navigation;
			navigation.selectOnDown = this.serpentButton;
			this.quitButton.navigation = navigation;
		}
		else
		{
			Navigation navigation2 = this.quitButton.navigation;
			if (Records.x.demo)
			{
				navigation2.selectOnDown = null;
			}
			else
			{
				navigation2.selectOnDown = this.demoButton;
			}
			navigation2.selectOnDown = null;
			this.quitButton.navigation = navigation2;
		}
		if (Records.x.demo)
		{
			Navigation navigation3 = this.serpentButton.navigation;
			navigation3.selectOnDown = null;
			this.serpentButton.navigation = navigation3;
			return;
		}
		Navigation navigation4 = this.serpentButton.navigation;
		navigation4.selectOnDown = this.demoButton;
		navigation4.selectOnDown = null;
		this.serpentButton.navigation = navigation4;
	}

	// Token: 0x0600122C RID: 4652 RVA: 0x001627BA File Offset: 0x001609BA
	public void Quit()
	{
		Links.x.hudControl.JoyBox(false);
		Application.Quit();
	}

	// Token: 0x0600122D RID: 4653 RVA: 0x001627D4 File Offset: 0x001609D4
	public void Options()
	{
		Links.x.hudControl.JoyBox(false);
		Links.x.options.OpenMenu();
		if (Links.x.joy)
		{
			Links.x.hudControl.OpenMenuSwitcher("Options");
		}
	}

	// Token: 0x0600122E RID: 4654 RVA: 0x00162820 File Offset: 0x00160A20
	public void NewGame()
	{
		Links.x.hudControl.JoyBox(false);
		this.StartSplash("New Game");
	}

	// Token: 0x0600122F RID: 4655 RVA: 0x00162840 File Offset: 0x00160A40
	public void LoadGame()
	{
		Links.x.hudControl.JoyBox(false);
		Links.x.saveLoad.OpenMenuLoad(false);
		if (Links.x.joy)
		{
			Links.x.hudControl.OpenMenuSwitcher("Options");
		}
	}

	// Token: 0x06001230 RID: 4656 RVA: 0x0016288D File Offset: 0x00160A8D
	public void ShowCredits()
	{
		this.animator.Play("MainMenuCreditsOpen");
		this.creditCloseButton.CheckController(Links.x.joy);
	}

	// Token: 0x06001231 RID: 4657 RVA: 0x001628B4 File Offset: 0x00160AB4
	public void CloseCredits()
	{
		this.animator.Play("MainMenuCreditsClose");
		if (Links.x.joy)
		{
			Links.x.gameplay.SetInteractableSelected(EventSystem.current, this.creditsButton.gameObject);
		}
	}

	// Token: 0x06001232 RID: 4658 RVA: 0x001628F4 File Offset: 0x00160AF4
	public void FindDemoFiles()
	{
		if (!Records.x.FindDemoFiles())
		{
			this.demoFilesNotFound.SetActive(true);
			this.demoText.gameObject.SetActive(false);
		}
		else
		{
			this.demoFilesNotFound.SetActive(false);
			this.demoText.gameObject.SetActive(true);
		}
		this.UpdateSerpentNav();
	}

	// Token: 0x06001233 RID: 4659 RVA: 0x00162950 File Offset: 0x00160B50
	public void FindSerpentFiles()
	{
		if (!Records.x.FindSerpentFiles())
		{
			this.filesNotFound.SetActive(true);
			this.serpentText.gameObject.SetActive(false);
		}
		else
		{
			this.filesNotFound.SetActive(false);
			this.serpentText.gameObject.SetActive(true);
			this.importSerpentFiles.SetActive(false);
			this.SetSerpentText();
			if (Links.x.joy)
			{
				EventSystem.current.SetSelectedGameObject(this.quitButton.gameObject);
			}
		}
		this.UpdateSerpentNav();
	}

	// Token: 0x06001234 RID: 4660 RVA: 0x001629DE File Offset: 0x00160BDE
	private void SetSerpentText()
	{
		this.serpentText.text = "Serpent in the Staglands files imported. " + Records.x.sitsNecholai + ", welcome back to Vol!";
	}

	// Token: 0x06001235 RID: 4661 RVA: 0x00162A04 File Offset: 0x00160C04
	private void OnDestroy()
	{
		if (this.rt != null)
		{
			this.rt.Release();
		}
	}

	// Token: 0x06001236 RID: 4662 RVA: 0x00162A20 File Offset: 0x00160C20
	private void Awake()
	{
		Links.x.mainMenu = this;
		Time.timeScale = 1f;
		this.loopVideo.enabled = false;
		this.startVideo.enabled = false;
		this.animator.Play("MainMenuOff");
		this.coroutineStart = this.VideoStart();
		base.StartCoroutine(this.coroutineStart);
	}

	// Token: 0x06001237 RID: 4663 RVA: 0x00162A83 File Offset: 0x00160C83
	private IEnumerator VideoStart()
	{
		yield return new WaitForEndOfFrame();
		if (this.rt != null)
		{
			this.rt.Release();
		}
		RenderTextureFormat renderTextureFormat = RenderTextureFormat.ARGB32;
		this.rt = new RenderTexture(3840, 2160, 24, renderTextureFormat);
		this.startVideo.targetTexture = this.rt;
		this.loopVideo.targetTexture = this.rt;
		this.videoImg.texture = this.rt;
		RenderTexture active = RenderTexture.active;
		RenderTexture.active = this.rt;
		GL.Clear(true, true, Color.black);
		RenderTexture.active = active;
		if (Links.x.saveKeeper.loadInGame)
		{
			yield return new WaitForSecondsRealtime(0.1f);
		}
		else if (Application.platform == RuntimePlatform.OSXPlayer)
		{
			yield return new WaitForSeconds(1f);
		}
		else if (!Records.x.editor)
		{
			yield return new WaitForSeconds(1f);
		}
		this.rt.Release();
		renderTextureFormat = RenderTextureFormat.ARGB32;
		this.rt = new RenderTexture(3840, 2160, 24, renderTextureFormat);
		RenderTexture active2 = RenderTexture.active;
		RenderTexture.active = this.rt;
		GL.Clear(true, true, Color.black);
		RenderTexture.active = active2;
		if (Records.x.linux)
		{
			this.startVideo.clip = this.mmVideoStartLinux;
			this.loopVideo.clip = this.mmVideoLoopLinux;
		}
		else if (!Records.x.linux && (Records.x.windows7 || Records.x.alwaysPlayTranscodedVideo))
		{
			this.startVideo.clip = this.mmVideoStartWindows7;
			this.loopVideo.clip = this.mmVideoLoopWindows7;
		}
		else
		{
			this.startVideo.clip = this.mmVideoStart;
			this.loopVideo.clip = this.mmVideoLoop;
		}
		this.startVideo.targetTexture = this.rt;
		this.loopVideo.targetTexture = this.rt;
		this.videoImg.texture = this.rt;
		this.startVideo.SetDirectAudioVolume(0, Links.x.options.musicVolume);
		this.loopVideo.SetDirectAudioVolume(0, Links.x.options.musicVolume);
		if (Links.x.fadeAnimator.GetCurrentAnimatorStateInfo(0).IsName("FadeOut") || Links.x.fadeAnimator.GetCurrentAnimatorStateInfo(0).IsName("FadeOutLoop"))
		{
			Links.x.gaia.PlayFade("In", "Scaled");
		}
		yield return new WaitForSeconds(0.5f);
		Links.x.gaia.SetPlaylist("Waltz", true, 0f);
		this.startVideo.enabled = true;
		this.startVideo.started += this.VideoStarted;
		this.startVideo.loopPointReached += this.EndReached;
		this.videoImg.enabled = true;
		yield break;
	}

	// Token: 0x06001238 RID: 4664 RVA: 0x00162A94 File Offset: 0x00160C94
	private void Update()
	{
		float num = this.rectTransformBlack.sizeDelta.x;
		float num2 = this.rectTransformBlack.sizeDelta.y;
		float num3 = (float)Screen.width / (float)Screen.height;
		float num4 = 1.7777778f;
		if (num3 != num4)
		{
			if (num3 > num4)
			{
				num = num2 * num4;
			}
			else
			{
				num2 = num / num4;
			}
		}
		this.rectTransform.sizeDelta = new Vector2(num, num2);
	}

	// Token: 0x06001239 RID: 4665 RVA: 0x00162AFB File Offset: 0x00160CFB
	public void VideoStarted(VideoPlayer vp)
	{
		base.StartCoroutine(this.VideoStarting());
	}

	// Token: 0x0600123A RID: 4666 RVA: 0x00162B0A File Offset: 0x00160D0A
	private IEnumerator VideoStarting()
	{
		float startTime = Time.timeSinceLevelLoad;
		while (Time.timeSinceLevelLoad < startTime + 3f && !Input.GetMouseButtonUp(0))
		{
			yield return null;
		}
		this.animator.Play("MainMenu");
		if (Links.x.joy)
		{
			EventSystem.current.SetSelectedGameObject(this.newGameButton.gameObject);
		}
		yield break;
	}

	// Token: 0x0600123B RID: 4667 RVA: 0x00162B19 File Offset: 0x00160D19
	public void EndReached(VideoPlayer vp)
	{
		this.loopVideo.enabled = true;
		vp.enabled = false;
	}

	// Token: 0x04001DF8 RID: 7672
	public VideoPlayer startVideo;

	// Token: 0x04001DF9 RID: 7673
	public VideoPlayer loopVideo;

	// Token: 0x04001DFA RID: 7674
	public Canvas canvas;

	// Token: 0x04001DFB RID: 7675
	public VideoClip mmVideoStart;

	// Token: 0x04001DFC RID: 7676
	public VideoClip mmVideoStartLinux;

	// Token: 0x04001DFD RID: 7677
	public VideoClip mmVideoLoop;

	// Token: 0x04001DFE RID: 7678
	public VideoClip mmVideoLoopLinux;

	// Token: 0x04001DFF RID: 7679
	public VideoClip mmVideoStartWindows7;

	// Token: 0x04001E00 RID: 7680
	public VideoClip mmVideoLoopWindows7;

	// Token: 0x04001E01 RID: 7681
	public RawImage videoImg;

	// Token: 0x04001E02 RID: 7682
	public RectTransform rectTransform;

	// Token: 0x04001E03 RID: 7683
	public RectTransform rectTransformBlack;

	// Token: 0x04001E04 RID: 7684
	public TextMeshProUGUI versionTxt;

	// Token: 0x04001E05 RID: 7685
	private IEnumerator coroutineStart;

	// Token: 0x04001E06 RID: 7686
	public Animator animator;

	// Token: 0x04001E07 RID: 7687
	public TextMeshProUGUI newGameText;

	// Token: 0x04001E08 RID: 7688
	public TextMeshProUGUI serpentText;

	// Token: 0x04001E09 RID: 7689
	public TextMeshProUGUI demoText;

	// Token: 0x04001E0A RID: 7690
	public GameObject importSerpentFiles;

	// Token: 0x04001E0B RID: 7691
	public GameObject filesNotFound;

	// Token: 0x04001E0C RID: 7692
	public GameObject importDemotFiles;

	// Token: 0x04001E0D RID: 7693
	public GameObject demoFilesNotFound;

	// Token: 0x04001E0E RID: 7694
	public AnimateButton creditCloseButton;

	// Token: 0x04001E0F RID: 7695
	public Button creditsButton;

	// Token: 0x04001E10 RID: 7696
	public Button serpentButton;

	// Token: 0x04001E11 RID: 7697
	public Button demoButton;

	// Token: 0x04001E12 RID: 7698
	public Button quitButton;

	// Token: 0x04001E13 RID: 7699
	public Button newGameButton;

	// Token: 0x04001E14 RID: 7700
	public GameObject splash;

	// Token: 0x04001E15 RID: 7701
	public CanvasGroup group;

	// Token: 0x04001E16 RID: 7702
	public TextMeshProUGUI controllerText;

	// Token: 0x04001E17 RID: 7703
	private RenderTexture rt;
}
