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

public abstract class WfScreenManager : MonoBehaviour
{
	public virtual void Start()
	{
		this.SettingChildrenList(this.children_dic_);
		GameMain.Instance.MainCamera.FadeOut(0f, false, null, true, default(Color));
	}

	public virtual void Update()
	{
		if (!this.init_)
		{
			bool flag = true;
			foreach (KeyValuePair<string, WfScreenChildren> keyValuePair in this.children_dic_)
			{
				if (!keyValuePair.Value.init_finishied)
				{
					flag = false;
					break;
				}
			}
			if (flag)
			{
				this.init_ = true;
				if (!string.IsNullOrEmpty(this.next_screen_))
				{
					string screen_name = this.next_screen_;
					this.next_screen_ = string.Empty;
					this.RunScreen(screen_name);
				}
			}
		}
		else if (!string.IsNullOrEmpty(this.next_screen_) && this.cur_call_screen_mgr.fade_status == WfScreenChildren.FadeStatus.FadeEnd)
		{
			this.cur_call_screen_mgr.Reset();
			string screen_name2 = this.next_screen_;
			this.next_screen_ = string.Empty;
			this.RunScreen(screen_name2);
		}
	}

	public virtual void CallScreen(string call_screen_name)
	{
		if (this.cur_call_screen_mgr == null)
		{
			this.next_screen_ = string.Empty;
			if (this.init_)
			{
				this.RunScreen(call_screen_name);
			}
			else
			{
				this.next_screen_ = call_screen_name;
			}
		}
		else if (this.cur_call_screen_mgr.fade_status == WfScreenChildren.FadeStatus.FadeEnd || this.cur_call_screen_mgr.fade_status == WfScreenChildren.FadeStatus.Null)
		{
			this.next_screen_ = call_screen_name;
		}
		else if (this.cur_call_screen_mgr.Finish())
		{
			this.next_screen_ = call_screen_name;
		}
	}

	private void RunScreen(string screen_name)
	{
		this.OnPrevRunScreen(screen_name);
		foreach (KeyValuePair<string, WfScreenChildren> keyValuePair in this.children_dic_)
		{
			keyValuePair.Value.root_obj.SetActive(false);
		}
		if (this.children_dic_[screen_name].Call())
		{
			this.call_screen_ = screen_name;
		}
	}

	protected virtual void OnPrevRunScreen(string screen_name)
	{
	}

	protected abstract void SettingChildrenList(Dictionary<string, WfScreenChildren> children_dic);

	public string cur_call_screen_name
	{
		get
		{
			return this.call_screen_;
		}
	}

	public WfScreenChildren cur_call_screen_mgr
	{
		get
		{
			if (this.call_screen_ == string.Empty)
			{
				return null;
			}
			return this.children_dic_[this.call_screen_];
		}
	}

	public Dictionary<string, WfScreenChildren> children_dic
	{
		get
		{
			return this.children_dic_;
		}
	}

	private Dictionary<string, WfScreenChildren> children_dic_ = new Dictionary<string, WfScreenChildren>();

	private bool init_;

	private string call_screen_ = string.Empty;

	private string next_screen_ = string.Empty;
}
