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

namespace Kasizuki
{
	public class KasizukiManSelectCtrl : MonoBehaviour
	{
		public Action<int> OnClickManTypeButton { get; set; }

		public ManDataType nowSelectManType { get; set; }

		private void Awake()
		{
			uGUIListViewer component = this.m_WindowManList.GetComponent<uGUIListViewer>();
			this.m_ButtonSelectedColor = (this.m_ButtonDefaultColor = component.tempItem.GetComponent<UIWidget>().color);
			this.m_ButtonSelectedColor.a = 1f;
			this.SetUpManList();
			this.SetUpManProfile();
			this.SetUpManInfo();
			this.m_WindowManInfo.SetActive(false);
		}

		private void SetUpManList()
		{
			KasizukiManSelectCtrl.<SetUpManList>c__AnonStorey0 <SetUpManList>c__AnonStorey = new KasizukiManSelectCtrl.<SetUpManList>c__AnonStorey0();
			<SetUpManList>c__AnonStorey.$this = this;
			this.m_ManListCache = new ObjectCacheDic();
			<SetUpManList>c__AnonStorey.dataArray = ManData.GetAllDatas(true, true);
			uGUIListViewer component = this.m_WindowManList.GetComponent<uGUIListViewer>();
			component.Show<UIButton>(<SetUpManList>c__AnonStorey.dataArray.Count, delegate(int index, UIButton button)
			{
				UILabel componentInChildren2 = button.GetComponentInChildren<UILabel>();
				componentInChildren2.text = <SetUpManList>c__AnonStorey.dataArray[index].drawName;
				EventDelegate.Add(button.onClick, delegate()
				{
					<SetUpManList>c__AnonStorey.OnClickManListButton(<SetUpManList>c__AnonStorey.dataArray[index].ID);
				});
				<SetUpManList>c__AnonStorey.$this.m_ManListCache.AddCache<UIButton>(<SetUpManList>c__AnonStorey.dataArray[index].ID.ToString(), button);
			});
			UIGrid component2 = component.parentItemArea.GetComponent<UIGrid>();
			if (component2)
			{
				component2.Reposition();
			}
			UIScrollView componentInChildren = component.GetComponentInChildren<UIScrollView>();
			if (componentInChildren)
			{
				componentInChildren.UpdatePosition();
			}
			componentInChildren.ResetPosition();
		}

		private void SetUpManProfile()
		{
			this.m_ManProfileCache = new ObjectCacheDic();
			this.m_ManProfileCache.CacheChildObject<UILabel>(this.m_WindowManProfile, "Text Free Comment", "フリーコメント");
			this.m_ManProfileCache.CacheChildObject<UILabel>(this.m_WindowManProfile, "Favorite/Value", "好きなプレイ");
		}

		private void SetUpManInfo()
		{
			this.m_ManInfoCache = new ObjectCacheDic();
			this.m_ManInfoCache.CacheChildObject<UILabel>(this.m_WindowManInfo, "PlayCount/Value", "プレイ回数");
			List<ItemData.Data> allDatas = ItemData.GetAllDatas(true);
			uGUIListViewer component = this.m_WindowManInfo.GetComponent<uGUIListViewer>();
			component.Show<UISprite>(allDatas.Count, delegate(int index, UISprite sprite)
			{
				UILabel componentInChildren2 = sprite.GetComponentInChildren<UILabel>();
				componentInChildren2.text = "未実装";
				this.ChangeButtonColor(sprite.gameObject, false);
			});
			UITable component2 = component.parentItemArea.GetComponent<UITable>();
			if (component2)
			{
				component2.Reposition();
			}
			UIScrollView componentInChildren = component.GetComponentInChildren<UIScrollView>();
			if (componentInChildren)
			{
				componentInChildren.UpdatePosition();
			}
			componentInChildren.ResetPosition();
		}

		public void OnClickManListButton(int selectedManID)
		{
			UIButton cache = this.m_ManListCache.GetCache<UIButton>(selectedManID.ToString());
			uGUIListViewer component = this.m_WindowManList.GetComponent<uGUIListViewer>();
			this.ChangeButtonArrayColor(component.ItemArray, cache.gameObject);
			this.nowSelectManType = ManData.GetData(selectedManID).manType;
			this.UpdateManProfile(selectedManID);
			this.UpdateManInfo();
			if (this.OnClickManTypeButton != null)
			{
				this.OnClickManTypeButton(selectedManID);
			}
		}

		private void UpdateManProfile(int manID)
		{
			ManData.Data data = ManData.GetData(manID);
			UILabel cache = this.m_ManProfileCache.GetCache<UILabel>("フリーコメント");
			cache.text = data.profileText;
			cache = this.m_ManProfileCache.GetCache<UILabel>("好きなプレイ");
			cache.text = data.favoritePlayText;
		}

		private void UpdateManInfo()
		{
			UILabel cache = this.m_ManInfoCache.GetCache<UILabel>("プレイ回数");
			cache.text = "未実装";
		}

		private void ChangeButtonArrayColor(GameObject[] buttonArray, GameObject target)
		{
			foreach (GameObject gameObject in buttonArray)
			{
				this.ChangeButtonColor(gameObject, gameObject == target);
			}
		}

		private void ChangeButtonColor(GameObject buttonObj, bool isHighLightColor)
		{
			if (buttonObj == null)
			{
				return;
			}
			UIButton component = buttonObj.GetComponent<UIButton>();
			if (component)
			{
				component.defaultColor = ((!isHighLightColor) ? this.m_ButtonDefaultColor : this.m_ButtonSelectedColor);
				return;
			}
			UIWidget component2 = buttonObj.GetComponent<UIWidget>();
			if (component2)
			{
				component2.color = ((!isHighLightColor) ? this.m_ButtonDefaultColor : this.m_ButtonSelectedColor);
				return;
			}
		}

		[SerializeField]
		private GameObject m_WindowManList;

		[SerializeField]
		private GameObject m_WindowManProfile;

		[SerializeField]
		private GameObject m_WindowManInfo;

		private ObjectCacheDic m_ManListCache;

		private ObjectCacheDic m_ManProfileCache;

		private ObjectCacheDic m_ManInfoCache;

		private Color m_ButtonDefaultColor;

		private Color m_ButtonSelectedColor;
	}
}
