using System;
using System.IO;
using UnityEngine;

public class FreeModeInit : WfScreenChildren
{
	public override void Awake()
	{
		base.Awake();
		base.SetFadeTime(0f);
	}

	protected override void OnCall()
	{
		this.mgr_ = (base.parent_mgr as SceneFreeModeSelectManager);
		NDebug.AssertNull(this.mgr_ != null);
		GameMain.Instance.ScriptMgr.ClearForcExecWaitEvent();
		GameMain.Instance.MsgWnd.CloseMessageWindowPanel();
		GameMain.Instance.MsgWnd.CancelSkipAndAuto();
		GameMain.Instance.BgMgr.DelPrefabFromBgAll();
		if (DailyMgr.IsLegacy)
		{
			GameMain.Instance.BgMgr.ChangeBg("Salon");
		}
		else
		{
			GameMain.Instance.BgMgr.ChangeBg("Theater");
		}
		GameMain.Instance.MainLight.Reset();
		GameMain.Instance.CharacterMgr.ResetCharaPosAll();
		GameMain.Instance.MainCamera.Reset(CameraMain.CameraType.Target, true);
		GameMain.Instance.SoundMgr.StopSe();
		GameMain.Instance.SoundMgr.VoiceStopAll();
		CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
		Maid man = characterMgr.GetMan(0);
		man.Visible = true;
		Maid maid = characterMgr.GetMaid(0);
		maid.Visible = true;
		string[] array = new string[]
		{
			"handitem",
			"kousoku_upper",
			"kousoku_lower",
			"skirt",
			"panz",
			"mizugi",
			"onepiece",
			"accanl",
			"accvag",
			"KubiScl",
			"UdeScl",
			"DouPer",
			"sintyou",
			"kata"
		};
		for (int i = 0; i < characterMgr.GetStockMaidCount(); i++)
		{
			Maid stockMaid = characterMgr.GetStockMaid(i);
			if (!(stockMaid == null))
			{
				stockMaid.ResetAll();
			}
		}
		for (int j = 0; j < characterMgr.GetStockManCount(); j++)
		{
			Maid stockMan = characterMgr.GetStockMan(j);
			if (!(stockMan == null))
			{
				stockMan.ResetAll();
			}
		}
		for (int k = 1; k < characterMgr.GetMaidCount(); k++)
		{
			characterMgr.DeactivateMaid(k);
		}
		if (maid != null)
		{
			string bgmFileName = maid.status.personal.bgmFileName;
			if (!string.IsNullOrEmpty(bgmFileName))
			{
				if (maid.status.isCompatiblePersonality)
				{
					GameMain.Instance.SoundMgr.PlayBGMLegacy(bgmFileName, 0.5f, true);
				}
				else
				{
					string text = (!maid.status.personal.oldPersonal) ? string.Empty : (Path.GetFileNameWithoutExtension(bgmFileName) + "_OLD.ogg");
					if (!string.IsNullOrEmpty(text) && GameUty.FileSystem.IsExistentFile(text))
					{
						GameMain.Instance.SoundMgr.PlayBGM(text, 0.5f, true);
					}
					else
					{
						GameMain.Instance.SoundMgr.PlayBGM(bgmFileName, 0.5f, true);
					}
				}
			}
			maid.Visible = false;
			maid.Visible = true;
			maid.FaceAnime("通常", 0f, 0);
			maid.FaceAnime("通常", 0.01f, 0);
			maid.FaceBlend("無し");
			maid.AllProcPropSeqStart();
		}
		man.AllProcPropSeqStart();
		GameMain.Instance.SysShortcut.strSceneHelpName = "SceneFreeModeSelect";
		uGUITutorialPanel.OpenTutorial("SceneFreeModeSelect", null, false);
	}

	protected override bool IsCallFadeIn()
	{
		CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
		bool flag = !characterMgr.IsBusy();
		if (!flag)
		{
			return false;
		}
		if (DailyMgr.IsLegacy)
		{
			YotogiOld.CreateData();
			if (!YotogiOldSkillSelectWaitMotion.ApplyMaidGesture(characterMgr.GetMaid(0), YotogiOld.Stage.サロン))
			{
				return false;
			}
		}
		else if (!YotogiSkillSelectWaitMotion.ApplyMaidGesture(characterMgr.GetMaid(0), YotogiStage.GetAllDatas(true)[0]))
		{
			return false;
		}
		GameMain.Instance.MainCamera.SetTargetOffset(new Vector3((float)Screen.width / 256f * 208f - (float)Screen.width / 2f, 0f, 0f), false);
		for (int i = 0; i < characterMgr.GetManCount(); i++)
		{
			Maid man = characterMgr.GetMan(i);
			if (man != null && man.Visible)
			{
				man.Visible = false;
			}
		}
		return flag;
	}

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

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

	protected override void OnFinish()
	{
		base.OnFinish();
		this.mgr_.CallScreen(this.next_screen);
	}

	public string next_screen { get; set; }

	private SceneFreeModeSelectManager mgr_;
}
