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

public class FreeModeItemList : MonoBehaviour
{
	public void Awake()
	{
		this.grid_ = UTY.GetChildObject(base.gameObject, "ListParent/MaskGroup/Contents/Grid", false).GetComponent<UIGrid>();
		this.scroll_view_ = UTY.GetChildObject(base.gameObject, "ListParent/MaskGroup/Contents", false).GetComponent<UIScrollView>();
		this.tab_pabel_ = UTY.GetChildObject(base.gameObject, "ListParent/MaskGroup/Contents/Grid", false).GetComponent<UIWFTabPanel>();
		this.info_label_ = UTY.GetChildObject(base.gameObject, "DetailParent/DetailBlock/Text", false).GetComponent<UILabel>();
		UIGrid component = UTY.GetChildObject(base.gameObject, "DetailParent/ConditionBlock/GridParent", false).GetComponent<UIGrid>();
		List<Transform> childList = component.GetChildList();
		for (int i = 0; i < childList.Count; i++)
		{
			this.condition_label_list_.Add(UTY.GetChildObject(childList[i].gameObject, "Message", false).GetComponent<UILabel>());
		}
	}

	public bool SetList(AbstractFreeModeItem[] item_list)
	{
		if (0 < this.grid_.gameObject.transform.childCount || item_list == null || item_list.Length <= 0)
		{
			return false;
		}
		this.select_item_data_ = null;
		UIWFTabButton uiwftabButton = null;
		for (int i = 0; i < item_list.Length; i++)
		{
			GameObject gameObject = Utility.CreatePrefab(this.grid_.gameObject, "SceneFreeModeSelect/FreeModeItemButton", true);
			UTY.GetChildObject(gameObject, "Name", false).GetComponent<UILabel>().text = item_list[i].title;
			UIWFTabButton component = gameObject.GetComponent<UIWFTabButton>();
			component.isEnabled = false;
			EventDelegate.Add(component.onSelect, new EventDelegate.Callback(this.OnSelectItem));
			UIEventTrigger component2 = gameObject.GetComponent<UIEventTrigger>();
			EventDelegate eventDelegate = new EventDelegate(this, "OnMouseHoverIn");
			eventDelegate.parameters[0].value = component;
			EventDelegate.Add(component2.onHoverOver, eventDelegate);
			EventDelegate.Add(component2.onHoverOut, new EventDelegate.Callback(this.OnMouseHoverOut));
			component2 = UTY.GetChildObject(gameObject, "HitRect", false).GetComponent<UIEventTrigger>();
			eventDelegate = new EventDelegate(this, "OnMouseHoverIn");
			eventDelegate.parameters[0].value = component;
			EventDelegate.Add(component2.onHoverOver, eventDelegate);
			EventDelegate.Add(component2.onHoverOut, new EventDelegate.Callback(this.OnMouseHoverOut));
			bool is_enabled = item_list[i].is_enabled;
			if (is_enabled)
			{
				component.isEnabled = true;
				UTY.GetChildObject(gameObject, "HitRect", false).SetActive(false);
				if (uiwftabButton == null)
				{
					uiwftabButton = component;
				}
			}
			else
			{
				component.isEnabled = false;
				UTY.GetChildObject(gameObject, "HitRect", false).SetActive(true);
			}
			this.item_obj_dic_.Add(gameObject, item_list[i]);
		}
		this.grid_.Reposition();
		this.scroll_view_.ResetPosition();
		this.tab_pabel_.UpdateChildren();
		if (uiwftabButton != null)
		{
			this.tab_pabel_.Select(uiwftabButton);
		}
		this.UpdateInfo(this.select_item_data_);
		return uiwftabButton != null;
	}

	public void OnSelectItem()
	{
		if (!UIWFTabButton.current.isSelected || !this.item_obj_dic_.ContainsKey(UIWFTabButton.current.gameObject))
		{
			return;
		}
		this.select_item_data_ = this.item_obj_dic_[UIWFTabButton.current.gameObject];
		this.UpdateInfo(this.select_item_data_);
	}

	private void OnMouseHoverIn(UIWFTabButton tab_btn)
	{
		this.UpdateInfo(this.item_obj_dic_[tab_btn.gameObject]);
	}

	private void OnMouseHoverOut()
	{
		this.UpdateInfo(this.select_item_data_);
	}

	public void UpdateInfo(AbstractFreeModeItem select_item_dat)
	{
		if (select_item_dat == null)
		{
			this.info_label_.text = string.Empty;
			for (int i = 0; i < this.condition_label_list_.Count; i++)
			{
				this.condition_label_list_[i].transform.parent.gameObject.SetActive(false);
			}
		}
		else
		{
			this.info_label_.text = select_item_dat.text;
			for (int j = 0; j < this.condition_label_list_.Count; j++)
			{
				if (j < select_item_dat.condition_texts.Length)
				{
					this.condition_label_list_[j].transform.parent.gameObject.SetActive(true);
					this.condition_label_list_[j].text = select_item_dat.condition_texts[j];
				}
				else
				{
					this.condition_label_list_[j].transform.parent.gameObject.SetActive(false);
				}
			}
		}
	}

	public AbstractFreeModeItem select_item_data
	{
		get
		{
			return this.select_item_data_;
		}
		set
		{
			this.select_item_data_ = value;
		}
	}

	private Dictionary<GameObject, AbstractFreeModeItem> item_obj_dic_ = new Dictionary<GameObject, AbstractFreeModeItem>();

	private UIGrid grid_;

	private UIScrollView scroll_view_;

	private UIWFTabPanel tab_pabel_;

	private UILabel info_label_;

	private List<UILabel> condition_label_list_ = new List<UILabel>();

	private AbstractFreeModeItem select_item_data_;
}
