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

public class PhotoManEditManager
{
	public PhotoManEditManager()
	{
		this.man_head_menu_list_ = new List<SceneEdit.SMenuItem>();
		this.man_body_menu_list_ = new List<SceneEdit.SMenuItem>();
		if (PhotoManEditManager.menu_file_name_list_ == null)
		{
			PhotoManEditManager.menu_file_name_list_ = new HashSet<string>();
			foreach (string text in GameUty.MenuFiles)
			{
				string text2 = text.ToLower();
				if (text2.Contains("mhead") || text2.Contains("mbody"))
				{
					SceneEdit.SMenuItem smenuItem = new SceneEdit.SMenuItem();
					if (SceneEdit.GetMenuItemSetUP(smenuItem, text, true))
					{
						if (!(smenuItem.m_texIcon == null) && smenuItem.m_bMan)
						{
							if (!PhotoManEditManager.menu_file_name_list_.Contains(text))
							{
								PhotoManEditManager.menu_file_name_list_.Add(text);
								if (smenuItem.m_mpn == MPN.head)
								{
									this.man_head_menu_list_.Add(smenuItem);
								}
								else
								{
									this.man_body_menu_list_.Add(smenuItem);
								}
							}
						}
					}
				}
			}
		}
		else
		{
			foreach (string f_strMenuFileName in PhotoManEditManager.menu_file_name_list_)
			{
				SceneEdit.SMenuItem smenuItem2 = new SceneEdit.SMenuItem();
				if (SceneEdit.GetMenuItemSetUP(smenuItem2, f_strMenuFileName, true))
				{
					if (smenuItem2.m_mpn == MPN.head)
					{
						this.man_head_menu_list_.Add(smenuItem2);
					}
					else
					{
						this.man_body_menu_list_.Add(smenuItem2);
					}
				}
			}
		}
	}

	public void Destroy()
	{
		List<SceneEdit.SMenuItem>[] array = new List<SceneEdit.SMenuItem>[]
		{
			this.man_head_menu_list_,
			this.man_body_menu_list_
		};
		foreach (List<SceneEdit.SMenuItem> list in array)
		{
			foreach (SceneEdit.SMenuItem smenuItem in list)
			{
				if (smenuItem.m_texIcon != null)
				{
					UnityEngine.Object.Destroy(smenuItem.m_texIcon);
				}
				if (smenuItem.m_texIconRandomColor != null)
				{
					UnityEngine.Object.Destroy(smenuItem.m_texIconRandomColor);
				}
			}
			list.Clear();
		}
	}

	public List<SceneEdit.SMenuItem> man_head_menu_list
	{
		get
		{
			return this.man_head_menu_list_;
		}
	}

	public List<SceneEdit.SMenuItem> man_body_menu_list
	{
		get
		{
			return this.man_body_menu_list_;
		}
	}

	private List<SceneEdit.SMenuItem> man_head_menu_list_;

	private List<SceneEdit.SMenuItem> man_body_menu_list_;

	private static HashSet<string> menu_file_name_list_;

	public class Controller
	{
		public Controller()
		{
		}

		public Controller(Maid man)
		{
			this.man = man;
			if (man != null)
			{
				NDebug.Assert(man.boMAN, "メイドが設定されました");
			}
		}

		public bool SetMenu(SceneEdit.SMenuItem set_menu)
		{
			if (this.man == null || this.IsSelected(set_menu))
			{
				return false;
			}
			bool chinkoVisible = this.man.body0.GetChinkoVisible();
			bool result = false;
			if (this.man.GetProp(set_menu.m_mpn).nFileNameRID != set_menu.m_nMenuFileRID)
			{
				this.man.SetProp(set_menu.m_mpn, set_menu.m_strMenuFileName, set_menu.m_nMenuFileRID, false, false);
				this.man.AllProcProp();
				result = true;
			}
			if (set_menu.m_mpn == MPN.body)
			{
				this.man.body0.SetChinkoVisible(chinkoVisible);
			}
			return result;
		}

		public bool IsSelected(SceneEdit.SMenuItem check_menu)
		{
			if (this.man == null || check_menu == null)
			{
				return false;
			}
			MaidProp prop = this.man.GetProp(check_menu.m_mpn);
			return prop != null && prop.nFileNameRID == check_menu.m_nMenuFileRID;
		}

		public Maid man { get; set; }

		public float fat
		{
			get
			{
				if (this.man == null)
				{
					return 0f;
				}
				MaidProp prop = this.man.GetProp(MPN.Hara);
				return (float)(prop.value - prop.min) / (float)(prop.max - prop.min);
			}
			set
			{
				if (this.man == null)
				{
					return;
				}
				MaidProp prop = this.man.GetProp(MPN.Hara);
				if (this.fat == value)
				{
					return;
				}
				this.man.SetProp(MPN.Hara, (int)((float)prop.min + (float)(prop.max - prop.min) * value + 0.5f), false);
				this.man.AllProcProp();
			}
		}

		public Color color
		{
			get
			{
				return (!(this.man == null)) ? this.man.ManColor : Color.black;
			}
			set
			{
				if (this.man == null)
				{
					return;
				}
				this.man.ManColor = value;
				this.man.ManColorUpdate();
			}
		}

		public int alpha
		{
			get
			{
				return GameMain.Instance.CMSystem.ManAlpha;
			}
			set
			{
				GameMain.Instance.CMSystem.ManAlpha = wf.Math.RoundMinMax(value, 0, 100);
				GameMain.Instance.CharacterMgr.ManAlphaUpdate();
			}
		}

		public bool parts_visible
		{
			get
			{
				if (this.man == null || this.man.body0 == null)
				{
					return false;
				}
				List<TBodySkin> goSlot = this.man.body0.goSlot;
				foreach (TBodySkin tbodySkin in goSlot)
				{
					if (!(tbodySkin.obj == null))
					{
						Transform transform = CMT.SearchObjName(tbodySkin.obj.transform, "chinkoCenter", false);
						if (!(transform == null))
						{
							return transform.localScale == Vector3.one;
						}
					}
				}
				return false;
			}
			set
			{
				if (this.man == null || this.man.body0 == null)
				{
					return;
				}
				this.man.body0.SetChinkoVisible(value);
			}
		}

		public int head_menu_rid
		{
			get
			{
				return (!(this.man == null)) ? this.man.GetProp(MPN.head).nFileNameRID : -1;
			}
		}

		public int body_menu_rid
		{
			get
			{
				return (!(this.man == null)) ? this.man.GetProp(MPN.body).nFileNameRID : -1;
			}
		}
	}
}
