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

public class VRMainMenu : MonoBehaviour, InterfaceVRCanvas
{
	private void Awake()
	{
		this.m_ButtonArray.Add(VRMainMenu.ButtonType.Edit, this.m_ButtonEdit);
		this.m_ButtonArray.Add(VRMainMenu.ButtonType.Yotogi, this.m_ButtonYotogi);
		this.m_ButtonArray.Add(VRMainMenu.ButtonType.Nei, this.m_ButtonNei);
		this.m_ButtonArray.Add(VRMainMenu.ButtonType.ChangeBG, this.m_ButtonChangeBG);
		this.m_ButtonArray.Add(VRMainMenu.ButtonType.Time, this.m_ButtonTime);
		this.m_ButtonArray.Add(VRMainMenu.ButtonType.Config, this.m_ButtonConfig);
		this.m_ButtonArray.Add(VRMainMenu.ButtonType.VRConfig, this.m_ButtonVRConfig);
		this.m_ButtonArray.Add(VRMainMenu.ButtonType.Trohy, this.m_ButtonTrohy);
		this.m_ButtonArray.Add(VRMainMenu.ButtonType.Manual, this.m_ButtonManual);
		this.m_ButtonArray.Add(VRMainMenu.ButtonType.EndButton, this.m_ButtonEnd);
		this.m_ButtonArray.Add(VRMainMenu.ButtonType.Skip, this.m_ButtonSkip);
	}

	private void Start()
	{
		this.MainMenuUpdate();
	}

	public void Event_SetButtonEnabled(VRMainMenu.ButtonType type, bool flag)
	{
		if (!this.m_ButtonArray.ContainsKey(type))
		{
			return;
		}
		Button button = this.m_ButtonArray[type];
		if (button == null)
		{
			return;
		}
		button.interactable = flag;
	}

	public void Event_SetButtonActive(VRMainMenu.ButtonType type, bool flag)
	{
		if (!this.m_ButtonArray.ContainsKey(type))
		{
			return;
		}
		Button button = this.m_ButtonArray[type];
		if (button == null)
		{
			return;
		}
		button.gameObject.SetActive(flag);
	}

	public void ButtonEvent_OpenDialogEndVacation()
	{
		VRDialogMenu dialogMenu = VRDialogMenu.CreateDialog();
		VRDialogMenu.TYPE_STYLE style = (VRDialogMenu.TYPE_STYLE)12;
		dialogMenu.OpenDialog("本当にバカンスを終了する？", style, delegate(VRDialogMenu.TYPE_STYLE buttonType)
		{
			dialogMenu.CloseDialog();
			if (buttonType == VRDialogMenu.TYPE_STYLE.OK)
			{
				VRExternalFileLoader.Event_CloseMovie();
				SceneVRCommunication.Instance.OnEnd();
			}
		});
	}

