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

public class EffectWindow : BaseMaidPhotoWindow
{
	public override void Awake()
	{
		base.Awake();
		for (int i = 0; i < this.EffectObjectArray.Length; i++)
		{
			GameObject gameObject = Utility.CreatePrefab(this.Grid.gameObject, "ScenePhotoMode/WindowListItem", true);
			gameObject.name = this.EffectObjectArray[i].Id.ToString();
			gameObject.GetComponentInChildren<UILabel>().text = this.EffectObjectArray[i].Name;
			EventDelegate.Add(gameObject.GetComponent<UIWFTabButton>().onSelect, new EventDelegate.Callback(this.OnSelectEvent));
			this.id_btn_dic_.Add(long.Parse(gameObject.name), gameObject.GetComponent<UIWFTabButton>());
		}
		this.Grid.Reposition();
		this.Grid.GetComponent<UIWFTabPanel>().UpdateChildren();
		for (int j = 0; j < this.EffectObjectArray.Length; j++)
		{
			if (!this.EffectObjectArray[j].EffectObject.gameObject.activeSelf)
			{
				this.EffectObjectArray[j].EffectObject.gameObject.SetActive(true);
			}
		}
	}

	public override void Start()
	{
		base.Start();
		this.UpdateChildren();
		for (int i = 0; i < this.EffectObjectArray.Length; i++)
		{
			this.EffectObjectArray[i].EffectObject.SetEffectWindow(this);
			this.EffectObjectArray[i].EffectObject.Init();
		}
		this.Grid.GetComponent<UIWFTabPanel>().Select(this.id_btn_dic_[(long)this.EffectObjectArray[0].Id]);
	}

	public override void OnMaidAddEvent(Maid maid, bool is_deserialize_load)
	{
		for (int i = 0; i < this.EffectObjectArray.Length; i++)
		{
			this.EffectObjectArray[i].EffectObject.OnMaidAddEvent(maid, is_deserialize_load);
		}
	}

	public void OnSelectEvent()
	{
		if (!UIWFSelectButton.current.isSelected)
		{
			return;
		}
		ulong num = ulong.Parse(UIWFSelectButton.current.name);
		for (int i = 0; i < this.EffectObjectArray.Length; i++)
		{
			this.EffectObjectArray[i].EffectObject.visible = ((int)num == this.EffectObjectArray[i].Id);
		}
	}

	public override void OnSerializeEvent()
	{
		for (int i = 0; i < this.EffectObjectArray.Length; i++)
		{
			this.EffectObjectArray[i].EffectObject.OnSerializeEvent();
		}
		Dictionary<string, Dictionary<string, string>> woldStoreData = base.GetWoldStoreData();
		if (!woldStoreData.ContainsKey("選択エフェクト"))
		{
			woldStoreData.Add("選択エフェクト", new Dictionary<string, string>());
		}
		Dictionary<string, string> dictionary = woldStoreData["選択エフェクト"];
		dictionary["id"] = this.Grid.GetComponent<UIWFTabPanel>().GetSelectButtonObject().name.ToString();
	}

	public override void OnDeserializeEvent()
	{
		for (int i = 0; i < this.EffectObjectArray.Length; i++)
		{
			this.EffectObjectArray[i].EffectObject.OnDeserializeEvent();
		}
		Dictionary<string, Dictionary<string, string>> woldStoreData = base.GetWoldStoreData();
		if (!woldStoreData.ContainsKey("選択エフェクト"))
		{
			woldStoreData.Add("選択エフェクト", new Dictionary<string, string>());
		}
		string value = this.EffectObjectArray[0].Id.ToString();
		Dictionary<string, string> dictionary = woldStoreData["選択エフェクト"];
		if (!dictionary.ContainsKey("id"))
		{
			dictionary["id"] = value;
		}
		else if (dictionary["id"] == "0")
		{
			dictionary["id"] = value;
		}
		long key = long.Parse(dictionary["id"]);
		this.Grid.GetComponent<UIWFTabPanel>().Select(this.id_btn_dic_[key]);
	}

	public Dictionary<string, Dictionary<string, string>> GetStoreData()
	{
		return base.mgr.GetWoldStoreData(this);
	}

	public UIGrid Grid;

	public EffectWindow.EffectObjectData[] EffectObjectArray;

	private Dictionary<long, UIWFTabButton> id_btn_dic_ = new Dictionary<long, UIWFTabButton>();

	[Serializable]
	public class EffectObjectData
	{
		public int Id;

		public string Name;

		public WindowPartsEffectBase EffectObject;
	}
}
