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

public class OnaholeBaseNodeMenuManager : MonoBehaviour
{
	public static OnaholeNodeButton CreateBasicNodeButton(GameObject parent, string text, string uniqueName, bool sizeSmall, bool drawNextMark)
	{
		GameObject gameObject = Utility.CreatePrefab(parent, "SceneYotogi/CBL/BasicNodeMenu", true);
		OnaholeNodeButton component = gameObject.GetComponent<OnaholeNodeButton>();
		component.selectType = OnaholeNodeButton.SelectType.None;
		component.text = text;
		component.uniqueName = uniqueName;
		component.visibleNextMarker = drawNextMark;
		component.sizeModeBig = !sizeSmall;
		return component;
	}

	public static OnaholeNodeSlider CreateNodeSlider(GameObject parent, OnaholeNodeSlider.SliderType type, string uniqueName)
	{
		GameObject gameObject = Utility.CreatePrefab(parent, "SceneYotogi/CBL/NodeSliderMenu", true);
		OnaholeNodeSlider component = gameObject.GetComponent<OnaholeNodeSlider>();
		component.selectType = OnaholeNodeButton.SelectType.None;
		component.uniqueName = uniqueName;
		component.SetSliderType(type);
		return component;
	}

	public OnaholeNodeIconButton CreateNodeIconMenu(GameObject parent, string uniqueName)
	{
		GameObject gameObject = Utility.CreatePrefab(parent, "SceneYotogi/CBL/NodeIconMenu", true);
		OnaholeNodeIconButton component = gameObject.GetComponent<OnaholeNodeIconButton>();
		component.selectType = OnaholeNodeButton.SelectType.None;
		component.uniqueName = uniqueName;
		return component;
	}

	public bool inputUpKey
	{
		get
		{
			return this.isInputEnabled && base.gameObject.activeInHierarchy && YotogiManager.instans.inputCBLUpKey;
		}
	}

	public bool inputDownKey
	{
		get
		{
			return this.isInputEnabled && base.gameObject.activeInHierarchy && YotogiManager.instans.inputCBLDownKey;
		}
	}

	public bool inputRightKye
	{
		get
		{
			return this.isInputEnabled && base.gameObject.activeInHierarchy && YotogiManager.instans.inputCBLRightKey;
		}
	}

	public bool inputLeftKey
	{
		get
		{
			return this.isInputEnabled && base.gameObject.activeInHierarchy && YotogiManager.instans.inputCBLLeftKey;
		}
	}

	public bool inputEnterKey
	{
		get
		{
			return this.isInputEnabled && base.gameObject.activeInHierarchy && YotogiManager.instans.inputCBLCancelKey;
		}
	}

	public bool inputCancelKey
	{
		get
		{
			return this.isInputEnabled && base.gameObject.activeInHierarchy && YotogiManager.instans.inputCBLEnterKey;
		}
	}

	public NodeButtonData selectedNodeButton
	{
		get
		{
			foreach (NodeButtonData nodeButtonData in this.menuButtons)
			{
				if (nodeButtonData.selectType == OnaholeNodeButton.SelectType.Select || nodeButtonData.selectType == OnaholeNodeButton.SelectType.Focus)
				{
					return nodeButtonData;
				}
			}
			return null;
		}
	}

