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

public class YotogiStageSelectManager : WfScreenChildren
{
	public override void Awake()
	{
		base.Awake();
		this.yotogi_mgr_ = base.GetComponentInParent<YotogiManager>();
		this.scroll_view_ = UTY.GetChildObject(base.root_obj, "StageSelectViewer/StageViewer/Contents", false).GetComponent<UIScrollView>();
	}

	protected override void OnCall()
	{
		if (!this.yotogi_mgr_.is_new_yotogi_mode)
		{
			uGUITutorialPanel.OpenTutorial("YotogiStageSelect", null, false);
		}
		if (!this.yotogi_mgr_.is_new_yotogi_mode)
		{
			GameMain.Instance.SysShortcut.strSceneHelpName = "YotogiStageSelect";
		}
		this.fix_stage_ = false;
		this.maid_ = this.yotogi_mgr_.maid;
		this.maid_.Visible = true;
		this.maid_.AllProcPropSeqStart();
		GameMain.Instance.MainLight.Reset();
		GameMain.Instance.CharacterMgr.ResetCharaPosAll();
		GameMain.Instance.CharacterMgr.DeactivateManAll();
		GameMain.Instance.MainCamera.Reset(CameraMain.CameraType.Target, true);
		GameMain.Instance.SoundMgr.VoiceStopAll();
		GameObject childObject = UTY.GetChildObject(base.root_obj, "StageSelectViewer/StageViewer/Contents/StageUnitParent", false);
		Transform transform = childObject.transform;
		for (int i = 0; i < transform.childCount; i++)
		{
			UnityEngine.Object.Destroy(transform.GetChild(i).gameObject);
		}
		transform.DetachChildren();
		bool isDaytime = GameMain.Instance.CharacterMgr.status.isDaytime;
		int clubGrade = GameMain.Instance.CharacterMgr.status.clubGrade;
		base.SetFadeTime(0.5f);
		UIButton component = UTY.GetChildObject(base.root_obj, "Ok", false).GetComponent<UIButton>();
		component.onClick.Clear();
		EventDelegate.Add(component.onClick, new EventDelegate.Callback(this.OnClickOK));
		string path = string.Empty;
		path = "SceneYotogi/StageSelect/Prefab/StageUnit";
		List<YotogiStage.Data> allDatas = YotogiStage.GetAllDatas(true);
		allDatas.Sort();
		YotogiStageUnit yotogiStageUnit = null;
		for (int j = 0; j < allDatas.Count; j++)
		{
			GameObject gameObject = Utility.CreatePrefab(childObject, path, true);
			YotogiStageUnit component2 = gameObject.GetComponent<YotogiStageUnit>();
			component2.SetStageData(allDatas[j], allDatas[j].isYotogiPlayable(clubGrade, true), isDaytime);
			component2.SetOnSelectEvent(new YotogiStageUnit.OnSelectEvent(this.OnSelectEvent));
			if (yotogiStageUnit == null)
			{
				yotogiStageUnit = gameObject.GetComponent<YotogiStageUnit>();
			}
		}
		childObject.GetComponent<UIGrid>().Reposition();
		this.scroll_view_.ResetPosition();
		childObject.GetComponent<UIWFTabPanel>().UpdateChildren();
		if (yotogiStageUnit != null)
		{
			childObject.GetComponent<UIWFTabPanel>().Select(yotogiStageUnit.button);
		}
	}

	protected override bool IsCallFadeIn()
	{
		if (this.maid_.IsBusy)
		{
			return false;
		}
		this.maid_.FaceAnime("通常", 0f, 0);
		this.maid_.FaceBlend("無し");
		this.maid_.Visible = false;
		if (this.yotogi_mgr_.is_new_yotogi_mode)
		{
			base.SetFadeStatus(WfScreenChildren.FadeStatus.Wait);
			float fade_time = base.fade_time;
			base.SetFadeTime(0f);
			this.Finish();
			base.SetFadeTime(fade_time);
			return false;
		}
		return true;
	}

	public static void SelectStage(YotogiStage.Data data, bool isDayTime)
	{
		if (YotogiStage.IsEnabled(data.id))
		{
			YotogiStageSelectManager.SelectedStage = data;
			YotogiStageSelectManager.SelectedStageRefDayTime = isDayTime;
		}
	}

	private void OnSelectEvent(YotogiStageUnit click_unit)
	{
		YotogiStage.Data stage_data = click_unit.stage_data;
		YotogiStageSelectManager.SelectStage(stage_data, GameMain.Instance.CharacterMgr.status.isDaytime);
		stage_data.stageSelectCameraData.Apply();
		GameMain.Instance.SoundMgr.PlayBGM(stage_data.bgmFileName, 1f, true);
	}

	private void OnClickOK()
	{
		if (this.yotogi_mgr_.null_mgr.IsExistNextLabel())
		{
			this.Finish();
		}
	}

	protected override void OnFinish()
	{
		base.OnFinish();
		this.maid_.Visible = true;
		if (this.yotogi_mgr_.null_mgr.IsExistNextLabel())
		{
			this.yotogi_mgr_.CallScreen(YotogiManager.CallScreenType.Null.ToString());
		}
	}

	public override void Update()
	{
		base.Update();
		if (this.fix_stage_ && base.fade_status == WfScreenChildren.FadeStatus.Wait)
		{
			this.Finish();
		}
	}

	protected override void FadeIn()
	{
		base.FadeIn();
		if (this.fix_stage_ && base.fade_status == WfScreenChildren.FadeStatus.Wait)
		{
			this.Finish();
		}
	}

	public static YotogiStage.Data SelectedStage;

	public static bool SelectedStageRefDayTime;

	private Maid maid_;

	private YotogiManager yotogi_mgr_;

	private UIScrollView scroll_view_;

	private bool fix_stage_;
}