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

namespace SceneEditWindow
{
	[AddComponentMenu("SceneEditWindow/UndressWindow")]
	public class UndressWindow : BasePhotoWindow
	{
		public override string windowName
		{
			get
			{
				return "UndressWindow";
			}
		}

		public override void Awake()
		{
			base.Awake();
			for (int i = 0; i < UndressWindow.IconTexFileNames.Length; i++)
			{
				UIWFTabButton uiwftabButton = this.CreateItemObject(this.itemGrit.gameObject, UndressWindow.IconTexFileNames[i]);
				uiwftabButton.name = i.ToString();
				EventDelegate.Add(uiwftabButton.onClick, delegate()
				{
					this.OnClickItem((UndressWindow.UndressType)int.Parse(UIButton.current.name));
				});
			}
			this.UpdateChildren();
		}

		protected virtual void OnDestroy()
		{
			foreach (KeyValuePair<string, Texture> keyValuePair in this.texDic)
			{
				UnityEngine.Object.DestroyImmediate(keyValuePair.Value);
			}
			this.texDic.Clear();
		}

		protected void OnClickItem(UndressWindow.UndressType type)
		{
			if (this.onClickUndressEvent != null)
			{
				this.onClickUndressEvent(type);
			}
		}

		protected UIWFTabButton CreateItemObject(GameObject parent, string textFileName)
		{
			GameObject gameObject = Utility.CreatePrefab(parent, "SceneEdit/WindowParts/PoseIconItem", true);
			if (!this.texDic.ContainsKey(textFileName))
			{
				this.texDic.Add(textFileName, ImportCM.CreateTexture(textFileName));
			}
			UITexture component = gameObject.GetComponent<UITexture>();
			component.mainTexture = this.texDic[textFileName];
			return gameObject.GetComponent<UIWFTabButton>();
		}

		public static readonly string[] IconTexFileNames = new string[]
		{
			"cm3d2_edit_clothesicon_dress.tex",
			"cm3d2_edit_clothesicon_lingerie.tex",
			"cm3d2_edit_clothesicon_nude.tex"
		};

		[SerializeField]
		public SceneEdit sceneEdit;

		[SerializeField]
		private UIGrid itemGrit;

		public Action<UndressWindow.UndressType> onClickUndressEvent;

		private Dictionary<string, Texture> texDic = new Dictionary<string, Texture>();

		public enum UndressType
		{
			Dress,
			Lingerie,
			Nude
		}
	}
}
