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

public class BodyStatusMgr : BaseMgr<BodyStatusMgr>
{
	private void Start()
	{
		this.Init();
	}

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

	private void Init()
	{
		this.m_goPanel = base.GetComponentInParent<UIRoot>().transform.Find("BodyStatusPanel").gameObject;
		this.m_BodyPanel = UTY.GetChildObject(this.m_goPanel, "Panel1", false);
		this.m_MotionPanel = UTY.GetChildObject(this.m_goPanel, "Panel2", false);
		EventDelegate.Add(UTY.GetChildObject(this.m_MotionPanel, "Close", false).GetComponent<UIButton>().onClick, new EventDelegate.Callback(this.CloseMotionPanel));
		EventDelegate.Add(this.CreateItemObject(UTY.GetChildObject(this.m_MotionPanel, "Grid", false), "com3d2_poseicon0001.tex").onClick, new EventDelegate.Callback(this.PlayMotionYure1));
		EventDelegate.Add(this.CreateItemObject(UTY.GetChildObject(this.m_MotionPanel, "Grid", false), "com3d2_poseicon0002.tex").onClick, new EventDelegate.Callback(this.PlayMotionYure2));
		EventDelegate.Add(this.CreateItemObject(UTY.GetChildObject(this.m_MotionPanel, "Grid", false), "cm3d2_poseicon01.tex").onClick, new EventDelegate.Callback(this.PlayMotionNormal));
		UTY.GetChildObject(this.m_MotionPanel, "Grid", false).GetComponent<UIGrid>().Reposition();
		this.m_ctrl = base.GetCtrl<BodyStatusCtrl>();
		this.m_ctrl.Init(this, this.m_BodyPanel);
		this.ClosePanel();
	}

	public void OpenPanel(bool muneYurePanel)
	{
		this.UpdateBodyStatus();
		this.m_goPanel.SetActive(true);
		this.m_BodyPanel.SetActive(true);
		if (muneYurePanel)
		{
			this.m_MotionPanel.SetActive(true);
		}
	}

	public void UpdateBodyStatus()
	{
		Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
		BodyStatusCtrl.Status data = this.LoadData(maid);
		this.m_ctrl.SetData(data);
	}

	private BodyStatusCtrl.Status LoadData(Maid maid)
	{
		Status status = maid.status;
		status.UpdateBodyParam();
		return new BodyStatusCtrl.Status
		{
			height = status.body.height,
			weight = status.body.weight,
			bust = status.body.bust,
			cup = status.body.cup,
			waist = status.body.waist,
			hip = status.body.hip
		};
	}

	public void PlayMotionNormal()
	{
		WindowManager component = base.GetComponentInParent<UIRoot>().transform.Find("Window").gameObject.GetComponent<WindowManager>();
		PoseIconWindow component2 = component.GetWindow("ポーズ").GetComponent<PoseIconWindow>();
		bool visibleAutoCam = SceneEdit.Instance.viewReset.GetVisibleAutoCam();
		SceneEdit.Instance.viewReset.SetVisibleAutoCam(false);
		component2.Exec(this.normalPoseId);
		SceneEdit.Instance.viewReset.SetVisibleAutoCam(visibleAutoCam);
	}

	public void PlayMotionYure1()
	{
		WindowManager component = base.GetComponentInParent<UIRoot>().transform.Find("Window").gameObject.GetComponent<WindowManager>();
		PoseIconWindow component2 = component.GetWindow("ポーズ").GetComponent<PoseIconWindow>();
		bool visibleAutoCam = SceneEdit.Instance.viewReset.GetVisibleAutoCam();
		SceneEdit.Instance.viewReset.SetVisibleAutoCam(false);
		component2.Exec(this.yure1PoseId);
		SceneEdit.Instance.viewReset.SetVisibleAutoCam(visibleAutoCam);
	}

	public void PlayMotionYure2()
	{
		WindowManager component = base.GetComponentInParent<UIRoot>().transform.Find("Window").gameObject.GetComponent<WindowManager>();
		PoseIconWindow component2 = component.GetWindow("ポーズ").GetComponent<PoseIconWindow>();
		bool visibleAutoCam = SceneEdit.Instance.viewReset.GetVisibleAutoCam();
		SceneEdit.Instance.viewReset.SetVisibleAutoCam(false);
		component2.Exec(this.yure2PoseId);
		SceneEdit.Instance.viewReset.SetVisibleAutoCam(visibleAutoCam);
	}

	public void CloseBodyPanel()
	{
		this.m_BodyPanel.SetActive(false);
	}

	public void CloseMotionPanel()
	{
		this.m_MotionPanel.SetActive(false);
	}

	public void ClosePanel()
	{
		this.m_BodyPanel.SetActive(false);
		this.m_MotionPanel.SetActive(false);
		this.m_goPanel.SetActive(false);
	}

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

	[SerializeField]
	private int normalPoseId = 100;

	[SerializeField]
	private int yure1PoseId = 1000;

	[SerializeField]
	private int yure2PoseId = 1010;

	private BodyStatusCtrl m_ctrl;

	private GameObject m_BodyPanel;

	private GameObject m_MotionPanel;

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