using System;
using UnityEngine;
using UnityEngine.UI;

public class VRTrophyMenu : MonoBehaviour
{
	private void Start()
	{
	}

	private void UpdateTrohyUI()
	{
		this.m_PrefabElement.SetActive(false);
		string text = "vrcom_trophy.nei";
		if (!GameUty.FileSystem.IsExistentFile(text))
		{
			NDebug.Assert("表がありません。" + text, false);
		}
		using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
		{
			using (CsvParser csvParser = new CsvParser())
			{
				bool condition = csvParser.Open(afileBase);
				NDebug.Assert(condition, text + "\nopen failed.");
				for (int i = 1; i < csvParser.max_cell_y; i++)
				{
					if (csvParser.IsCellToExistData(0, i))
					{
						int num = 0;
						int cellAsInteger = csvParser.GetCellAsInteger(num++, i);
						string cellAsString = csvParser.GetCellAsString(num++, i);
						string cellAsString2 = csvParser.GetCellAsString(num++, i);
						string cellAsString3 = csvParser.GetCellAsString(num++, i);
						string cellAsString4 = csvParser.GetCellAsString(num++, i);
						bool isGet = false;
						if (GameMain.Instance.CharacterMgr.GetMaid(0) != null)
						{
							isGet = (GameMain.Instance.CharacterMgr.GetMaid(0).status.GetFlag(cellAsString) >= 1);
						}
						VRTrophyMenu.ElementData elementData = this.CreateElement(isGet);
						elementData.TextName.text = cellAsString2;
						elementData.TextFlag.text = cellAsString3;
						elementData.TextItem.text = cellAsString4;
					}
				}
			}
		}
	}

	private VRTrophyMenu.ElementData CreateElement(bool isGet)
	{
		GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_PrefabElement);
		gameObject.SetActive(true);
		gameObject.transform.SetParent(this.m_Content, false);
		VRTrophyMenu.ElementData elementData = new VRTrophyMenu.ElementData();
		elementData.TextName = gameObject.transform.Find("Text Trohy Name").GetComponent<Text>();
		elementData.TextFlag = gameObject.transform.Find("Text Trohy Flag").GetComponent<Text>();
		elementData.TextItem = gameObject.transform.Find("Text Trohy Item").GetComponent<Text>();
		Color targetColor = (!isGet) ? (Color.white * 0.75f) : Color.white;
		Graphic[] componentsInChildren = gameObject.GetComponentsInChildren<Graphic>();
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			componentsInChildren[i].CrossFadeColor(targetColor, 0f, false, false);
		}
		return elementData;
	}

	private void OnEnable()
	{
		this.UpdateTrohyUI();
	}

	private void OnDisable()
	{
		if (base.gameObject == null)
		{
			return;
		}
		if (this.m_Content == null)
		{
			return;
		}
		if (this.m_PrefabElement == null)
		{
			return;
		}
		for (int i = 0; i < this.m_Content.childCount; i++)
		{
			GameObject gameObject = this.m_Content.GetChild(i).gameObject;
			if (!(gameObject == this.m_PrefabElement))
			{
				UnityEngine.Object.Destroy(gameObject);
			}
		}
	}

	[SerializeField]
	[Tooltip("トロフィーの概要を表示する要素（プレハブ）")]
	private GameObject m_PrefabElement;

	[SerializeField]
	[Tooltip("説明する要素を並べるUI")]
	private RectTransform m_Content;

	private class ElementData
	{
		public ElementData()
		{
			this.TextName = null;
			this.TextFlag = null;
			this.TextItem = null;
		}

		public Text TextName;

		public Text TextFlag;

		public Text TextItem;
	}
}
