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

public class OnaholeNodeMenuChildSecondRow : OnaholeBaseNodeMenuManager
{
	private void Awake()
	{
		this.Clear();
	}

	public void Clear()
	{
		this.isInputEnabled = (this.sliderInputMode = false);
		this.changeInput = -1;
		this.ClearButtonObject();
		this.mode = OnaholeNodeMenuChildSecondRow.Mode.SkillCategorySelect;
	}

	public void CallMenu(OnaholeNodeMenuChildSecondRow.Mode mode)
	{
		this.mode = mode;
		this.ClearButtonObject();
		if (mode == OnaholeNodeMenuChildSecondRow.Mode.StageSelect)
		{
			this.CallStageSlect();
		}
		else if (mode == OnaholeNodeMenuChildSecondRow.Mode.SkillCategorySelect)
		{
			this.CallSkillCategorySelect();
		}
		else if (mode == OnaholeNodeMenuChildSecondRow.Mode.Costume)
		{
			this.CallCostumeSetting();
		}
		else if (mode == OnaholeNodeMenuChildSecondRow.Mode.DeviceSetting)
		{
			this.CallChuBLipSetting();
		}
		else if (mode == OnaholeNodeMenuChildSecondRow.Mode.MaidSensitivity)
		{
			this.CallMaidSensitivitySetting();
		}
		else if (mode == OnaholeNodeMenuChildSecondRow.Mode.PistonSetting)
		{
			this.CallPistonSetting();
		}
		else if (mode == OnaholeNodeMenuChildSecondRow.Mode.ManAlpha)
		{
			this.CallManAlphaSetting();
		}
		else if (mode == OnaholeNodeMenuChildSecondRow.Mode.AutoMode)
		{
			this.CallGeneralBoolControl(this.nodeMenuManager.autoPistonEnabled);
		}
		else if (mode == OnaholeNodeMenuChildSecondRow.Mode.AutoFinish)
		{
			this.CallGeneralBoolControl(this.nodeMenuManager.autoFinishEnabled);
		}
		else if (mode == OnaholeNodeMenuChildSecondRow.Mode.AutoReaction)
		{
			this.CallGeneralBoolControl(this.nodeMenuManager.autoReaction);
		}
		else if (mode == OnaholeNodeMenuChildSecondRow.Mode.YotogiEnd)
		{
			this.CallYotogiEnd();
		}
		if (mode != OnaholeNodeMenuChildSecondRow.Mode.Costume)
		{
			this.menuButtonGrid.Reposition();
		}
		this.changeInput = 1;
	}

	private void CallStageSlect()
	{
	}

	public void CallSkillCategorySelect()
	{
	}

	private void CallCostumeSetting()
	{
		Action enterEvent = delegate()
		{
			UndressingManager.UndressingData undressingData = this.nodeMenuManager.undressingManager.GetUndressingData((UndressingManager.UnitType)Enum.Parse(typeof(UndressingManager.UnitType), base.selectedNodeButton.button.uniqueName));
			this.nodeMenuManager.undressingManager.OnClickButton(undressingData);
		};
		GameObject gameObject = this.menuButtonGrid.gameObject;
		foreach (UndressingManager.UnitData unitData in this.nodeMenuManager.undressingManager.UnitDataList)
		{
			OnaholeNodeIconButton onaholeNodeIconButton = base.CreateNodeIconMenu(gameObject, unitData.UnitType.ToString());
			onaholeNodeIconButton.SetCopyTargetSprite(unitData.ButtonObject.GetComponent<UISprite>());
			onaholeNodeIconButton.selectType = ((!unitData.ButtonObject.isEnabled) ? OnaholeNodeButton.SelectType.Disable : OnaholeNodeButton.SelectType.Focus);
			this.menuButtons.Add(new NodeButtonData(onaholeNodeIconButton, enterEvent));
		}
		base.SetFocusButton(this.menuButtons[0]);
		this.menuButtonGrid.arrangement = UIGrid.Arrangement.Horizontal;
		this.menuButtonGrid.cellWidth = (this.menuButtonGrid.cellHeight = 115f);
		this.menuButtonGrid.maxPerLine = 3;
		this.menuButtonGrid.Reposition();
		this.operationMap = new List<List<NodeButtonData>>();
		for (int i = 0; i < this.menuButtonGrid.maxPerLine; i++)
		{
			this.operationMap.Add(new List<NodeButtonData>());
		}
		int num = 0;
		foreach (NodeButtonData item in this.menuButtons)
		{
			List<NodeButtonData> list = this.operationMap[num];
			list.Add(item);
			num++;
			if (this.operationMap.Count <= num)
			{
				num = 0;
			}
		}
		this.menuButtonGrid.cellWidth = 0f;
		this.menuButtonGrid.arrangement = UIGrid.Arrangement.Vertical;
		this.menuButtonGrid.maxPerLine = 0;
	}

