using System.Collections.Generic;
using Cute;
using UnityEngine;
using Wizard;

public class QuestNextSceneSelector : INextSceneSelector
{
	private BattleResultUIController _battleResultNewControl;

	private bool _isMovingPage;

	private const float QUEST_RESULT_SHOW_TIME = 0.5f;

	private const int DECK_SELECT_UI_DEPTH = 40;

	public QuestNextSceneSelector(BattleResultUIController battleResultControl)
	{
		_battleResultNewControl = battleResultControl;
		_isMovingPage = false;
	}

	private void SetupSecretBoss()
	{
		_battleResultNewControl.QuestBattleResultObject.MyPageCamera.gameObject.SetActive(value: true);
		_battleResultNewControl.MissionBtnObj.buttons[0].gameObject.SetActive(value: false);
		_battleResultNewControl.gameObject.SetActive(value: true);
		_battleResultNewControl.RetryBtnObj.labels[0].text = Data.SystemText.Get("Battle_0204");
		_battleResultNewControl.RetryBtnObj.buttons[0].onClick.Clear();
		_battleResultNewControl.RetryBtnObj.buttons[0].onClick.Add(new EventDelegate(OnClickSecretBossRetry));
		_battleResultNewControl.HomeBtnObj.labels[0].text = Data.SystemText.Get("Quest_0016");
		_battleResultNewControl.HomeBtnObj.buttons[0].onClick.Clear();
		_battleResultNewControl.HomeBtnObj.buttons[0].onClick.Add(new EventDelegate(delegate
		{
			MoveToQuestSelectionPage();
		}));
	}

