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

public class PhotoMotionDataShortcutSetter : MonoBehaviour
{
	public float fadeSpeed
	{
		get
		{
			return this.m_FadeSpeed;
		}
		set
		{
			this.m_FadeSpeed = Mathf.Clamp(value, 0.001f, 1f);
		}
	}

	private PhotoMotionDataShortcut targetControllerRight
	{
		get
		{
			return this.m_TargetControllerRight;
		}
	}

	private PhotoMotionDataShortcut targetControllerLeft
	{
		get
		{
			return this.m_TargetControllerLeft;
		}
	}

	private PhotoMotionDataShortcut.ItemData nowSelectItem
	{
		get
		{
			return this.m_NowSelectItem;
		}
		set
		{
			this.m_NowSelectItem = value;
		}
	}

	private void Start()
	{
		this.m_FadeWindowShortcutButtonsRight = this.m_ButtonListShortcutRight.GetComponent<NGUIWindow>();
		this.m_FadeWindowShortcutButtonsLeft = this.m_ButtonListShortcutLeft.GetComponent<NGUIWindow>();
		this.m_FadeWindowMotionDataList = this.m_WindowListMotionData.GetComponent<NGUIWindow>();
		this.targetControllerRight.CreateItemList(8);
		this.targetControllerLeft.CreateItemList(8);
		PhotoMotionData.Create();
		List<PhotoMotionData> data2 = PhotoMotionData.data;
		ListViewerWindow windowListMotionData = this.m_WindowListMotionData;
		windowListMotionData.Show<PhotoMotionData, UIWFTabButton>(data2, delegate(int index, PhotoMotionData data, UIWFTabButton item)
		{
			UILabel componentInChildren = item.GetComponentInChildren<UILabel>();
			componentInChildren.text = data.name;
			EventDelegate.Add(item.onClick, delegate()
			{
				this.OnClickData(data);
			});
		});
		UIWFTabPanel component = windowListMotionData.viewer.parentItemArea.GetComponent<UIWFTabPanel>();
		if (component)
		{
			component.UpdateChildren();
		}
		this.m_ButtonListShortcutRight.Show<Transform>(this.targetControllerRight.itemDataList.Count, delegate(int index, Transform trans)
		{
			PhotoMotionDataShortcut.ItemData data = this.targetControllerRight.itemDataList[index];
			UILabel componentInChildren = trans.GetComponentInChildren<UILabel>();
			UIButton componentInChildren2 = trans.GetComponentInChildren<UIButton>();
			componentInChildren.text = data.GetDataName();
			EventDelegate.Add(componentInChildren2.onClick, delegate()
			{
				this.OnClickShortcutButton(data);
			});
			PhotoMotionDataShortcutSetter.ItemData itemData = trans.gameObject.AddComponent<PhotoMotionDataShortcutSetter.ItemData>();
			itemData.label = componentInChildren;
			this.m_ItemPairDic.Add(data, itemData);
		});
		this.m_ButtonListShortcutLeft.Show<Transform>(this.targetControllerLeft.itemDataList.Count, delegate(int index, Transform trans)
		{
			PhotoMotionDataShortcut.ItemData data = this.targetControllerLeft.itemDataList[index];
			UILabel componentInChildren = trans.GetComponentInChildren<UILabel>();
			UIButton componentInChildren2 = trans.GetComponentInChildren<UIButton>();
			componentInChildren.text = data.GetDataName();
			EventDelegate.Add(componentInChildren2.onClick, delegate()
			{
				this.OnClickShortcutButton(data);
			});
			PhotoMotionDataShortcutSetter.ItemData itemData = trans.gameObject.AddComponent<PhotoMotionDataShortcutSetter.ItemData>();
			itemData.label = componentInChildren;
			this.m_ItemPairDic.Add(data, itemData);
		});
		EventDelegate.Add(this.m_ButtonMotionListOK.onClick, new EventDelegate.Callback(this.OnClickMotionListOK));
	}