	private void CallChuBLipSetting()
	{
		GameObject gameObject = this.menuButtonGrid.gameObject;
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateNodeSlider(gameObject, OnaholeNodeSlider.SliderType.Sensitivity, "Sensitivity"), new Action(this.StartSliderInputMode)));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateNodeSlider(gameObject, OnaholeNodeSlider.SliderType.HoleSync, "HoleSync"), new Action(this.StartSliderInputMode)));
		base.SetFocusButton(this.menuButtons[0]);
		this.menuButtonGrid.cellHeight = (float)this.kGridCellHeightSliderItem;
	}

	private void CallMaidSensitivitySetting()
	{
		GameObject gameObject = this.menuButtonGrid.gameObject;
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateNodeSlider(gameObject, OnaholeNodeSlider.SliderType.MaidSensitivity, "MaidSensitivity"), new Action(this.StartSliderInputMode)));
		base.SetFocusButton(this.menuButtons[0]);
		this.menuButtonGrid.cellHeight = (float)this.kGridCellHeightSliderItem;
	}

	private void CallPistonSetting()
	{
		GameObject gameObject = this.menuButtonGrid.gameObject;
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateNodeSlider(gameObject, OnaholeNodeSlider.SliderType.HoleAutoSpeed, "HoleAutoSpeed"), new Action(this.StartSliderInputMode)));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateNodeSlider(gameObject, OnaholeNodeSlider.SliderType.HoleAutoInsertStartPos, "HoleAutoInsertStartPos"), new Action(this.StartSliderInputMode)));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateNodeSlider(gameObject, OnaholeNodeSlider.SliderType.HoleAutoInsertEndPos, "HoleAutoInsertEndPos"), new Action(this.StartSliderInputMode)));
		base.SetFocusButton(this.menuButtons[0]);
		this.menuButtonGrid.cellHeight = (float)this.kGridCellHeightSliderItem;
	}

	private void CallManAlphaSetting()
	{
		GameObject gameObject = this.menuButtonGrid.gameObject;
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateNodeSlider(gameObject, OnaholeNodeSlider.SliderType.ManAlpha, "ManAlpha"), new Action(this.StartSliderInputMode)));
		base.SetFocusButton(this.menuButtons[0]);
		this.menuButtonGrid.cellHeight = (float)this.kGridCellHeightSliderItem;
	}

	private void CallGeneralBoolControl(bool currentValue)
	{
		Action enterEvent = delegate()
		{
			this.OnCancelMenu();
		};
		GameObject gameObject = this.menuButtonGrid.gameObject;
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "ON", "true", true, false), enterEvent));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "OFF", "false", true, false), enterEvent));
		base.SetFocusButton((!currentValue) ? this.menuButtons[1] : this.menuButtons[0]);
		this.menuButtonGrid.cellHeight = (float)this.kGridCellHeightButtonItem;
	}

	private void CallYotogiEnd()
	{
		Action enterEvent = delegate()
		{
			if (bool.Parse(base.selectedNodeButton.button.uniqueName))
			{
				this.nodeMenuManager.EndYotogi();
			}
			else
			{
				this.OnCancelMenu();
			}
			this.isInputEnabled = false;
		};
		GameObject gameObject = this.menuButtonGrid.gameObject;
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "OK", "true", true, false), enterEvent));
		this.menuButtons.Add(new NodeButtonData(OnaholeBaseNodeMenuManager.CreateBasicNodeButton(gameObject, "CANCEL", "false", true, false), enterEvent));
		base.SetFocusButton(this.menuButtons[1]);
		this.menuButtonGrid.cellHeight = (float)this.kGridCellHeightButtonItem;
	}

	private void StartSliderInputMode()
	{
		NodeButtonData selectedNodeButton = base.selectedNodeButton;
		base.SetSelectedButton(selectedNodeButton);
		this.sliderInputMode = true;
	}

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

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

	protected override void OnCancelMenu()
	{
		base.OnCancelMenu();
		string uniqueName = base.selectedNodeButton.button.uniqueName;
		if (this.mode == OnaholeNodeMenuChildSecondRow.Mode.AutoMode)
		{
			this.nodeMenuManager.autoPistonEnabled = bool.Parse(uniqueName);
		}
		else if (this.mode == OnaholeNodeMenuChildSecondRow.Mode.AutoFinish)
		{
			this.nodeMenuManager.autoFinishEnabled = bool.Parse(uniqueName);
		}
		else if (this.mode == OnaholeNodeMenuChildSecondRow.Mode.AutoReaction)
		{
			this.nodeMenuManager.autoReaction = bool.Parse(uniqueName);
		}
		this.isInputEnabled = false;
		this.ClearButtonObject();
		this.nodeMenuManager.ReturnMenu();
	}

	private void ClearButtonObject()
	{
		Transform transform = this.menuButtonGrid.transform;
		GameObject[] array = new GameObject[transform.childCount];
		for (int i = 0; i < transform.childCount; i++)
		{
			array[i] = transform.GetChild(i).gameObject;
		}
		for (int j = 0; j < array.Length; j++)
		{
			UnityEngine.Object.DestroyImmediate(array[j]);
		}
		transform.DetachChildren();
		this.menuButtons.Clear();
		this.operationMap.Clear();
	}

	protected override void Update()
	{
		if (this.sliderInputMode)
		{
			NodeButtonData selectedNodeButton = base.selectedNodeButton;
			OnaholeNodeSlider onaholeNodeSlider = selectedNodeButton.button as OnaholeNodeSlider;
			if (onaholeNodeSlider != null)
			{
				if (base.inputRightKye)
				{
					onaholeNodeSlider.sliderValue += 0.1f;
				}
				else if (base.inputLeftKey)
				{
					onaholeNodeSlider.sliderValue -= 0.1f;
				}
				else if (base.inputCancelKey)
				{
					base.SetFocusButton(selectedNodeButton);
					this.sliderInputMode = false;
					base.OnCancelMenu();
				}
				else if (base.inputEnterKey)
				{
					base.SetFocusButton(selectedNodeButton);
					this.sliderInputMode = false;
					base.OnEnterMenu();
				}
			}
		}
		else if (this.mode != OnaholeNodeMenuChildSecondRow.Mode.Costume)
		{
			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();
			}
		}
		else if (base.inputDownKey)
		{
			base.NextItem();
		}
		else if (base.inputUpKey)
		{
			base.PrevItem();
		}
		else if (base.inputRightKye)
		{
			base.RightItem();
		}
		else if (base.inputLeftKey)
		{
			bool flag = false;
			int num = 0;
			while (num < this.operationMap[0].Count && !flag)
			{
				NodeButtonData nodeButtonData = this.operationMap[0][num];
				if (nodeButtonData.button.selectType == OnaholeNodeButton.SelectType.Focus || nodeButtonData.button.selectType == OnaholeNodeButton.SelectType.Select)
				{
					flag = true;
				}
				num++;
			}
			if (flag)
			{
				this.OnCancelMenu();
			}
			else
			{
				base.LeftItem();
			}
		}
		else if (base.inputEnterKey)
		{
			this.OnEnterMenu();
		}
		else if (base.inputCancelKey)
		{
			this.OnCancelMenu();
		}
		if (this.changeInput != -1)
		{
			this.isInputEnabled = (this.changeInput == 1);
		}
		this.changeInput = -1;
	}

	private readonly int kGridCellHeightButtonItem = 45;

	private readonly int kGridCellHeightSliderItem = 100;

	[SerializeField]
	public OnaholeNodeMenuManager nodeMenuManager;

	[SerializeField]
	private OnaholeNodeMenuChildThirdRow thirdRow;

	private OnaholeNodeMenuChildSecondRow.Mode mode;

	private int changeInput;

	private bool sliderInputMode;

	public enum Mode
	{
		StageSelect,
		SkillCategorySelect,
		Costume,
		DeviceSetting,
		MaidSensitivity,
		PistonSetting,
		ManAlpha,
		AutoMode,
		AutoFinish,
		AutoReaction,
		YotogiEnd
	}
}
