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

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

	protected override void OnCall()
	{
		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.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();
		if (this.maid_.status.OldStatus.condition == Condition.Osioki)
		{
			base.SetFadeTime(0f);
			this.fix_stage_ = true;
			base.root_obj.SetActive(false);
			YotogiOldStageSelectManager.SelectStage(YotogiOld.stage_data_list[YotogiOld.Stage.ＳＭル\u30FCム]);
		}
		else
		{
			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;
			List<KeyValuePair<YotogiOld.StageData, bool>> playableStageList = YotogiOld.GetPlayableStageList(99, null);
			path = "SceneYotogi/StageSelect/Prefab/Old/StageUnit";
			YotogiOldStageUnit yotogiOldStageUnit = null;
			for (int j = 0; j < playableStageList.Count; j++)
			{
				GameObject gameObject = Utility.CreatePrefab(childObject, path, true);
				YotogiOldStageUnit component2 = gameObject.GetComponent<YotogiOldStageUnit>();
				component2.SetStageData(playableStageList[j].Key, playableStageList[j].Value);
				component2.SetOnSelectEvent(new YotogiOldStageUnit.OnSelectEvent(this.OnSelectEvent));
				if (yotogiOldStageUnit == null)
				{
					yotogiOldStageUnit = gameObject.GetComponent<YotogiOldStageUnit>();
				}
			}
			childObject.GetComponent<UIGrid>().Reposition();
			this.scroll_view_.ResetPosition();
			childObject.GetComponent<UIWFTabPanel>().UpdateChildren();
			if (yotogiOldStageUnit != null)
			{
				childObject.GetComponent<UIWFTabPanel>().Select(yotogiOldStageUnit.button);
			}
		}
	}

	protected override bool IsCallFadeIn()
	{
		if (this.maid_.IsBusy)
		{
			return false;
		}
		this.maid_.FaceAnime("通常", 0f, 0);
		this.maid_.FaceBlend("無し");
		this.maid_.Visible = false;
		return true;
	}

	public static void SelectStage(YotogiOld.StageData data)
	{
		YotogiOldStageSelectManager.StageName = data.stage_name;
		YotogiOldStageSelectManager.StagePrefab = data.prefab_name;
	}

	private void OnSelectEvent(YotogiOldStageUnit click_unit)
	{
		YotogiOld.StageData stage_data = click_unit.stage_data;
		YotogiOldStageSelectManager.SelectStage(stage_data);
		GameMain.Instance.MainCamera.SetFromScriptOnTarget(stage_data.camera_data.stage_select_camera_center, stage_data.camera_data.stage_select_camera_radius, stage_data.camera_data.stage_select_camera_rotate);
		GameMain.Instance.SoundMgr.PlayBGM(click_unit.stage_data.bgm_file, 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(YotogiOldManager.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 string StageName = string.Empty;

	public static string StagePrefab = string.Empty;

	private Maid maid_;

	private YotogiOldManager yotogi_mgr_;

	private UIScrollView scroll_view_;

	private bool fix_stage_;
}
