using System;
using System.Collections.Generic;
using Kasizuki;
using UnityEngine;

public class SceneKasizukiMainMenu : WfScreenManager
{
	public WfScreenMoveChildren moveScreen
	{
		get
		{
			return this.m_MoveScreen;
		}
	}

	public void Awake()
	{
		this.m_advKag = GameMain.Instance.ScriptMgr.adv_kag;
	}

	public override void Start()
	{
		base.Start();
		this.m_MoveScreen = base.children_dic["Move"].GetComponent<WfScreenMoveChildren>();
		BgMgr bgMgr = GameMain.Instance.BgMgr;
		bgMgr.ChangeBg("EmpireClub_Entrance");
		GameMain.Instance.MainLight.Reset();
		GameMain.Instance.CharacterMgr.ResetCharaPosAll();
		GameMain.Instance.MainCamera.Reset(CameraMain.CameraType.Target, true);
		GameMain.Instance.SoundMgr.VoiceStopAll();
		this.GetTagBackup();
		CharacterMgr characterMgr = GameMain.Instance.CharacterMgr;
		for (int i = 0; i < characterMgr.GetMaidCount(); i++)
		{
			if (characterMgr.GetMaid(i) != null)
			{
				characterMgr.GetMaid(i).Visible = false;
			}
		}
		this.UpdateMan(delegate
		{
			this.CallScreen("MainMenu");
		});
		GameMain.Instance.SoundMgr.PlayBGM(this.m_MusicName + ".ogg", 0.5f, true);
		if (!uGUITutorialPanel.IsOpened())
		{
			uGUITutorialPanel.OpenTutorial("SceneKasizukiMainMenu", null, false);
		}
	}

	protected override void SettingChildrenList(Dictionary<string, WfScreenChildren> children_dic)
	{
		string[] array = new string[]
		{
			"MainMenu",
			"MaidInfo",
			"Move"
		};
		for (int i = 0; i < array.Length; i++)
		{
			WfScreenChildren component = UTY.GetChildObject(base.gameObject, array[i], false).GetComponent<WfScreenChildren>();
			if (component == null)
			{
				NDebug.Assert(string.Format("オブジェクト「{0}」は見つかりましたが、WfScreenChildrenコンポーネントがありません", array[i]), false);
			}
			component.parent_mgr = this;
			children_dic.Add(array[i], component);
		}
	}

	private void GetTagBackup()
	{
		Dictionary<string, string> tag_backup = this.m_advKag.tag_backup;
		if (tag_backup != null && tag_backup.Count > 0)
		{
			string a;
			if (tag_backup.TryGetValue("name", out a))
			{
				if (a == "SceneKasizukiMainMenu")
				{
					string empty = string.Empty;
					if (tag_backup.TryGetValue("label", out empty))
					{
						this.strScriptReturnLabel = empty;
					}
					else
					{
						NDebug.Warning(string.Format("スクリプトからの引数「{0}」がありませんでした", "label"));
					}
					if (tag_backup.TryGetValue("label_free", out empty))
					{
						this.strScriptReturnLabelFree = empty;
					}
					else
					{
						NDebug.Warning(string.Format("スクリプトからの引数「{0}」がありませんでした", "label_free"));
					}
					if (tag_backup.TryGetValue("edit_label", out empty))
					{
						this.strScriptReturnLabelEdit = empty;
					}
					this.isReturnEdit = tag_backup.ContainsKey("return_edit");
					this.isUpdateMaidStatus = tag_backup.ContainsKey("update_maid_status");
				}
			}
			else
			{
				Debug.Log("スクリプトからの引数がありませんでした");
			}
		}
	}

	public void UpdateMan(Action callback)
	{
		int nowManType = GameMain.Instance.KasizukiMgr.GetNowManType();
		ManData.Data data = ManData.GetData(nowManType);
		Maid man = GameMain.Instance.KasizukiMgr.GetMan();
		GameMain.Instance.KasizukiMgr.SetManModel(man, data.manType);
		GameMain.Instance.KasizukiMgr.UpdateManModel(man, delegate
		{
			if (callback != null)
			{
				callback();
			}
			this.UpdateManEnd();
		});
	}

	private void UpdateManEnd()
	{
		Maid man = GameMain.Instance.KasizukiMgr.GetMan();
		man.body0.SetChinkoVisible(false);
		man.CrossFade("man_porse01.anm", false, true, false, 0f, 1f);
	}

	private void OnDestroy()
	{
		if (this.isQuit)
		{
			return;
		}
		this.CameraFadeOut(delegate
		{
			GameMain.Instance.KasizukiMgr.SetNowManType(ManDataType.主人公);
			this.UpdateMan(delegate
			{
				this.CameraFadeIn(null);
			});
		}, 0.01f);
	}

	private void OnApplicationQuit()
	{
		this.isQuit = true;
	}

	public void CameraFadeIn(Action onEnd)
	{
		CameraMain.dgOnCompleteFade dgOnCompleteFade = null;
		if (onEnd != null)
		{
			dgOnCompleteFade = new CameraMain.dgOnCompleteFade(onEnd.Invoke);
		}
		CameraMain mainCamera = GameMain.Instance.MainCamera;
		CameraMain.dgOnCompleteFade f_dg = dgOnCompleteFade;
		mainCamera.FadeIn(0.5f, false, f_dg, true, true, default(Color));
	}

	public void CameraFadeOut(Action onEnd, float time = 0.5f)
	{
		CameraMain.dgOnCompleteFade dgOnCompleteFade = null;
		if (onEnd != null)
		{
			dgOnCompleteFade = new CameraMain.dgOnCompleteFade(onEnd.Invoke);
		}
		CameraMain mainCamera = GameMain.Instance.MainCamera;
		CameraMain.dgOnCompleteFade f_dg = dgOnCompleteFade;
		mainCamera.FadeOut(time, false, f_dg, true, default(Color));
	}

	public string strScriptReturnLabel { get; private set; }

	public string strScriptReturnLabelEdit { get; private set; }

	public string strScriptReturnLabelFree { get; private set; }

	public bool isReturnEdit { get; private set; }

	public bool isUpdateMaidStatus { get; private set; }

	private WfScreenMoveChildren m_MoveScreen;

	private ADVKagManager m_advKag;

	public string m_MusicName = "BGM020";

	private bool isQuit;
}
