using System;
using UnityEngine;

public class OnaholeNodeMenuManager : OnaholeBaseNodeMenuManager
{
	public bool isOpen
	{
		get
		{
			return base.gameObject.activeSelf;
		}
	}

	private void Awake()
	{
		GameObject gameObject = this.menuButtonGrid.gameObject;
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "ステージ選択", OnaholeNodeMenuChildSecondRow.Mode.StageSelect.ToString(), true, true), new Action(this.CallSubMenu)));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "夜伽スキル", OnaholeNodeMenuChildSecondRow.Mode.SkillCategorySelect.ToString(), true, true), new Action(this.CallSubMenu)));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "コスチューム", OnaholeNodeMenuChildSecondRow.Mode.Costume.ToString(), true, true), new Action(this.CallSubMenu)));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "Chu-B Lip S2設定", OnaholeNodeMenuChildSecondRow.Mode.DeviceSetting.ToString(), true, true), new Action(this.CallSubMenu)));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "メイド感度", OnaholeNodeMenuChildSecondRow.Mode.MaidSensitivity.ToString(), true, true), new Action(this.CallSubMenu)));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "ピストン設定", OnaholeNodeMenuChildSecondRow.Mode.PistonSetting.ToString(), true, true), new Action(this.CallSubMenu)));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "男の透明度", OnaholeNodeMenuChildSecondRow.Mode.ManAlpha.ToString(), true, true), new Action(this.CallSubMenu)));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "オートモード", OnaholeNodeMenuChildSecondRow.Mode.AutoMode.ToString(), true, true), new Action(this.CallSubMenu)));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "オートフィニッシュ", OnaholeNodeMenuChildSecondRow.Mode.AutoFinish.ToString(), true, true), new Action(this.CallSubMenu)));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "オートリアクション", OnaholeNodeMenuChildSecondRow.Mode.AutoReaction.ToString(), true, true), new Action(this.CallSubMenu)));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "リアクションLevelUp", "reactionlevelup", true, false), new Action(this.ClickEmulate)));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "エディット", "edit", true, false), new Action(this.ClickEmulate)));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "液体を拭く", "releaseseieki", true, false), new Action(this.ClickEmulate)));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "カメラリセット", "camerareset", true, false), new Action(this.ClickEmulate)));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "夜伽終了", OnaholeNodeMenuChildSecondRow.Mode.YotogiEnd.ToString(), true, true), new Action(this.CallSubMenu)));
		this.reactionLevelUpButtonData = base.GetNodeButtonData("reactionlevelup");
		this.menuButtonGrid.Reposition();
		base.SetFocusButton(this.menuButtons[0]);
		this.isInputEnabled = false;
		this.changeInput = -1;
	}

	public void Open()
	{
		this.Close();
		this.changeInput = 1;
		if (!this.editButton.isEnabled)
		{
			base.GetNodeButtonData("edit").selectType = OnaholeNodeButton.SelectType.Disable;
		}
		base.SetFocusButton(this.menuButtons[0]);
		base.gameObject.SetActive(true);
		GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Click);
	}

	public void Close()
	{
		this.isInputEnabled = false;
		this.changeInput = -1;
		this.secondRow.Clear();
		this.thirdRow.Clear();
		base.gameObject.SetActive(false);
	}

	private void CallSubMenu()
	{
		if (base.selectedNodeButton == null)
		{
			return;
		}
		base.SetSelectedButton(base.selectedNodeButton);
		this.secondRow.CallMenu((OnaholeNodeMenuChildSecondRow.Mode)Enum.Parse(typeof(OnaholeNodeMenuChildSecondRow.Mode), base.selectedNodeButton.button.uniqueName));
		this.isInputEnabled = false;
	}

	private void ClickEmulate()
	{
		if (base.selectedNodeButton == null)
		{
			return;
		}
		UIButton uibutton = null;
		if (base.selectedNodeButton.button.uniqueName == "edit")
		{
			uibutton = this.editButton;
		}
		else if (base.selectedNodeButton.button.uniqueName == "releaseseieki")
		{
			uibutton = this.releaseSeiekiButton;
		}
		else if (base.selectedNodeButton.button.uniqueName == "camerareset")
		{
			uibutton = this.cameraResetButton;
		}
		else if (base.selectedNodeButton.button.uniqueName == "reactionlevelup")
		{
			uibutton = this.reactionLevelUpButton;
		}
		if (uibutton != null)
		{
			EventDelegate.Execute(uibutton.onClick);
		}
	}

	public void ReturnMenu()
	{
		if (base.selectedNodeButton != null)
		{
			base.selectedNodeButton.button.selectType = OnaholeNodeButton.SelectType.Focus;
		}
		this.changeInput = 1;
	}

	public void EndYotogi()
	{
		EventDelegate.Execute(this.yotogiEndButton.onClick);
	}

	protected override void OnEnterMenu()
	{
		base.OnEnterMenu();
		if (base.selectedNodeButton != null)
		{
			base.selectedNodeButton.enterEvent();
		}
	}

	protected override void OnCancelMenu()
	{
	}

	private void UpdateUIText()
	{
		NodeButtonData nodeButtonData = base.GetNodeButtonData(OnaholeNodeMenuChildSecondRow.Mode.AutoMode.ToString());
		OnaholeNodeButton onaholeNodeButton = nodeButtonData.button as OnaholeNodeButton;
		onaholeNodeButton.text = "オートモード:" + ((!this.autoPistonEnabled) ? "OFF" : "ON");
		nodeButtonData = base.GetNodeButtonData(OnaholeNodeMenuChildSecondRow.Mode.AutoFinish.ToString());
		onaholeNodeButton = (nodeButtonData.button as OnaholeNodeButton);
		onaholeNodeButton.text = "オートフィニッシュ:" + ((!this.autoFinishEnabled) ? "OFF" : "ON");
		nodeButtonData = base.GetNodeButtonData(OnaholeNodeMenuChildSecondRow.Mode.AutoReaction.ToString());
		onaholeNodeButton = (nodeButtonData.button as OnaholeNodeButton);
		onaholeNodeButton.text = "オートリアクション:" + ((!this.autoReaction) ? "OFF" : "ON");
		bool flag = false;
		if ((this.autoReaction && this.reactionLevelUpButtonData.button.selectType != OnaholeNodeButton.SelectType.Disable) || (this.reactionLevel == 2 && this.reactionLevelUpButtonData.button.selectType != OnaholeNodeButton.SelectType.Disable))
		{
			flag = true;
		}
		if (flag)
		{
			if (base.selectedNodeButton.button.uniqueName == this.reactionLevelUpButtonData.button.uniqueName)
			{
				for (int i = 0; i < this.menuButtons.Count; i++)
				{
					if (this.menuButtons[i].button.uniqueName == base.selectedNodeButton.button.uniqueName)
					{
						int num = i + 1;
						if (this.menuButtons.Count <= num)
						{
							num = 0;
						}
						base.SetFocusButton(this.menuButtons[num]);
						break;
					}
				}
			}
			this.reactionLevelUpButtonData.button.selectType = OnaholeNodeButton.SelectType.Disable;
		}
		else if (!this.autoReaction && this.reactionLevel != 2 && this.reactionLevelUpButtonData.button.selectType == OnaholeNodeButton.SelectType.Disable)
		{
			this.reactionLevelUpButtonData.button.selectType = OnaholeNodeButton.SelectType.None;
		}
	}

	protected override void Update()
	{
		if (base.inputDownKey)
		{
			base.NextItem();
		}
		else if (base.inputUpKey)
		{
			base.PrevItem();
		}
		else if (base.inputEnterKey || base.inputRightKye)
		{
			this.OnEnterMenu();
		}
		else if (base.inputCancelKey || base.inputLeftKey)
		{
			this.OnCancelMenu();
		}
		if (this.changeInput != -1)
		{
			this.isInputEnabled = (this.changeInput == 1);
		}
		this.changeInput = -1;
		this.UpdateUIText();
	}

	[SerializeField]
	private OnaholeNodeMenuChildSecondRow secondRow;

	[SerializeField]
	private OnaholeNodeMenuChildThirdRow thirdRow;

	[SerializeField]
	[Header("夜伽から貰ってくるコンポーネント群")]
	public YotogiPlayManagerWithChubLip playManager;

	[SerializeField]
	public YotogiAppearanceWithChubLip appearanceData;

	[SerializeField]
	public UndressingManager undressingManager;

	[SerializeField]
	private UIButton reactionLevelUpButton;

	[SerializeField]
	private UIButton editButton;

	[SerializeField]
	private UIButton releaseSeiekiButton;

	[SerializeField]
	private UIButton cameraResetButton;

	[SerializeField]
	private UIButton yotogiEndButton;

	private int changeInput;

	private NodeButtonData reactionLevelUpButtonData;

	public bool autoPistonEnabled;

	public bool autoFinishEnabled;

	public bool autoReaction;

	public int reactionLevel;
}