	public void ButtonEvent_NextTime()
	{
		SceneVRCommunication sceneVRCom = SceneVRCommunication.Instance;
		if (sceneVRCom == null)
		{
			return;
		}
		VRExternalFileLoader.Event_CloseMovie();
		SceneVRCommunication.VR_TIME nowTime = sceneVRCom.GetNowTime();
		if (nowTime != SceneVRCommunication.VR_TIME.NIGHT)
		{
			sceneVRCom.KagDoNextTime();
		}
		else
		{
			VRSelectorMenu selector = VRSelectorMenu.CreateSelector();
			selector.SetSelectType(VRChoices.SelectPair.Type.Text);
			List<VRChoices.SelectPair> list = new List<VRChoices.SelectPair>();
			list.Add(new VRChoices.SelectPair("VIPへ進む", "0", 0, VRChoices.SelectPair.Type.Text, 0, -1f));
			list.Add(new VRChoices.SelectPair("翌日ヘ進む", "1", 0, VRChoices.SelectPair.Type.Text, 0, -1f));
			selector.SelectStart(list, delegate(VRChoices.SelectPair choice)
			{
				selector.SelectFinalize(null);
				if (choice.strLabel == "0")
				{
					VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.VIP);
				}
				else
				{
					VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
					sceneVRCom.KagDoNextTime();
				}
			});
		}
	}

	public void ButtonEvent_OpenConfig()
	{
		if (BaseMgr<ConfigMgr>.Instance != null)
		{
			BaseMgr<ConfigMgr>.Instance.OpenConfigPanel();
		}
	}

	public void ButtonEvent_OpenEdit()
	{
		VRDialogMenu dialog = VRDialogMenu.CreateDialog();
		VRDialogMenu.TYPE_STYLE style = (VRDialogMenu.TYPE_STYLE)12;
		dialog.OpenDialog("エディット画面を開きます。", style, delegate(VRDialogMenu.TYPE_STYLE type)
		{
			dialog.CloseDialog();
			if (type == VRDialogMenu.TYPE_STYLE.OK)
			{
				VRExternalFileLoader.Event_CloseMovie();
				SceneVRCommunication.Instance.MaidEditStart();
			}
			else
			{
				VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
			}
		});
	}

	public void ButtonEvent_OpenYotogi()
	{
		VRCanvasManager.Instance.IsYotogiSelecting = true;
		VRCanvasManager.Instance.CloseVRCanvas();
		VRCanvasManager.Instance.ClearCanvasStack();
		SceneVRCommunication.Instance.YotogiStart(delegate
		{
			VRExternalFileLoader.Event_CloseMovie();
			VRCanvasManager.Instance.IsYotogiSelecting = false;
		}, delegate
		{
			Canvas vrcanvas = VRCanvasManager.Instance.GetVRCanvas(VRCanvasManager.VRCanvasType.VRConfig);
			if (vrcanvas)
			{
				if (VRCanvasManager.Instance.m_CallbackCloseVRConfig != null)
				{
					VRCanvasManager.Instance.m_CallbackCloseVRConfig();
				}
				Transform transform = vrcanvas.transform.Find("Button return");
				Button component = transform.GetComponent<Button>();
				UICanvasFade component2 = vrcanvas.GetComponent<UICanvasFade>();
				component.onClick.RemoveAllListeners();
			}
			VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
			VRCanvasManager.Instance.IsYotogiSelecting = false;
		});
	}

	public void OnUpdateCanvas()
	{
		this.MainMenuUpdate();
	}

	private void MainMenuUpdate()
	{
		SceneVRCommunication instance = SceneVRCommunication.Instance;
		if (instance == null)
		{
			return;
		}
		Text componentInChildren = this.m_ButtonTime.GetComponentInChildren<Text>();
		if (componentInChildren != null)
		{
			SceneVRCommunication.VR_TIME nowTime = instance.GetNowTime();
			if (nowTime == SceneVRCommunication.VR_TIME.MONING)
			{
				componentInChildren.text = "昼へ進む";
			}
			else if (nowTime == SceneVRCommunication.VR_TIME.DAY)
			{
				componentInChildren.text = "夜へ進む";
			}
			else if (nowTime == SceneVRCommunication.VR_TIME.NIGHT)
			{
				componentInChildren.text = "翌日へ進む";
			}
			else
			{
				Debug.LogError("[VRMainMenu]ゲーム内の時間指定が分かりません");
			}
		}
		bool flag = false;
		if (GameMain.Instance.CharacterMgr.GetMaid(0) != null)
		{
			string text = "vrcom_nei_letter.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++)
					{
						string cellAsString = csvParser.GetCellAsString(2, i);
						if (GameMain.Instance.CharacterMgr.GetMaid(0).status.GetFlag(cellAsString) == 1)
						{
							flag = true;
							break;
						}
					}
				}
			}
		}
		this.Event_SetButtonEnabled(VRMainMenu.ButtonType.Nei, flag);
	}

	[SerializeField]
	[Tooltip("ボタン「エディット」")]
	private Button m_ButtonEdit;

	[SerializeField]
	[Tooltip("ボタン「夜伽」")]
	private Button m_ButtonYotogi;

	[SerializeField]
	[Tooltip("ボタン「ねい人形からの手紙」")]
	private Button m_ButtonNei;

	[SerializeField]
	[Tooltip("ボタン「背景移動」")]
	private Button m_ButtonChangeBG;

	[SerializeField]
	[Tooltip("ボタン「時間」")]
	private Button m_ButtonTime;

	[SerializeField]
	[Tooltip("ボタン「コンフィグ」")]
	private Button m_ButtonConfig;

	[SerializeField]
	[Tooltip("ボタン「VRコンフィグ」")]
	private Button m_ButtonVRConfig;

	[SerializeField]
	[Tooltip("ボタン「トロフィー」")]
	private Button m_ButtonTrohy;

	[SerializeField]
	[Tooltip("ボタン「マニュアル」")]
	private Button m_ButtonManual;

	[SerializeField]
	[Tooltip("ボタン「終了」")]
	private Button m_ButtonEnd;

	[SerializeField]
	[Tooltip("ボタン「SKIP」")]
	private Button m_ButtonSkip;

	private Dictionary<VRMainMenu.ButtonType, Button> m_ButtonArray = new Dictionary<VRMainMenu.ButtonType, Button>();

	public enum ButtonType
	{
		Edit,
		Yotogi,
		Nei,
		ChangeBG,
		Time,
		Config,
		VRConfig,
		Trohy,
		Manual,
		EndButton,
		Skip
	}
}