	private void OnClickSecretBossRetry()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_COMMON_BUTTON);
		GameMgr.GetIns().GetDataMgr().QuestFirstSelectType = QuestSelectionPage.FirstSelectType.BOSS_RUSH;
		BossRushClearDeckListTask task = new BossRushClearDeckListTask();
		UIManager.GetInstance().StartCoroutine(Toolbox.NetworkManager.Connect(task, delegate
		{
			Format format = Format.Hof;
			DeckGroupListData deckGroupListData = new DeckGroupListData(new DeckGroup(task.DeckList, format, DeckAttributeType.QuestSecretBoss));
			DeckSelectUIDialog deckSelectUIDialog = DeckSelectUIDialog.Create(Data.SystemText.Get("BossRush_0032"), deckGroupListData, format, DeckSelectUIDialog.eFormatChangeUIType.SingleFormat, isVisibleCreateNew: false, delegate(DialogBase dialog, DeckData deck)
			{
				OnSelectDeck(deck, task.AbilityDictionary[deck.GetDeckID()]);
			});
			deckSelectUIDialog.Dialog.SetLayer("MyPage");
			deckSelectUIDialog.Dialog.SetPanelDepth(40);
			deckSelectUIDialog.SetPanelDepth(41);
		}));
	}

	private void OnSelectDeck(DeckData deck, List<BossRushLobbyAbilityData> abilityList)
	{
		SecretBossDeckConfirmDialog.Create(deck, abilityList, isBattleAgain: true);
	}

	public void Setup(bool isWin, GameObject gameObject)
	{
		if (GameMgr.GetIns().GetDataMgr().m_BattleType == DataMgr.BattleType.SecretBossQuest)
		{
			SetupSecretBoss();
			return;
		}
		if (!BattleManagerBase.GetIns().IsPuzzleMgr && GameMgr.GetIns().GetDataMgr().m_BattleType != DataMgr.BattleType.BossRushQuest)
		{
			_battleResultNewControl.MissionBtnObj.labels[0].text = Data.SystemText.Get("Quest_0005");
			_battleResultNewControl.MissionBtnObj.buttons[0].onClick.Clear();
			_battleResultNewControl.MissionBtnObj.buttons[0].onClick.Add(new EventDelegate(delegate
			{
				GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_COMMON_BUTTON);
				_battleResultNewControl.QuestBattleResultObject.CreateQuestList();
			}));
		}
		else
		{
			_battleResultNewControl.MissionBtnObj.buttons[0].gameObject.SetActive(value: false);
		}
		_battleResultNewControl.HomeBtnObj.labels[0].text = Data.SystemText.Get("Quest_0016");
		_battleResultNewControl.HomeBtnObj.buttons[0].onClick.Clear();
		_battleResultNewControl.HomeBtnObj.buttons[0].onClick.Add(new EventDelegate(delegate
		{
			MoveToQuestSelectionPage();
		}));
		if (BattleManagerBase.GetIns().IsPuzzleMgr)
		{
			_battleResultNewControl.RetryBtnObj.labels[0].text = Data.SystemText.Get("Puzzle_QuestSelect_Button");
			_battleResultNewControl.RetryBtnObj.buttons[0].onClick.Clear();
			_battleResultNewControl.RetryBtnObj.buttons[0].onClick.Add(new EventDelegate(OnClickPuzzleButton));
			return;
		}
		if (GameMgr.GetIns().GetDataMgr().m_BattleType == DataMgr.BattleType.BossRushQuest)
		{
			_battleResultNewControl.RetryBtnObj.labels[0].text = Data.SystemText.Get("Battle_0203");
			_battleResultNewControl.RetryBtnObj.buttons[0].onClick.Clear();
			_battleResultNewControl.RetryBtnObj.buttons[0].onClick.Add(new EventDelegate(delegate
			{
				MoveToBossRushLobby();
			}));
			return;
		}
		if (isWin && GameMgr.GetIns().GetDataMgr().QuestBattleData.IsExtra)
		{
			_battleResultNewControl.RetryBtnObj.buttons[0].gameObject.SetActive(value: false);
			return;
		}
		_battleResultNewControl.gameObject.SetActive(value: true);
		_battleResultNewControl.RetryBtnObj.labels[0].text = Data.SystemText.Get("Battle_0204");
		_battleResultNewControl.RetryBtnObj.buttons[0].onClick.Clear();
		_battleResultNewControl.RetryBtnObj.buttons[0].onClick.Add(new EventDelegate(delegate
		{
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_COMMON_BUTTON);
			QuestDeckListTask task = new QuestDeckListTask();
			task.SetParameter(GameMgr.GetIns().GetDataMgr().QuestBattleData.QuestStageId);
			UIManager.GetInstance().StartCoroutine(Toolbox.NetworkManager.Connect(task, delegate
			{
				QuestSelectionPage.CreateQuestDeckDialog(task.DeckGroupListData, task.BonusFormatList, task.BonusClassList, isBattleAgain: true);
			}));
		}));
	}

	public void Show()
	{
		iTween.MoveTo(_battleResultNewControl.ButtonGrid.gameObject, iTween.Hash("position", _battleResultNewControl.DefaultPosDict["ButtonGrid"], "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
	}

	private void MoveToQuestSelectionPage()
	{
		if (!_isMovingPage)
		{
			_isMovingPage = true;
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_CANCEL_TRANS);
			GameMgr.GetIns().GetBattleCtrl().BattleEnd(UIManager.ViewScene.QuestSelectionPage);
		}
	}

	private void MoveToBossRushLobby()
	{
		if (!_isMovingPage)
		{
			_isMovingPage = true;
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_CANCEL_TRANS);
			GameMgr.GetIns().GetBattleCtrl().BattleEnd(UIManager.ViewScene.BossRushLobby);
		}
	}

	private void OnClickPuzzleButton()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_COMMON_BUTTON);
		UIManager.GetInstance().StartCoroutine(PuzzleUtil.OpenPuzzleSelectDialogCoroutine(OnDecidePuzzleQuest));
	}

	private void OnDecidePuzzleQuest(PuzzleQuestData data, int difficulty)
	{
		GameMgr.GetIns().GetSoundMgr().StopAllBGM(0.5f);
		UIManager.GetInstance().CreatFadeClose(delegate
		{
			UIManager.GetInstance().StartCoroutine(BattleManagerBase.GetIns().GetBattleControl().BattleEnd(delegate
			{
				UIManager.GetInstance().CreatFadeOpen();
				PuzzleUtil.SetPuzzleQuestData(data, difficulty, DataMgr.BattleType.Quest);
				PuzzleUtil.ChangeSceneToPuzzleQuest(data);
			}));
		});
	}
}
