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

public class PracticePuzzleNextSceneSelector : INextSceneSelector
{
	private BattleResultUIController _battleResultController;

	private bool _movingToMyPage;

	public PracticePuzzleNextSceneSelector(BattleResultUIController battleResultControl)
	{
		_battleResultController = battleResultControl;
		_movingToMyPage = false;
	}

	public void Setup(bool isWin, GameObject gameObject)
	{
		_battleResultController.RetryBtnObj.gameObject.SetActive(value: false);
		_battleResultController.MissionBtnObj.labels[0].text = Data.SystemText.Get("Puzzle_QuestSelect_Button");
		_battleResultController.MissionBtnObj.buttons[0].onClick.Clear();
		_battleResultController.MissionBtnObj.buttons[0].onClick.Add(new EventDelegate(delegate
		{
			SelectOtherPuzzle();
		}));
		_battleResultController.HomeBtnObj.labels[0].text = Data.SystemText.Get("Battle_0516");
		_battleResultController.HomeBtnObj.buttons[0].onClick.Clear();
		_battleResultController.HomeBtnObj.buttons[0].onClick.Add(new EventDelegate(delegate
		{
			MovePuzleLobby();
		}));
	}

	private void SelectOtherPuzzle()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_COMMON_BUTTON);
		UIManager.GetInstance().createInSceneCenterLoading();
		PracticePuzzleListTask task = new PracticePuzzleListTask();
		int practicePuzzleGroupId = GameMgr.GetIns().GetDataMgr().PracticePuzzleGroupId;
		task.SetParameter(practicePuzzleGroupId);
		UIManager.GetInstance().StartCoroutine(Toolbox.NetworkManager.Connect(task, delegate
		{
			List<string> loadList = PuzzleQuestSelectDialog.CollectResourcePath(task.PuzzleQuestInfo.DisplayDatas);
			UIManager.GetInstance().StartCoroutine(Toolbox.ResourcesManager.LoadAssetGroupAsync(loadList, delegate
			{
				UIManager.GetInstance().closeInSceneCenterLoading();
				PuzzleQuestSelectDialog.CreateDialog(task.PuzzleQuestInfo, delegate(PuzzleQuestData puzzleData, int difficulty)
				{
					ChangeSceneOtherPuzzle(puzzleData, difficulty);
				}).OnClose = delegate
				{
					Toolbox.ResourcesManager.RemoveAssetGroup(loadList);
				};
			}));
		}));
	}

	private void ChangeSceneOtherPuzzle(PuzzleQuestData puzzleData, int difficulty)
	{
		int groupId = GameMgr.GetIns().GetDataMgr().PracticePuzzleGroupId;
		UIManager.GetInstance().CreatFadeClose(delegate
		{
			UIManager.GetInstance().StartCoroutine(BattleManagerBase.GetIns().GetBattleControl().BattleEnd(delegate
			{
				UIManager.GetInstance().CreatFadeOpen();
				PuzzleUtil.SetPracticePuzzleData(groupId, puzzleData, difficulty, DataMgr.BattleType.Practice);
				PuzzleUtil.ChangeSceneToPracticePuzzle(puzzleData);
			}));
		});
	}

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

	private void MovePuzleLobby()
	{
		if (!_movingToMyPage)
		{
			_movingToMyPage = true;
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_CANCEL_TRANS);
			GameMgr.GetIns().GetBattleCtrl().BattleEnd(UIManager.ViewScene.PracticePuzzle);
		}
	}
}
