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

public class PoseEditWindow : BaseMaidPhotoWindow
{
	public static IKManager GetMaidIKManager(Maid maid)
	{
		GameObject gameObject = GameObject.Find("PoseEditWorkParent");
		if (gameObject == null)
		{
			gameObject = new GameObject("PoseEditWorkParent");
		}
		if (maid == null || maid.boMAN)
		{
			return null;
		}
		GameObject gameObject2 = GameObject.Find("PoseEditWorkParent/" + maid.status.guid);
		if (gameObject2 != null && gameObject2.GetComponent<IKManager>() != null)
		{
			return gameObject2.GetComponent<IKManager>();
		}
		if (gameObject2 == null)
		{
			gameObject2 = new GameObject(maid.status.guid);
			gameObject2.transform.SetParent(gameObject.transform, false);
		}
		IKManager ikmanager = gameObject2.AddComponent<IKManager>();
		ikmanager.SetMaid(maid);
		IEnumerator enumerator = Enum.GetValues(typeof(IKManager.BoneSetType)).GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				object obj = enumerator.Current;
				IKManager.BoneSetType bone_set_type = (IKManager.BoneSetType)obj;
				ikmanager.SetRotateVisibleBoneSet(bone_set_type, false);
				ikmanager.SetTransAxisVisibleBoneSet(bone_set_type, false);
			}
		}
		finally
		{
			IDisposable disposable;
			if ((disposable = (enumerator as IDisposable)) != null)
			{
				disposable.Dispose();
			}
		}
		ikmanager.SetTransAxisVisibleRoot(false);
		return ikmanager;
	}

	public override void Awake()
	{
		base.Awake();
		this.noCharaActive = base.GetComponentInChildren<PhotoNoCharaActive>();
		EventDelegate.Add(this.BtnSave.onClick, new EventDelegate.Callback(this.OnBtnSave));
		if (this.BtnReversal != null)
		{
			EventDelegate.Add(this.BtnReversal.onClick, new EventDelegate.Callback(this.OnBtnReversal));
		}
		this.ControlSelectBtnTab.UpdateChildren();
		foreach (UIWFTabButton uiwftabButton in this.ControlSelectBtnTab.button_list)
		{
			EventDelegate.Add(uiwftabButton.onSelect, new EventDelegate.Callback(this.OnSelectControlSelectBtn));
		}
		for (int i = 0; i < this.FingerBlendArray.Length; i++)
		{
			this.FingerBlendArray[i].mgr = base.mgr;
			this.FingerBlendArray[i].OnClickFingerBlendEnabledEvent = delegate(WindowPartsFingerBlend.Type blend_type, bool blend_enabled)
			{
				IKManager.BoneSetType boneSetType = IKManager.BoneSetType.Body;
				WFCheckBox wfcheckBox = null;
				if (blend_type == WindowPartsFingerBlend.Type.RightArm)
				{
					wfcheckBox = this.ikbox_visible_dic_["ik_box_visible_RightArmFinger"];
					boneSetType = IKManager.BoneSetType.RightArmFinger;
				}
				else if (blend_type == WindowPartsFingerBlend.Type.LeftArm)
				{
					wfcheckBox = this.ikbox_visible_dic_["ik_box_visible_LeftArmFinger"];
					boneSetType = IKManager.BoneSetType.LeftArmFinger;
				}
				else if (blend_type == WindowPartsFingerBlend.Type.RightLeg)
				{
					wfcheckBox = this.ikbox_visible_dic_["ik_box_visible_RightLegFinger"];
					boneSetType = IKManager.BoneSetType.RightLegFinger;
				}
				else if (blend_type == WindowPartsFingerBlend.Type.LeftLeg)
				{
					wfcheckBox = this.ikbox_visible_dic_["ik_box_visible_LeftLegFinger"];
					boneSetType = IKManager.BoneSetType.LeftLegFinger;
				}
				if (!blend_enabled)
				{
					wfcheckBox.enabled = true;
					for (int l = 0; l < this.RotateCheckBoxArray.Length; l++)
					{
						if (this.RotateCheckBoxArray[l].BoneSetType == boneSetType)
						{
							this.RotateCheckBoxArray[l].AllCheckBoxEnabled(true);
						}
					}
					return;
				}
				WFCheckBox wfcheckBox2 = wfcheckBox;
				bool flag = false;
				wfcheckBox.enabled = flag;
				wfcheckBox2.check = flag;
				foreach (Action<WFCheckBox> action in wfcheckBox.onClick)
				{
					action(wfcheckBox);
				}
				for (int m = 0; m < this.RotateCheckBoxArray.Length; m++)
				{
					if (this.RotateCheckBoxArray[m].BoneSetType == boneSetType)
					{
						this.RotateCheckBoxArray[m].AllCheckBoxOFF();
						this.RotateCheckBoxArray[m].AllCheckBoxEnabled(false);
					}
				}
			};
		}
		for (int j = 0; j < this.RotateCheckBoxArray.Length; j++)
		{
			this.RotateCheckBoxArray[j].mgr = base.mgr;
		}
		this.GetControlPanelParentObject(PoseEditWindow.ControlType.Body).SetActive(true);
		this.GetControlPanelParentObject(PoseEditWindow.ControlType.Hand).SetActive(true);
		this.GetControlPanelParentObject(PoseEditWindow.ControlType.Leg).SetActive(true);
		List<KeyValuePair<PoseEditWindow.ControlType, KeyValuePair<string, string>>> list = new List<KeyValuePair<PoseEditWindow.ControlType, KeyValuePair<string, string>>>();
		list.Add(new KeyValuePair<PoseEditWindow.ControlType, KeyValuePair<string, string>>(PoseEditWindow.ControlType.Body, new KeyValuePair<string, string>("ik_box_visible_Root", "CheckCenterVisible")));
		list.Add(new KeyValuePair<PoseEditWindow.ControlType, KeyValuePair<string, string>>(PoseEditWindow.ControlType.Body, new KeyValuePair<string, string>("ik_box_visible_Body", "CheckLimbVisible")));
		list.Add(new KeyValuePair<PoseEditWindow.ControlType, KeyValuePair<string, string>>(PoseEditWindow.ControlType.Hand, new KeyValuePair<string, string>("ik_box_visible_RightArmFinger", "RightSet/Parent/CheckIKVisible")));
		list.Add(new KeyValuePair<PoseEditWindow.ControlType, KeyValuePair<string, string>>(PoseEditWindow.ControlType.Hand, new KeyValuePair<string, string>("ik_box_visible_LeftArmFinger", "LeftSet/Parent/CheckIKVisible")));
		list.Add(new KeyValuePair<PoseEditWindow.ControlType, KeyValuePair<string, string>>(PoseEditWindow.ControlType.Leg, new KeyValuePair<string, string>("ik_box_visible_RightLegFinger", "RightSet/Parent/CheckIKVisible")));
		list.Add(new KeyValuePair<PoseEditWindow.ControlType, KeyValuePair<string, string>>(PoseEditWindow.ControlType.Leg, new KeyValuePair<string, string>("ik_box_visible_LeftLegFinger", "LeftSet/Parent/CheckIKVisible")));
		for (int k = 0; k < list.Count; k++)
		{
			WFCheckBox component = UTY.GetChildObject(this.GetControlPanelParentObject(list[k].Key), list[k].Value.Value, false).GetComponent<WFCheckBox>();
			component.name = list[k].Value.Key;
			component.onClick.Add(new Action<WFCheckBox>(this.OnIKBOXVixibleCheckBox));
			this.ikbox_visible_dic_.Add(component.name, component);
		}
	}

	public override void Start()
	{
		base.Start();
		this.UpdateChildren();
		this.CheckbtnUse.onClick.Add(new Action<WFCheckBox>(this.OnClickUseCheck));
		this.noCharaActive.ChangeMode(true, true);
	}

	public new void Update()
	{
		if (base.mgr.select_maid == null || base.mgr.select_maid.boMAN || !this.CheckbtnUse.check)
		{
			return;
		}
		bool flag = false;
		bool flag2 = false;
		if ((Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftControl)) && Input.GetKeyDown(KeyCode.Z))
		{
			flag = true;
		}
		if ((Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftControl)) && Input.GetKeyDown(KeyCode.Y))
		{
			flag2 = true;
		}
		if (flag || flag2)
		{
			bool flag3 = true;
			string draw_text = string.Empty;
			for (int i = 0; i < this.FingerBlendArray.Length; i++)
			{
				if (this.FingerBlendArray[i].CheckBoxEnabled.enabled && this.FingerBlendArray[i].CheckBoxEnabled.check)
				{
					if (flag)
					{
						draw_text = "指先ブレンド中はUndoできません";
					}
					else
					{
						draw_text = "指先ブレンド中はRedoできません";
					}
					flag3 = false;
					break;
				}
			}
			if (GizmoRender.control_lock || IKDragPoint.IsDrag)
			{
				if (flag)
				{
					draw_text = "操作中はUndoできません";
				}
				else
				{
					draw_text = "操作中はRedoできません";
				}
				flag3 = false;
			}
			MouseExposition @object = MouseExposition.GetObject();
			if (flag3)
			{
				bool flag4 = (!flag) ? this.ik_mgr.HistoryRedo() : this.ik_mgr.HistoryUndo();
				if (flag4)
				{
					@object.SetText((!flag) ? "Redo" : "Undo", 0.5f);
				}
			}
			else
			{
				@object.SetText(draw_text, 3f);
			}
		}
	}

	public override void OnMaidAddEvent(Maid maid, bool is_deserialize_load)
	{
		base.OnMaidAddEvent(maid, is_deserialize_load);
		if (maid.boMAN)
		{
			return;
		}
		Dictionary<string, string> maidStoreData = base.GetMaidStoreData(maid);
		if (!maidStoreData.ContainsKey("use"))
		{
			maidStoreData["use"] = false.ToString();
		}
		if (!maidStoreData.ContainsKey("select_control_type"))
		{
			maidStoreData["select_control_type"] = PoseEditWindow.ControlType.Body.ToString();
		}
		if (!maidStoreData.ContainsKey("pose_binary"))
		{
			maidStoreData["pose_binary"] = string.Empty;
		}
		if (!maidStoreData.ContainsKey("use_mune_key_l"))
		{
			Dictionary<string, string> dictionary = maidStoreData;
			string key = "use_mune_key_l";
			string value = false.ToString();
			maidStoreData["use_mune_key_r"] = value;
			dictionary[key] = value;
		}
		foreach (KeyValuePair<string, WFCheckBox> keyValuePair in this.ikbox_visible_dic_)
		{
			if (!maidStoreData.ContainsKey(keyValuePair.Value.name))
			{
				maidStoreData[keyValuePair.Value.name] = false.ToString();
			}
		}
		maidStoreData["ik_box_visible_Body"] = true.ToString();
		for (int i = 0; i < this.FingerBlendArray.Length; i++)
		{
			this.FingerBlendArray[i].OnMaidAddEvent(maid, is_deserialize_load);
		}
		for (int j = 0; j < this.RotateCheckBoxArray.Length; j++)
		{
			this.RotateCheckBoxArray[j].OnMaidAddEvent(maid, is_deserialize_load);
		}
		if (is_deserialize_load && !string.IsNullOrEmpty(maidStoreData["pose_binary"]))
		{
			IKManager maidIKManager = PoseEditWindow.GetMaidIKManager(maid);
			KeyValuePair<bool, bool> keyValuePair2 = maidIKManager.cache_bone_data.SetFrameBinary(Convert.FromBase64String(maidStoreData["pose_binary"]));
			maid.body0.jbMuneL.enabled = !keyValuePair2.Key;
			maid.body0.jbMuneR.enabled = !keyValuePair2.Value;
		}
	}

	public void OnMotionUpdate(Maid maid)
	{
		if (base.mgr.select_maid == null || base.mgr.select_maid != maid || maid.boMAN)
		{
			return;
		}
		Dictionary<string, string> maidStoreData = base.GetMaidStoreData(maid);
		if (!bool.Parse(maidStoreData["use"]))
		{
			return;
		}
		maidStoreData["use_mune_key_l"] = (maid.body0.GetMuneYureL() == 0f).ToString();
		maidStoreData["use_mune_key_r"] = (maid.body0.GetMuneYureR() == 0f).ToString();
		maid.body0.jbMuneL.enabled = (maid.body0.GetMuneYureL() != 0f);
		maid.body0.jbMuneR.enabled = (maid.body0.GetMuneYureR() != 0f);
		for (int i = 0; i < this.RotateCheckBoxArray.Length; i++)
		{
			this.RotateCheckBoxArray[i].OnMotionUpdate();
		}
		if (this.ik_mgr_ != null)
		{
			IKManager.BoneSetType[] array = new IKManager.BoneSetType[0];
			if (this.ik_mgr_ != null && this.ctrl_type_ == PoseEditWindow.ControlType.Body)
			{
				array = new IKManager.BoneSetType[]
				{
					IKManager.BoneSetType.RightArmFinger,
					IKManager.BoneSetType.LeftArmFinger,
					IKManager.BoneSetType.RightLegFinger,
					IKManager.BoneSetType.LeftLegFinger
				};
			}
			else if (this.ik_mgr_ != null && this.ctrl_type_ == PoseEditWindow.ControlType.Hand)
			{
				array = new IKManager.BoneSetType[]
				{
					IKManager.BoneSetType.Body,
					IKManager.BoneSetType.RightLegFinger,
					IKManager.BoneSetType.LeftLegFinger
				};
			}
			else if (this.ik_mgr_ != null && this.ctrl_type_ == PoseEditWindow.ControlType.Leg)
			{
				array = new IKManager.BoneSetType[]
				{
					IKManager.BoneSetType.Body,
					IKManager.BoneSetType.RightArmFinger,
					IKManager.BoneSetType.LeftArmFinger
				};
			}
			foreach (IKManager.BoneSetType bone_set_type in array)
			{
				this.ik_mgr_.SetRotateVisibleBoneSet(bone_set_type, false);
			}
		}
		for (int k = 0; k < this.FingerBlendArray.Length; k++)
		{
			this.FingerBlendArray[k].OnMotionUpdate();
		}
		if (this.ik_mgr_ != null)
		{
			this.ik_mgr.HistoryClear();
			this.ik_mgr.HistoryNew();
		}
	}

	public void OnSelectControlSelectBtn()
	{
		if (this.ControlSelectBtnTab.GetSelectButtonObject() == null || base.mgr.select_maid == null || base.mgr.select_maid.boMAN || !UIWFSelectButton.current.isSelected)
		{
			return;
		}
		UILabel componentInChildren = this.ControlSelectBtnTab.GetSelectButtonObject().GetComponentInChildren<UILabel>();
		if (componentInChildren == null)
		{
			return;
		}
		Dictionary<string, string> maidStoreData = base.GetMaidStoreData(base.mgr.select_maid);
		string key = "select_control_type";
		if (componentInChildren.text == "胴体")
		{
			this.ctrl_type_ = PoseEditWindow.ControlType.Body;
		}
		else if (componentInChildren.text == "手")
		{
			this.ctrl_type_ = PoseEditWindow.ControlType.Hand;
		}
		else
		{
			this.ctrl_type_ = PoseEditWindow.ControlType.Leg;
		}
		maidStoreData[key] = this.ctrl_type_.ToString();
		this.SetControlPanel(this.ctrl_type_);
		IKManager.BoneSetType[] array = new IKManager.BoneSetType[0];
		bool flag = false;
		if (this.ik_mgr_ != null && this.ctrl_type_ == PoseEditWindow.ControlType.Body)
		{
			array = new IKManager.BoneSetType[]
			{
				IKManager.BoneSetType.RightArmFinger,
				IKManager.BoneSetType.LeftArmFinger,
				IKManager.BoneSetType.RightLegFinger,
				IKManager.BoneSetType.LeftLegFinger
			};
			flag = true;
		}
		else if (this.ik_mgr_ != null && this.ctrl_type_ == PoseEditWindow.ControlType.Hand)
		{
			array = new IKManager.BoneSetType[]
			{
				IKManager.BoneSetType.Body,
				IKManager.BoneSetType.RightLegFinger,
				IKManager.BoneSetType.LeftLegFinger
			};
		}
		else if (this.ik_mgr_ != null && this.ctrl_type_ == PoseEditWindow.ControlType.Leg)
		{
			array = new IKManager.BoneSetType[]
			{
				IKManager.BoneSetType.Body,
				IKManager.BoneSetType.RightArmFinger,
				IKManager.BoneSetType.LeftArmFinger
			};
		}
		foreach (KeyValuePair<string, WFCheckBox> keyValuePair in this.ikbox_visible_dic_)
		{
			keyValuePair.Value.check = bool.Parse(maidStoreData[keyValuePair.Value.name]);
			keyValuePair.Value.onClick[0](keyValuePair.Value);
		}
		foreach (IKManager.BoneSetType bone_set_type in array)
		{
			this.ik_mgr_.SetRotateVisibleBoneSet(bone_set_type, false);
			this.ik_mgr_.SetTransAxisVisibleBoneSet(bone_set_type, false);
		}
		if (!flag)
		{
			this.ik_mgr_.SetTransAxisVisibleRoot(false);
		}
		List<IKManager.BoneSetType> list = new List<IKManager.BoneSetType>(array);
		for (int j = 0; j < this.RotateCheckBoxArray.Length; j++)
		{
			if (0 > list.IndexOf(this.RotateCheckBoxArray[j].BoneSetType))
			{
				this.RotateCheckBoxArray[j].Apply();
			}
		}
	}

	public void OnClickUseCheck(WFCheckBox check_box)
	{
		if (base.mgr.select_maid == null || base.mgr.select_maid.boMAN)
		{
			return;
		}
		if (!check_box.check && GameMain.Instance.SysDlg.IsDecided)
		{
			GameMain.Instance.SysDlg.Show("セーブしていないデータは失われます。\nOFFにしますか？", SystemDialog.TYPE.YES_NO, delegate
			{
				check_box.check = false;
				this.OnClickUseCheckRun(false);
				GameMain.Instance.SysDlg.Close();
			}, null);
			check_box.check = true;
			return;
		}
		this.OnClickUseCheckRun(true);
	}

	public void OnClickUseCheckRun(bool check)
	{
		Dictionary<string, string> maidStoreData = base.GetMaidStoreData(base.mgr.select_maid);
		maidStoreData["use"] = check.ToString();
		if (!check)
		{
			maidStoreData["pose_binary"] = string.Empty;
		}
		this.ChangeEnabeled(check);
		this.ik_mgr.HistoryClear();
		this.ik_mgr.HistoryNew();
		MaidColliderCollect component = base.mgr.select_maid.GetComponent<MaidColliderCollect>();
		List<CapsuleCollider> collider = component.GetCollider(MaidColliderCollect.ColliderType.Grab);
		foreach (CapsuleCollider capsuleCollider in collider)
		{
			capsuleCollider.gameObject.SetActive(!check);
		}
	}

	public void OnIKBOXVixibleCheckBox(WFCheckBox check_box)
	{
		if (base.mgr.select_maid == null || base.mgr.select_maid.boMAN || this.ik_mgr_ == null)
		{
			return;
		}
		Dictionary<string, string> maidStoreData = base.GetMaidStoreData(base.mgr.select_maid);
		maidStoreData[check_box.name] = check_box.check.ToString();
		string text = check_box.name.Replace("ik_box_visible_", string.Empty);
		if (text == "Root")
		{
			this.ik_mgr_.SetTransAxisVisibleRoot(check_box.check);
		}
		else
		{
			IKManager.BoneSetType boneSetType = (IKManager.BoneSetType)Enum.Parse(typeof(IKManager.BoneSetType), text);
			this.ik_mgr_.SetTransAxisVisibleBoneSet(boneSetType, check_box.check);
			if (check_box.check && boneSetType != IKManager.BoneSetType.Body)
			{
				WindowPartsFingerBlend windowPartsFingerBlend = this.GetWindowPartsFingerBlend(boneSetType);
				if (windowPartsFingerBlend != null && windowPartsFingerBlend.CheckBoxEnabled.check)
				{
					windowPartsFingerBlend.OnClickEnter();
				}
			}
		}
	}

	public void ChangeEnabeled(bool use)
	{
		if (use && (base.mgr.select_maid == null || base.mgr.select_maid.boMAN))
		{
			use = false;
		}
		if (use)
		{
			Dictionary<string, string> maidStoreData = base.GetMaidStoreData(base.mgr.select_maid);
			this.BtnSave.isEnabled = true;
			MotionWindow motionWindow = base.mgr.GetWindow(PhotoWindowManager.WindowType.Motion) as MotionWindow;
			if (!motionWindow.CheckbtnStop.check)
			{
				motionWindow.CheckbtnStop.check = true;
				motionWindow.OnClickStopCheck(motionWindow.CheckbtnStop);
			}
			base.mgr.select_maid.IKTargetToBone("左手", null, "無し", Vector3.zero, IKCtrlData.IKAttachType.Point, false, 0f, false, false);
			base.mgr.select_maid.IKTargetToBone("右手", null, "無し", Vector3.zero, IKCtrlData.IKAttachType.Point, false, 0f, false, false);
			this.ControlSelectBtnTab.ResetSelect();
			Dictionary<PoseEditWindow.ControlType, UIWFTabButton> dictionary = new Dictionary<PoseEditWindow.ControlType, UIWFTabButton>();
			foreach (UIWFTabButton uiwftabButton in this.ControlSelectBtnTab.button_list)
			{
				uiwftabButton.SetSelect(false);
				uiwftabButton.isEnabled = true;
				dictionary.Add((PoseEditWindow.ControlType)Enum.Parse(typeof(PoseEditWindow.ControlType), uiwftabButton.transform.parent.name), uiwftabButton);
			}
			base.mgr.select_maid.body0.jbMuneL.enabled = (base.mgr.select_maid.body0.GetMuneYureL() != 0f);
			base.mgr.select_maid.body0.jbMuneR.enabled = (base.mgr.select_maid.body0.GetMuneYureR() != 0f);
			for (int i = 0; i < this.RotateCheckBoxArray.Length; i++)
			{
				this.RotateCheckBoxArray[i].ChangeEnabeled(use);
			}
			for (int j = 0; j < this.FingerBlendArray.Length; j++)
			{
				this.FingerBlendArray[j].ChangeEnabeled(use);
			}
			this.ControlSelectBtnTab.Select(dictionary[this.ctrl_type_]);
		}
		else
		{
			this.ControlSelectBtnTab.ResetSelect();
			foreach (UIWFTabButton uiwftabButton2 in this.ControlSelectBtnTab.button_list)
			{
				uiwftabButton2.SetSelect(false);
				uiwftabButton2.isEnabled = false;
			}
			this.BtnSave.isEnabled = false;
			MotionWindow motionWindow2 = base.mgr.GetWindow(PhotoWindowManager.WindowType.Motion) as MotionWindow;
			motionWindow2.UpdateAnimationData(base.mgr.select_maid);
			this.SetControlPanel(PoseEditWindow.ControlType.Null);
			if (this.ik_mgr_ != null)
			{
				IEnumerator enumerator3 = Enum.GetValues(typeof(IKManager.BoneSetType)).GetEnumerator();
				try
				{
					while (enumerator3.MoveNext())
					{
						object obj = enumerator3.Current;
						IKManager.BoneSetType bone_set_type = (IKManager.BoneSetType)obj;
						this.ik_mgr_.SetRotateVisibleBoneSet(bone_set_type, false);
						this.ik_mgr_.SetTransAxisVisibleBoneSet(bone_set_type, false);
					}
				}
				finally
				{
					IDisposable disposable;
					if ((disposable = (enumerator3 as IDisposable)) != null)
					{
						disposable.Dispose();
					}
				}
				this.ik_mgr_.SetTransAxisVisibleRoot(false);
			}
			if (base.mgr.select_maid != null && base.mgr.select_maid.body0 != null && !base.mgr.select_maid.boMAN)
			{
				base.mgr.select_maid.body0.jbMuneL.enabled = (base.mgr.select_maid.body0.GetMuneYureL() != 0f);
				base.mgr.select_maid.body0.jbMuneR.enabled = (base.mgr.select_maid.body0.GetMuneYureR() != 0f);
			}
			if (this.ik_mgr != null)
			{
				this.ik_mgr.HistoryClear();
			}
			for (int k = 0; k < this.RotateCheckBoxArray.Length; k++)
			{
				this.RotateCheckBoxArray[k].ChangeEnabeled(use);
			}
			for (int l = 0; l < this.FingerBlendArray.Length; l++)
			{
				this.FingerBlendArray[l].ChangeEnabeled(use);
			}
		}
		this.Apply();
	}

	public void Apply()
	{
		if (base.mgr.select_maid == null || base.mgr.select_maid.boMAN)
		{
			return;
		}
		Dictionary<string, string> maidStoreData = base.GetMaidStoreData(base.mgr.select_maid);
		if (!bool.Parse(maidStoreData["use"]))
		{
			return;
		}
		for (int i = 0; i < this.FingerBlendArray.Length; i++)
		{
			this.FingerBlendArray[i].Apply();
		}
	}

	public void OnBtnSave()
	{
		if (this.ik_mgr_ == null || base.mgr.select_maid == null)
		{
			return;
		}
		Dictionary<string, string> maidStoreData = base.GetMaidStoreData(base.mgr.select_maid);
		this.PanelSave.OpenPoseSaveMode(this.ik_mgr_.cache_bone_data.GetAnmBinary(bool.Parse(maidStoreData["use_mune_key_l"]), bool.Parse(maidStoreData["use_mune_key_r"])));
	}

	public void OnBtnReversal()
	{
		this.ik_mgr.Flip();
	}

	public override void OnMaidRemoveEvent(Maid maid)
	{
		if (maid != null && maid.boMAN)
		{
			maid = null;
		}
		this.DeleteIKManager(maid);
	}

	public override void OnMaidChangeEvent(Maid maid)
	{
		base.OnMaidChangeEvent(maid);
		if (maid == null)
		{
			this.ik_mgr_ = null;
		}
		Dictionary<string, string> dictionary;
		if (this.ik_mgr_ != null)
		{
			dictionary = base.GetMaidStoreData(this.ik_mgr_.maid);
			byte[] frameBinary = this.ik_mgr_.cache_bone_data.GetFrameBinary(bool.Parse(dictionary["use_mune_key_l"]), bool.Parse(dictionary["use_mune_key_r"]));
			if (bool.Parse(dictionary["use"]))
			{
				dictionary["pose_binary"] = Convert.ToBase64String(frameBinary);
			}
			else
			{
				dictionary["pose_binary"] = string.Empty;
			}
			IEnumerator enumerator = Enum.GetValues(typeof(IKManager.BoneSetType)).GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					object obj = enumerator.Current;
					IKManager.BoneSetType bone_set_type = (IKManager.BoneSetType)obj;
					this.ik_mgr_.SetRotateVisibleBoneSet(bone_set_type, false);
					this.ik_mgr_.SetTransAxisVisibleBoneSet(bone_set_type, false);
				}
			}
			finally
			{
				IDisposable disposable;
				if ((disposable = (enumerator as IDisposable)) != null)
				{
					disposable.Dispose();
				}
			}
			this.ik_mgr_.SetTransAxisVisibleRoot(false);
		}
		this.ik_mgr_ = PoseEditWindow.GetMaidIKManager(maid);
		dictionary = null;
		bool flag = maid != null && !maid.boMAN;
		if (flag)
		{
			dictionary = base.GetMaidStoreData(base.mgr.select_maid);
			this.CheckbtnUse.check = bool.Parse(dictionary["use"]);
			this.ctrl_type_ = (PoseEditWindow.ControlType)Enum.Parse(typeof(PoseEditWindow.ControlType), dictionary["select_control_type"]);
		}
		else
		{
			this.CheckbtnUse.check = false;
			this.ctrl_type_ = PoseEditWindow.ControlType.Null;
		}
		this.CheckbtnUse.enabled = flag;
		this.ChangeEnabeled(this.CheckbtnUse.check);
		if (this.ik_mgr_ != null && this.CheckbtnUse.check)
		{
			if (dictionary["pose_binary"] != string.Empty)
			{
				KeyValuePair<bool, bool> keyValuePair = this.ik_mgr_.cache_bone_data.SetFrameBinary(Convert.FromBase64String(dictionary["pose_binary"]));
				maid.body0.MuneYureL((float)((!keyValuePair.Key) ? 1 : 0));
				maid.body0.MuneYureR((float)((!keyValuePair.Value) ? 1 : 0));
			}
			this.Apply();
			this.ik_mgr.HistoryNew();
		}
		this.noCharaActive.ChangeMode(maid == null, true);
	}

	public override void OnDeserializeEvent()
	{
		List<string> maidStoreGuidList = base.mgr.GetMaidStoreGuidList();
		for (int i = 0; i < maidStoreGuidList.Count; i++)
		{
			Dictionary<string, string> maidStoreData = base.GetMaidStoreData(maidStoreGuidList[i]);
		}
	}

	public override void OnSerializeEvent()
	{
		base.OnSerializeEvent();
		if (base.mgr.select_maid == null || base.mgr.select_maid.boMAN)
		{
			return;
		}
		Dictionary<string, string> maidStoreData = base.GetMaidStoreData(base.mgr.select_maid);
		byte[] frameBinary = this.ik_mgr_.cache_bone_data.GetFrameBinary(bool.Parse(maidStoreData["use_mune_key_l"]), bool.Parse(maidStoreData["use_mune_key_r"]));
		maidStoreData = base.GetMaidStoreData(this.ik_mgr_.maid);
		if (bool.Parse(maidStoreData["use"]))
		{
			maidStoreData["pose_binary"] = Convert.ToBase64String(frameBinary);
		}
		else
		{
			maidStoreData["pose_binary"] = string.Empty;
		}
	}

	public WindowPartsFingerBlend GetWindowPartsFingerBlend(IKManager.BoneSetType bone_set_type)
	{
		Dictionary<IKManager.BoneSetType, WindowPartsFingerBlend.Type> dictionary = new Dictionary<IKManager.BoneSetType, WindowPartsFingerBlend.Type>();
		dictionary.Add(IKManager.BoneSetType.RightArmFinger, WindowPartsFingerBlend.Type.RightArm);
		dictionary.Add(IKManager.BoneSetType.LeftArmFinger, WindowPartsFingerBlend.Type.LeftArm);
		dictionary.Add(IKManager.BoneSetType.RightLegFinger, WindowPartsFingerBlend.Type.RightLeg);
		dictionary.Add(IKManager.BoneSetType.LeftLegFinger, WindowPartsFingerBlend.Type.LeftLeg);
		WindowPartsFingerBlend result = null;
		for (int i = 0; i < this.FingerBlendArray.Length; i++)
		{
			if (dictionary[bone_set_type] == this.FingerBlendArray[i].BlendType)
			{
				result = this.FingerBlendArray[i];
				break;
			}
		}
		return result;
	}

	private void DeleteIKManager(Maid maid)
	{
		GameObject x = GameObject.Find("PoseEditWorkParent");
		if (x == null)
		{
			x = new GameObject("PoseEditWorkParent");
		}
		if (maid == null)
		{
			return;
		}
		GameObject gameObject = GameObject.Find("PoseEditWorkParent/" + maid.status.guid);
		if (gameObject != null)
		{
			if (this.ik_mgr_ != null && this.ik_mgr_.maid == maid)
			{
				this.ik_mgr_ = null;
			}
			UnityEngine.Object.DestroyImmediate(gameObject);
		}
	}

	private void SetControlPanel(PoseEditWindow.ControlType type)
	{
		if (type == PoseEditWindow.ControlType.Null)
		{
			this.WindowSize = new Vector2(480f, 120f);
			GameObject[] array = new GameObject[]
			{
				this.GetControlPanelParentObject(PoseEditWindow.ControlType.Body),
				this.GetControlPanelParentObject(PoseEditWindow.ControlType.Hand),
				this.GetControlPanelParentObject(PoseEditWindow.ControlType.Leg)
			};
			foreach (GameObject gameObject in array)
			{
				gameObject.SetActive(false);
			}
		}
		else if (type == PoseEditWindow.ControlType.Body)
		{
			this.WindowSize = new Vector2(513f, 850f);
			GameObject[] array3 = new GameObject[]
			{
				this.GetControlPanelParentObject(PoseEditWindow.ControlType.Hand),
				this.GetControlPanelParentObject(PoseEditWindow.ControlType.Leg)
			};
			foreach (GameObject gameObject2 in array3)
			{
				gameObject2.SetActive(false);
			}
			this.GetControlPanelParentObject(PoseEditWindow.ControlType.Body).SetActive(true);
		}
		else if (type == PoseEditWindow.ControlType.Hand)
		{
			this.WindowSize = new Vector2(765f, 890f);
			GameObject[] array5 = new GameObject[]
			{
				this.GetControlPanelParentObject(PoseEditWindow.ControlType.Body),
				this.GetControlPanelParentObject(PoseEditWindow.ControlType.Leg)
			};
			foreach (GameObject gameObject3 in array5)
			{
				gameObject3.SetActive(false);
			}
			this.GetControlPanelParentObject(PoseEditWindow.ControlType.Hand).SetActive(true);
		}
		else if (type == PoseEditWindow.ControlType.Leg)
		{
			this.WindowSize = new Vector2(765f, 710f);
			GameObject[] array7 = new GameObject[]
			{
				this.GetControlPanelParentObject(PoseEditWindow.ControlType.Body),
				this.GetControlPanelParentObject(PoseEditWindow.ControlType.Hand)
			};
			foreach (GameObject gameObject4 in array7)
			{
				gameObject4.SetActive(false);
			}
			this.GetControlPanelParentObject(PoseEditWindow.ControlType.Leg).SetActive(true);
		}
		base.ResizeWindow();
	}

	private GameObject GetControlPanelParentObject(PoseEditWindow.ControlType type)
	{
		if (type == PoseEditWindow.ControlType.Body)
		{
			return UTY.GetChildObject(base.gameObject, "Parent/ContentParent/BodyPanel", false);
		}
		if (type == PoseEditWindow.ControlType.Hand)
		{
			return UTY.GetChildObject(base.gameObject, "Parent/ContentParent/HandPanel", false);
		}
		if (type == PoseEditWindow.ControlType.Leg)
		{
			return UTY.GetChildObject(base.gameObject, "Parent/ContentParent/LegPanel", false);
		}
		return null;
	}

	public IKManager ik_mgr
	{
		get
		{
			return this.ik_mgr_;
		}
	}

	public UIButton BtnSave;

	public PhotoModePoseSave PanelSave;

	public WFCheckBox CheckbtnUse;

	public UIWFTabPanel ControlSelectBtnTab;

	public UIButton BtnReversal;

	public WindowPartsBoneCheckBox[] RotateCheckBoxArray;

	public WindowPartsFingerBlend[] FingerBlendArray;

	private Dictionary<string, WFCheckBox> ikbox_visible_dic_ = new Dictionary<string, WFCheckBox>();

	private PhotoNoCharaActive noCharaActive;

	private PoseEditWindow.ControlType ctrl_type_;

	private IKManager ik_mgr_;

	private Dictionary<string, string> store_type_name_map_ = new Dictionary<string, string>();

	private enum ControlType
	{
		Null,
		Body,
		Hand,
		Leg
	}
}
