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

[RequireComponent(typeof(UIPanel))]
public class VRYotogiOldSelectMenu : WfFadeBehaviour
{
	public Maid maid { get; set; }

	public static VRYotogiOldSelectMenu Createprefab(GameObject parent)
	{
		return Utility.CreatePrefab(parent, "SceneYotogi/Yotogi/Prefab/Old/VR YotogiSelectMenu", true).GetComponentInChildren<VRYotogiOldSelectMenu>();
	}

	public void Awake()
	{
		this.bgSprite.alpha = 0f;
		this.bgSprite.width = 1550;
		this.bgSprite.height = 850;
		this.yotogiPlay = false;
		this.panel = base.GetComponent<UIPanel>();
		this.cblConfig.gameObject.SetActive(false);
	}

	public void Call()
	{
		this.yotogiPlay = false;
		this.stageSelectMgr.onClickEnterEvent.Clear();
		EventDelegate.Add(this.stageSelectMgr.onClickEnterEvent, new EventDelegate.Callback(this.OnEnterStageSelect));
		this.stageSelectMgr.visibledCancelBtn = false;
		this.skillSelectMgr.SetCancelButtonText("Cancel");
		this.skillSelectMgr.OnUpdateFadeOut(0f);
		WfFadeJob.Create(this.stageSelectMgr, null, this.fadeTime, iTween.EaseType.easeOutSine);
	}

	public void CallFromYotogiScene(YotogiOld.StageData stageData, int spotNo, YotogiOld.VRSkillData skill)
	{
		float num = this.fadeTime;
		this.fadeTime = 0f;
		this.Call();
		this.yotogiPlay = true;
		this.stageSelectMgr.SetStageData(stageData.stage, spotNo);
		this.skillSelectMgr.selectedSkill = skill;
		this.skillSelectMgr.SetCancelButtonText("End");
		this.OnEnterStageSelect();
		this.fadeTime = num;
		this.skillSelectMgr.SelectCategory(skill.skill.category.ToString());
	}

	public void CallCBLConfig()
	{
		this.callVRConfig = false;
		WfFadeJob.Create(this.cblConfig, this, this.fadeTime, iTween.EaseType.easeOutSine);
	}

	public void CallVRConfig()
	{
		this.callVRConfig = true;
		WfFadeJob.Create(null, this, this.fadeTime, iTween.EaseType.easeOutSine);
	}

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

	private void OnEnterStageSelect()
	{
		this.stageSelectMgr.visibledCancelBtn = true;
		this.stageSelectMgr.onClickCancelEvent.Clear();
		EventDelegate.Add(this.stageSelectMgr.onClickCancelEvent, new EventDelegate.Callback(this.OnCancelStageSelect));
		this.skillSelectMgr.onClickStageSelect.Clear();
		EventDelegate.Add(this.skillSelectMgr.onClickStageSelect, new EventDelegate.Callback(this.OnClickStageSelect));
		this.skillSelectMgr.onClickCancelEvent.Clear();
		EventDelegate.Add(this.skillSelectMgr.onClickCancelEvent, new EventDelegate.Callback(this.onClickEnd));
		this.skillSelectMgr.onClickEnterEvent.Clear();
		EventDelegate.Add(this.skillSelectMgr.onClickEnterEvent, new EventDelegate.Callback(this.OnEnterSkill));
		this.skillSelectMgr.UpdateData(GameMain.Instance.CharacterMgr.GetMaid(0), this.stageSelectMgr.selectStageData.stage, this.stageSelectMgr.selectSpotNo);
		WfFadeJob.Create(this.skillSelectMgr, this.stageSelectMgr, this.fadeTime, iTween.EaseType.easeOutSine);
	}

