using System;
using System.Collections;
using System.Linq;
using UnityEngine;

public class BenchResult : Result_Display
{
	private void Awake()
	{
		base.Initialize();
		this.m_ButtonUI.SetActive(true);
		GameMain.Instance.BgMgr.ChangeBg("LiveStage");
		this.m_LoopModeFlag = BenchSetting.Setting.IsLoopMode;
		bool flag = false;
		this.m_OSLabel.text = SystemInfo.operatingSystem;
		this.m_CPULabel.text = string.Concat(new object[]
		{
			SystemInfo.processorType,
			" : ",
			SystemInfo.processorCount,
			"Core"
		});
		this.m_MemoryLabel.text = SystemInfo.systemMemorySize + " MB System Memory ";
		this.m_GraphicsLabel.text = string.Concat(new object[]
		{
			SystemInfo.graphicsDeviceName,
			" : ",
			SystemInfo.graphicsMemorySize,
			"MB : ",
			SystemInfo.graphicsDeviceType
		});
		string text = "benchmark_setting.nei";
		if (!GameUty.FileSystem.IsExistentFile(text))
		{
			NDebug.Assert("表がありません。" + text, false);
		}
		using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
		{
			using (CsvParser csvParser = new CsvParser())
			{
				bool condition = csvParser.Open(afileBase);
				NDebug.Assert(condition, text + "\nopen failed.");
				for (int i = 1; i < csvParser.max_cell_y; i++)
				{
					this.m_BenchNotation[i - 1].BenchScore = csvParser.GetCellAsInteger(1, i);
				}
			}
		}
		foreach (BenchResult.BenchParam benchParam in this.m_BenchNotation)
		{
			benchParam.ScoreImage.SetActive(true);
			if (benchParam.BenchScore > BenchMarkScore.BenchScore || flag)
			{
				benchParam.ScoreImage.SetActive(false);
			}
			else
			{
				flag = true;
			}
		}
		this.m_FPSLabel.gameObject.SetActive(Application.targetFrameRate != 60);
		this.m_FPSLabel.text = "TargetFPS：";
		UILabel fpslabel = this.m_FPSLabel;
		fpslabel.text += ((Application.targetFrameRate > 0) ? Application.targetFrameRate.ToString() : "No limit");
		if (!flag)
		{
			this.m_BenchNotation.Last<BenchResult.BenchParam>().ScoreImage.SetActive(true);
		}
		this.m_LoopSupplement.SetActive(this.m_LoopModeFlag);
		if (this.m_LoopModeFlag)
		{
			base.StartCoroutine(this.LoopWait());
		}
	}

	private IEnumerator LoopWait()
	{
		while (this.m_LoopModeFlag)
		{
			if (!BaseMgr<ConfigMgr>.Instance.IsOpenConfigPanel())
			{
				this.m_WaitTimer += Time.deltaTime;
			}
			this.m_NextLoopLabel.text = string.Format("次のループまであと:{0}秒", Mathf.Max(this.m_NextLoopWait - Mathf.Floor(this.m_WaitTimer), 0f));
			if (this.m_WaitTimer >= this.m_NextLoopWait)
			{
				this.m_EndLabel = this.m_LoopLabel;
				base.StartCoroutine(base.FadeOut());
				yield break;
			}
			yield return null;
		}
		yield break;
		yield break;
	}

	private void FadeEnd()
	{
		BenchSetting.SettingApplay();
		DanceSelect.BenchMarkInit();
		ShootCutInTex.SetEnemyCutInTex(false);
		ShootCutInTex.SetPlayerCutInTex();
		base.ResultEnd();
	}

	public override void ClickButton()
	{
		if (this.m_LoopModeFlag)
		{
			if (this.m_WaitTimer >= this.m_NextLoopWait)
			{
				return;
			}
			this.m_LoopModeFlag = false;
			BenchSetting.SettingRecet();
		}
		base.ClickButton();
	}

	protected override void ResultEnd()
	{
		if (this.m_LoopModeFlag)
		{
			GameMain.Instance.MainCamera.FadeOut(0.5f, false, new CameraMain.dgOnCompleteFade(this.FadeEnd), false, default(Color));
		}
		else
		{
			base.ResultEnd();
		}
	}

	protected override void Update()
	{
		base.Update();
	}

	protected override void UIInit(Transform child)
	{
	}

	[SerializeField]
	[Header("システム情報")]
	private UILabel m_OSLabel;

	[SerializeField]
	private UILabel m_CPULabel;

	[SerializeField]
	private UILabel m_MemoryLabel;

	[SerializeField]
	private UILabel m_GraphicsLabel;

	[SerializeField]
	[Header("各評価の表記")]
	private BenchResult.BenchParam[] m_BenchNotation;

	[SerializeField]
	[Header("次のループに行くまでの待機時間")]
	private float m_NextLoopWait = 10f;

	[SerializeField]
	private GameObject m_LoopSupplement;

	[SerializeField]
	private UILabel m_NextLoopLabel;

	private float m_WaitTimer;

	[SerializeField]
	[Header("ループモード時に飛ぶラベル")]
	private string m_LoopLabel = "*ダンススタート";

	[SerializeField]
	private UILabel m_FPSLabel;

	private bool m_LoopModeFlag;

	private enum BenchEvalue
	{
		VeryComfort,
		Comfort,
		Normal,
		Strict,
		VeryStrict
	}

	[Serializable]
	private class BenchParam
	{
		public BenchResult.BenchEvalue Evalue;

		public GameObject ScoreImage;

		[HideInInspector]
		public int BenchScore;
	}
}