	public void NextItem()
	{
		List<NodeButtonData> list = this.menuButtons;
		if (this.operationMap != null && 0 < this.operationMap.Count)
		{
			foreach (List<NodeButtonData> list2 in this.operationMap)
			{
				foreach (NodeButtonData nodeButtonData in list2)
				{
					if (nodeButtonData.selectType == OnaholeNodeButton.SelectType.Select || nodeButtonData.selectType == OnaholeNodeButton.SelectType.Focus)
					{
						list = list2;
						break;
					}
				}
			}
		}
		NodeButtonData nodeButtonData2 = null;
		for (int i = 0; i < list.Count; i++)
		{
			if (list[i].selectType == OnaholeNodeButton.SelectType.Select || list[i].selectType == OnaholeNodeButton.SelectType.Focus)
			{
				nodeButtonData2 = list[i];
				int num = i;
				for (;;)
				{
					num++;
					if (list.Count <= num)
					{
						num = -1;
					}
					else if (list[num].selectType != OnaholeNodeButton.SelectType.Disable)
					{
						break;
					}
				}
				nodeButtonData2 = list[num];
				break;
			}
		}
		if (nodeButtonData2 != null)
		{
			this.SetFocusButton(nodeButtonData2);
			GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Hover);
		}
	}

	public void PrevItem()
	{
		List<NodeButtonData> list = this.menuButtons;
		if (this.operationMap != null && 0 < this.operationMap.Count)
		{
			foreach (List<NodeButtonData> list2 in this.operationMap)
			{
				foreach (NodeButtonData nodeButtonData in list2)
				{
					if (nodeButtonData.selectType == OnaholeNodeButton.SelectType.Select || nodeButtonData.selectType == OnaholeNodeButton.SelectType.Focus)
					{
						list = list2;
						break;
					}
				}
			}
		}
		NodeButtonData nodeButtonData2 = null;
		for (int i = 0; i < list.Count; i++)
		{
			if (list[i].selectType == OnaholeNodeButton.SelectType.Select || list[i].selectType == OnaholeNodeButton.SelectType.Focus)
			{
				nodeButtonData2 = list[i];
				int num = i;
				for (;;)
				{
					num--;
					if (num < 0)
					{
						num = list.Count;
					}
					else if (list[num].selectType != OnaholeNodeButton.SelectType.Disable)
					{
						break;
					}
				}
				nodeButtonData2 = list[num];
				break;
			}
		}
		if (nodeButtonData2 != null)
		{
			this.SetFocusButton(nodeButtonData2);
			GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Hover);
		}
	}

	public void RightItem()
	{
		if (this.operationMap == null || this.operationMap.Count <= 1)
		{
			return;
		}
		List<NodeButtonData> list = null;
		for (int i = 0; i < this.operationMap.Count; i++)
		{
			for (int j = 0; j < this.operationMap[i].Count; j++)
			{
				NodeButtonData nodeButtonData = this.operationMap[i][j];
				if (nodeButtonData.selectType == OnaholeNodeButton.SelectType.Select || nodeButtonData.selectType == OnaholeNodeButton.SelectType.Focus)
				{
					list = new List<NodeButtonData>();
					for (int k = 0; k < this.operationMap.Count; k++)
					{
						list.Add(this.operationMap[k][j]);
					}
					break;
				}
			}
			if (list != null)
			{
				break;
			}
		}
		if (list == null)
		{
			return;
		}
		NodeButtonData nodeButtonData2 = null;
		for (int l = 0; l < list.Count; l++)
		{
			if (list[l].selectType == OnaholeNodeButton.SelectType.Select || list[l].selectType == OnaholeNodeButton.SelectType.Focus)
			{
				nodeButtonData2 = list[l];
				int num = l;
				for (;;)
				{
					num++;
					if (list.Count <= num)
					{
						num = -1;
					}
					else if (list[num].selectType != OnaholeNodeButton.SelectType.Disable)
					{
						break;
					}
				}
				nodeButtonData2 = list[num];
				break;
			}
		}
		if (nodeButtonData2 != null)
		{
			this.SetFocusButton(nodeButtonData2);
			GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Hover);
		}
	}

	public void LeftItem()
	{
		if (this.operationMap == null || this.operationMap.Count <= 1)
		{
			return;
		}
		List<NodeButtonData> list = null;
		for (int i = 0; i < this.operationMap.Count; i++)
		{
			for (int j = 0; j < this.operationMap[i].Count; j++)
			{
				NodeButtonData nodeButtonData = this.operationMap[i][j];
				if (nodeButtonData.selectType == OnaholeNodeButton.SelectType.Select || nodeButtonData.selectType == OnaholeNodeButton.SelectType.Focus)
				{
					list = new List<NodeButtonData>();
					for (int k = 0; k < this.operationMap.Count; k++)
					{
						list.Add(this.operationMap[k][j]);
					}
					break;
				}
			}
			if (list != null)
			{
				break;
			}
		}
		if (list == null)
		{
			return;
		}
		NodeButtonData nodeButtonData2 = null;
		for (int l = 0; l < list.Count; l++)
		{
			if (list[l].selectType == OnaholeNodeButton.SelectType.Select || list[l].selectType == OnaholeNodeButton.SelectType.Focus)
			{
				nodeButtonData2 = list[l];
				int num = l;
				for (;;)
				{
					num--;
					if (num < 0)
					{
						num = list.Count;
					}
					else if (list[num].selectType != OnaholeNodeButton.SelectType.Disable)
					{
						break;
					}
				}
				nodeButtonData2 = list[num];
				break;
			}
		}
		if (nodeButtonData2 != null)
		{
			this.SetFocusButton(nodeButtonData2);
			GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Hover);
		}
	}

	protected virtual void OnEnterMenu()
	{
		GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Click);
	}

	protected virtual void OnCancelMenu()
	{
		GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Click);
	}

	protected virtual void Update()
	{
		if (this.inputDownKey)
		{
			this.NextItem();
		}
		else if (this.inputUpKey)
		{
			this.PrevItem();
		}
	}

	protected NodeButtonData GetNodeButtonData(string uniquName)
	{
		foreach (NodeButtonData nodeButtonData in this.menuButtons)
		{
			if (nodeButtonData.button.uniqueName == uniquName)
			{
				return nodeButtonData;
			}
		}
		return null;
	}

	protected void SetFocusButton(NodeButtonData buttonData)
	{
		if (buttonData == null)
		{
			return;
		}
		foreach (NodeButtonData nodeButtonData in this.menuButtons)
		{
			if (nodeButtonData.button.selectType != OnaholeNodeButton.SelectType.Disable)
			{
				nodeButtonData.button.selectType = ((buttonData.button != nodeButtonData.button) ? OnaholeNodeButton.SelectType.None : OnaholeNodeButton.SelectType.Focus);
			}
		}
	}

	protected void SetSelectedButton(NodeButtonData buttonData)
	{
		if (buttonData == null)
		{
			return;
		}
		foreach (NodeButtonData nodeButtonData in this.menuButtons)
		{
			if (nodeButtonData.button.selectType != OnaholeNodeButton.SelectType.Disable)
			{
				nodeButtonData.button.selectType = ((buttonData.button != nodeButtonData.button) ? OnaholeNodeButton.SelectType.None : OnaholeNodeButton.SelectType.Select);
			}
		}
	}

	[SerializeField]
	protected UIGrid menuButtonGrid;

	protected List<NodeButtonData> menuButtons = new List<NodeButtonData>();

	protected List<List<NodeButtonData>> operationMap = new List<List<NodeButtonData>>();

	public bool isInputEnabled;
}