	private void OnEnterSkill()
	{
		YotogiOldManager.select_vr_stage_data = this.stageSelectMgr.selectStageData;
		YotogiOldManager.select_vr_stage_spot_no = this.stageSelectMgr.selectSpotNo;
		YotogiOldManager.select_vr_skill_data = this.skillSelectMgr.selectedSkill;
		YotogiOldStageSelectManager.SelectStage(YotogiOldManager.select_vr_stage_data);
		YotogiOldStageSelectManager.StagePrefab = ((!GameMain.Instance.CharacterMgr.status.isDaytime) ? YotogiOldManager.select_vr_stage_data.prefab_name_night : YotogiOldManager.select_vr_stage_data.prefab_name);
		int flag = GameMain.Instance.CharacterMgr.status.GetFlag("時間帯");
		Dictionary<YotogiOld.Stage, string> dictionary = new Dictionary<YotogiOld.Stage, string>();
		if (flag == 1)
		{
			dictionary = new Dictionary<YotogiOld.Stage, string>
			{
				{
					YotogiOld.Stage.海,
					"BGM014"
				},
				{
					YotogiOld.Stage.畑,
					"BGM_vr0006"
				},
				{
					YotogiOld.Stage.ヴィラ,
					"BGM_vr0006"
				},
				{
					YotogiOld.Stage.ベットル\u30FCム,
					"BGM_vr0006"
				},
				{
					YotogiOld.Stage.露天風呂,
					"BGM006"
				}
			};
		}
		else if (flag == 2)
		{
			dictionary = new Dictionary<YotogiOld.Stage, string>
			{
				{
					YotogiOld.Stage.海,
					"BGM014"
				},
				{
					YotogiOld.Stage.畑,
					"BGM014"
				},
				{
					YotogiOld.Stage.ヴィラ,
					"BGM013"
				},
				{
					YotogiOld.Stage.ベットル\u30FCム,
					"BGM013"
				},
				{
					YotogiOld.Stage.露天風呂,
					"BGM011"
				}
			};
		}
		else if (flag == 3)
		{
			dictionary = new Dictionary<YotogiOld.Stage, string>
			{
				{
					YotogiOld.Stage.海,
					"BGM_vr0002"
				},
				{
					YotogiOld.Stage.畑,
					"BGM_vr0001"
				},
				{
					YotogiOld.Stage.ヴィラ,
					"BGM013"
				},
				{
					YotogiOld.Stage.ベットル\u30FCム,
					"BGM013"
				},
				{
					YotogiOld.Stage.露天風呂,
					"BGM011"
				}
			};
		}
		if (dictionary.ContainsKey(YotogiOldManager.select_vr_stage_data.stage))
		{
			GameMain.Instance.SoundMgr.PlayBGM(dictionary[YotogiOldManager.select_vr_stage_data.stage] + ".ogg", 0.3f, true);
		}
		if (this.onEnterSkillEvent != null)
		{
			this.onEnterSkillEvent(this.stageSelectMgr.selectStageData, this.stageSelectMgr.selectSpotNo, this.skillSelectMgr.selectedSkill);
		}
	}

	private void OnClickStageSelect()
	{
		WfFadeJob.Create(this.stageSelectMgr, this.skillSelectMgr, this.fadeTime, iTween.EaseType.easeOutSine);
	}

	private void OnCancelStageSelect()
	{
		WfFadeJob.Create(this.skillSelectMgr, this.stageSelectMgr, this.fadeTime, iTween.EaseType.easeOutSine);
	}

	private void onClickEnd()
	{
		if (!this.yotogiPlay)
		{
			this.Call();
		}
		if (this.onCancelEvent != null)
		{
			this.onCancelEvent();
		}
	}

	public override void OnStartedFadeOut()
	{
		this.uiMask.enabled = true;
	}

	public override void OnCompleteFadeIn()
	{
		this.uiMask.enabled = false;
	}

	public override void OnCompleteFadeOut()
	{
		if (this.callVRConfig)
		{
			this.callVRConfig = false;
			VRCanvasManager instance = VRCanvasManager.Instance;
			if (instance != null)
			{
				this.uiMask.enabled = false;
				instance.OpenVRConfig(delegate
				{
					this.uiMask.enabled = true;
					WfFadeJob.Create(this, null, this.fadeTime, iTween.EaseType.easeOutSine);
				});
			}
			else
			{
				WfFadeJob.Create(this, null, this.fadeTime, iTween.EaseType.easeOutSine);
			}
		}
	}

	public override void OnUpdateFadeIn(float val)
	{
		this.panel.alpha = val;
	}

	public override void OnUpdateFadeOut(float val)
	{
		this.panel.alpha = val;
	}

	[SerializeField]
	public YotogiOldVRStageSelectManager stageSelectMgr;

	[SerializeField]
	public YotogiOldVRSkillSelectManager skillSelectMgr;

	[SerializeField]
	private UISprite bgSprite;

	[SerializeField]
	private UIWFHitMasks uiMask;

	[SerializeField]
	private VRChuBLipMenu cblConfig;

	[SerializeField]
	public float fadeTime = 0.3f;

	public VRYotogiOldSelectMenu.EventOnEnterSkill onEnterSkillEvent;

	public Action onCancelEvent;

	public bool yotogiPlay;

	private UIPanel panel;

	private bool callVRConfig;

	public delegate void EventOnEnterSkill(YotogiOld.StageData stageData, int spotNo, YotogiOld.VRSkillData skill);
}