	private void OnClickData(PhotoMotionData data)
	{
		Debug.Log("モーション：" + data.name);
		if (this.nowSelectItem != null)
		{
			this.nowSelectItem.data = data;
		}
		PhotoMotionDataShortcutSetter.ItemData itemData;
		if (this.m_ItemPairDic != null && this.m_ItemPairDic.TryGetValue(this.nowSelectItem, out itemData))
		{
			itemData.label.text = this.nowSelectItem.GetDataName();
		}
		if (this.nowSelectItem != null)
		{
			if (this.targetControllerRight.itemDataList.Contains(this.nowSelectItem))
			{
				this.targetControllerRight.Emulate(this.nowSelectItem);
			}
			else if (this.targetControllerLeft.itemDataList.Contains(this.nowSelectItem))
			{
				this.targetControllerLeft.Emulate(this.nowSelectItem);
			}
			else
			{
				Debug.LogWarning("コントローラに存在しない項目を更新しているかも");
			}
		}
	}

	private void OnClickShortcutButton(PhotoMotionDataShortcut.ItemData item)
	{
		this.nowSelectItem = item;
		this.m_FadeWindowShortcutButtonsRight.Close(this.fadeSpeed, null);
		this.m_FadeWindowShortcutButtonsLeft.Close(this.fadeSpeed, null);
		this.WaitTime(this.fadeSpeed, delegate
		{
			this.m_FadeWindowMotionDataList.Open(this.fadeSpeed, null);
		});
		this.m_WindowListMotionData.Reposition();
		UIWFTabPanel component = this.m_WindowListMotionData.viewer.parentItemArea.GetComponent<UIWFTabPanel>();
		UIWFTabButton selectButtonObject = component.GetSelectButtonObject();
		if (selectButtonObject != null)
		{
			selectButtonObject.SetSelect(false);
		}
		component.ResetSelect();
		component.UpdateChildren();
	}

	private void OnClickMotionListOK()
	{
		this.m_FadeWindowMotionDataList.Close(this.fadeSpeed, null);
		this.WaitTime(this.fadeSpeed, delegate
		{
			this.m_FadeWindowShortcutButtonsRight.Open(this.fadeSpeed, null);
			this.m_FadeWindowShortcutButtonsLeft.Open(this.fadeSpeed, null);
		});
	}

	private void OnApplicationQuit()
	{
		this.m_IsQuittingApplication = true;
	}

	private void OnDisable()
	{
		if (this.m_IsQuittingApplication)
		{
			return;
		}
		Debug.LogWarning("デバッグ：モーション用コントローラ無効化");
		this.targetControllerRight.gameObject.SetActive(false);
		this.targetControllerLeft.gameObject.SetActive(false);
	}

	private void OnEnable()
	{
		Debug.LogWarning("デバッグ：モーション用コントローラ有効化");
		this.targetControllerRight.gameObject.SetActive(true);
		this.targetControllerLeft.gameObject.SetActive(true);
	}

	private void WaitTime(float time, Action onFinish)
	{
		base.StartCoroutine(this.CoWaitTime(time, onFinish));
	}

	private IEnumerator CoWaitTime(float time, Action onFinish)
	{
		yield return new WaitForSeconds(time);
		if (onFinish != null)
		{
			onFinish();
		}
		yield break;
	}

	[SerializeField]
	[Range(0.001f, 1f)]
	private float m_FadeSpeed = 0.25f;

	[SerializeField]
	private PhotoMotionDataShortcut m_TargetControllerRight;

	[SerializeField]
	private PhotoMotionDataShortcut m_TargetControllerLeft;

	[SerializeField]
	private CircleCommandUI m_ButtonListShortcutRight;

	[SerializeField]
	private CircleCommandUI m_ButtonListShortcutLeft;

	[SerializeField]
	private ListViewerWindow m_WindowListMotionData;

	[SerializeField]
	private UIButton m_ButtonMotionListOK;

	private NGUIWindow m_FadeWindowShortcutButtonsRight;

	private NGUIWindow m_FadeWindowShortcutButtonsLeft;

	private NGUIWindow m_FadeWindowMotionDataList;

	private PhotoMotionDataShortcut.ItemData m_NowSelectItem;

	private Dictionary<PhotoMotionDataShortcut.ItemData, PhotoMotionDataShortcutSetter.ItemData> m_ItemPairDic = new Dictionary<PhotoMotionDataShortcut.ItemData, PhotoMotionDataShortcutSetter.ItemData>();

	private bool m_IsQuittingApplication;

	public class ItemData : MonoBehaviour
	{
		public UILabel label
		{
			get
			{
				return this.m_Label;
			}
			set
			{
				this.m_Label = value;
			}
		}

		private UILabel m_Label;
	}
}
