using System;
using System.Collections.Generic;
using I2.Loc;
using UnityEngine;

public class HairLongWindow : BasePhotoWindow
{
	public override string windowName
	{
		get
		{
			return "HairLongWindow";
		}
	}

	public override void Start()
	{
		base.Start();
		this.m_goParent = base.transform.Find("Parent").gameObject;
		this.m_goDummySlider = base.transform.Find("Parent/ContentParent/GameObject/EditTool/InputScale").gameObject;
		this.m_goDummySlider.SetActive(false);
		this.visible = false;
		this.UpdateChildren();
	}

	private void ClearSliders()
	{
		for (int i = 0; i < this.m_listSliders.Count; i++)
		{
			this.m_listSliders[i].Remove();
		}
		this.m_listSliders.Clear();
	}

	public override void Update()
	{
		if (SceneEdit.Instance != null && SceneEdit.Instance.maid != null && (SceneEdit.Instance.NowMPN == MPN.hairf || SceneEdit.Instance.NowMPN == MPN.hairr || SceneEdit.Instance.NowMPN == MPN.hairs || SceneEdit.Instance.NowMPN == MPN.hairt))
		{
			if (SceneEdit.Instance.maid.IsBusy)
			{
				return;
			}
			if (this.m_mpnBackActive == MPN.null_mpn || this.m_mpnBackActive != SceneEdit.Instance.NowMPN || SceneEdit.Instance.maid.GetProp(SceneEdit.Instance.NowMPN).nFileNameRID != this.m_nRID)
			{
				this.ClearSliders();
				Dictionary<string, TBodySkin.HairLengthCtrl.HairLength> hairLengthListFromMPN = SceneEdit.Instance.maid.body0.GetHairLengthListFromMPN(SceneEdit.Instance.NowMPN);
				if (hairLengthListFromMPN != null)
				{
					foreach (KeyValuePair<string, TBodySkin.HairLengthCtrl.HairLength> f_kvNameAndHl in hairLengthListFromMPN)
					{
						GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_goDummySlider);
						gameObject.transform.SetParent(this.m_goDummySlider.transform.parent);
						gameObject.transform.localPosition = this.m_goDummySlider.transform.localPosition;
						gameObject.transform.localPosition = new Vector3(gameObject.transform.localPosition.x, 76f - 64f * (float)this.m_listSliders.Count, gameObject.transform.localPosition.z);
						gameObject.transform.localScale = this.m_goDummySlider.transform.localScale;
						gameObject.transform.localRotation = this.m_goDummySlider.transform.localRotation;
						gameObject.SetActive(true);
						this.m_listSliders.Add(new HairLongWindow.EditBone(gameObject, f_kvNameAndHl, SceneEdit.Instance.maid));
					}
				}
				this.WindowSize.y = 120f + (float)(this.m_listSliders.Count - 1) * 64f;
				base.ResizeWindow();
			}
			this.m_nRID = SceneEdit.Instance.maid.GetProp(SceneEdit.Instance.NowMPN).nFileNameRID;
			this.m_mpnBackActive = SceneEdit.Instance.NowMPN;
		}
		else
		{
			this.ClearSliders();
			this.m_nRID = 0;
			this.m_mpnBackActive = MPN.null_mpn;
		}
		if (this.visible != (this.m_listSliders.Count != 0))
		{
			this.visible = (this.m_listSliders.Count != 0);
		}
	}

	private GameObject m_goParent;

	private GameObject m_goDummySlider;

	private MPN m_mpnBackActive;

	private List<HairLongWindow.EditBone> m_listSliders = new List<HairLongWindow.EditBone>();

	private int m_nRID;

	private class EditBone
	{
		public EditBone(GameObject f_goRoot, KeyValuePair<string, TBodySkin.HairLengthCtrl.HairLength> f_kvNameAndHl, Maid f_maid)
		{
			this.root = f_goRoot;
			this.hl = f_kvNameAndHl.Value;
			this.m_maid = f_maid;
			this.label = this.root.transform.Find("Text").GetComponent<UILabel>();
			this.slider = this.root.GetComponent<PhotoSliderAndInput>();
			this.slider.MinNum = 0f;
			this.slider.MaxNum = 100f;
			this.slider.ResetNum = 50f;
			this.slider.onChangeValue.Add(new Action<float>(this.OnChangeValue));
			string str = string.Empty;
			string str2 = string.Empty;
			int num = f_kvNameAndHl.Key.Length - 1;
			while (0 <= num)
			{
				if ('1' > f_kvNameAndHl.Key[num] || f_kvNameAndHl.Key[num] > '9')
				{
					str = f_kvNameAndHl.Key.Substring(0, num + 1);
					str2 = f_kvNameAndHl.Key.Substring(num + 1, f_kvNameAndHl.Key.Length - (num + 1));
					break;
				}
				num--;
			}
			Localize localize = this.label.gameObject.GetComponent<Localize>();
			if (localize == null)
			{
				localize = this.label.gameObject.AddComponent<Localize>();
			}
			localize.SetTerm("SceneEdit/カテゴリー/サブ/" + str);
			UILabel uilabel = this.label;
			uilabel.text += str2;
			this.slider.value = (this.m_fBackValue = this.hl.GetLengthRate() * 100f);
		}

		public void OnChangeValue(float f_fValue)
		{
			this.hl.SetLengthRate(f_fValue / 100f);
			if (this.m_fBackValue != f_fValue)
			{
				this.m_maid.body0.HairLengthBlend();
			}
			this.m_fBackValue = f_fValue;
		}

		public void Remove()
		{
			UnityEngine.Object.DestroyImmediate(this.root);
		}

		public GameObject root;

		public UILabel label;

		public PhotoSliderAndInput slider;

		public TBodySkin.HairLengthCtrl.HairLength hl;

		private Maid m_maid;

		private float m_fBackValue = 50f;
	}
}
