using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Cute;
using UnityEngine;
using Wizard.DeckCardEdit;
using Wizard.Lottery;

namespace Wizard.Scripts.Network.Data.TaskData.BuildDeckPurchase;

public class BuildDeckPurchasePage : BaseShopPurchasePage
{
	private const int DEFAULT_INDEX = 0;

	private const string LAYER_DIALOG_PRODUCT_DETAIL = "MyPage";

	private const int SORTODER_DIALOG_PRODUCT_DETAIL = 2;

	private const int DEPTH_DIALOG_PRODUCT_DETAIL = 140;

	private const string LAYER_DIALOG_PURCHASE_REWARD = "MyPage";

	private const int SORTODER_DIALOG_PURCHASE_REWARD = 2;

	private const int DEPTH_DIALOG_PURCHASE_REWARD = 140;

	[SerializeField]
	private GameObject _prefabDialogSelectBuyMeans;

	[SerializeField]
	private PurchaseConfirm _prefabDialogPurchaseConfirm;

	[SerializeField]
	private BuildDeckDetailWindow _prefabDialogBuildDeckDetail;

	[SerializeField]
	private CardDetailUI _cardDetailPrefab;

	private CardDetailUI _cardDetail;

	[SerializeField]
	private UICardList _cardListPrefab;

	private UICardList _uiCardListClass;

	[SerializeField]
	private ShopDrumrollScrollManager _drumrollManager;

	[SerializeField]
	private UIButton _btnSeriesRewards;

	[SerializeField]
	private UIAnchor _achiveAnchor;

	private BuildDeckSeriesPurchaseInfo _selectSeriesInfo;

	private BuildDeckProductInfo _purchaseProductInfo;

	private string _purchaseDeckName = string.Empty;

	private int _purchaseDeckClassId;

	private List<int> _purchaseDeckCardIds;

	private BuildDeckPlate _selectPlate;

	private DialogBase _dialogPurchaseConfirm;

	private DialogBase _dialogSelectBuyMeans;

	private DialogBase _dialogProductDetail;

	private DialogBase _dialogCrystalShortage;

	private BuildDeckBuyTask _buyTask;

	private bool _isBuyConnect;

	private static int _autoShowBuildDeckProductId;

	private static bool _autoShowBuildDeckEnable;

	private Format _deckCreateFormat;

	private List<string> _loadResource = new List<string>();

	private int _addShowSeriesId;

	[SerializeField]
	private NotificatonAnimation _notificationAnimationPrefab;

	[SerializeField]
	private GameObject _achieveLog;

	private NotificatonAnimation _notificationAnimation;

	public static void BuildDeckConfirmDialogShow(int productID)
	{
		_autoShowBuildDeckEnable = true;
		_autoShowBuildDeckProductId = productID;
	}

	public override void onFirstStart()
	{
		_cardDetail = UnityEngine.Object.Instantiate(_cardDetailPrefab);
		_cardDetail.transform.parent = base.transform;
		_cardDetail.transform.localPosition = Vector3.zero;
		_cardDetail.transform.localScale = Vector3.one;
		_cardDetail.Initialize(LayerMask.NameToLayer("Detail"), CardMaster.CardMasterId.Default);
		_cardDetail.gameObject.SetActive(value: false);
		_uiCardListClass = UnityEngine.Object.Instantiate(_cardListPrefab).GetComponent<UICardList>();
		_uiCardListClass.SetActive(in_Active: false);
		_uiCardListClass.Init(base.gameObject, _cardDetail, null, null, "Detail", in_DetailCameraUse: true);
		CreateTopBar(Wizard.Data.SystemText.Get("Shop_0116"), delegate
		{
			MyPageMenu.Instance.GoToShopCard();
		});
		_achiveAnchor.uiCamera = UIManager.GetInstance().MyPageUICameraObj.GetComponent<Camera>();
		base.onFirstStart();
	}

	protected override void onOpen()
	{
		base.onOpen();
		_loadedResourceList = new List<string>();
		StartGetBuildDeckInfo(OnBuildDeckInfoRequestFinished);
	}

	protected override void onClose()
	{
		base.onClose();
		DisposeResource();
	}

	private void DisposeResource()
	{
		Toolbox.ResourcesManager.RemoveAssetGroup(_loadResource);
		_loadResource.Clear();
	}

	private void StartGetBuildDeckInfo(Action<NetworkTask.ResultCode> callbackOnSuccess)
	{
		BuildDeckPurchaseInfoTask buildDeckPurchaseInfoTask = new BuildDeckPurchaseInfoTask();
		buildDeckPurchaseInfoTask.SetParameter(_addShowSeriesId);
		StartCoroutine(Toolbox.NetworkManager.Connect(buildDeckPurchaseInfoTask, callbackOnSuccess));
	}

	private void StartBuyBuildDeck(ShopCommonUtility.SalesType costType, int id)
	{
		if (!_isBuyConnect)
		{
			_isBuyConnect = true;
			UIManager.GetInstance().createInSceneCenterLoading();
			_buyTask = new BuildDeckBuyTask();
			_buyTask.SetParameter(id, costType);
			StartCoroutine(Toolbox.NetworkManager.Connect(_buyTask, delegate(NetworkTask.ResultCode error)
			{
				onSuccessPurchase(error, costType);
			}, _OnFailurePurchase, _OnResultCodeError));
		}
	}

	private int GetViewSeriesId()
	{
		int seriesId = Wizard.Data.BuildDeckPurchaseInfo.seriesList[0]._seriesId;
		int value = PlayerPrefsWrapper.GetValue(PlayerPrefsWrapper.LATEST_DECK_SERIES_ID);
		if (seriesId != value)
		{
			PlayerPrefsWrapper.SetValue(PlayerPrefsWrapper.LATEST_DECK_SERIES_ID, seriesId);
			PlayerPrefsWrapper.SetValue(PlayerPrefsWrapper.LAST_PURCHASE_DECK_SERIES_ID, seriesId);
		}
		if (_autoShowBuildDeckEnable)
		{
			return Wizard.Data.BuildDeckPurchaseInfo.GetSeriesId(_autoShowBuildDeckProductId);
		}
		int value2 = PlayerPrefsWrapper.GetValue(PlayerPrefsWrapper.SCENE_TRANSITION_VIEW_DECK_SERIES_ID);
		if (value2 > -1)
		{
			PlayerPrefsWrapper.SetValue(PlayerPrefsWrapper.SCENE_TRANSITION_VIEW_DECK_SERIES_ID, -1);
			return value2;
		}
		return PlayerPrefsWrapper.GetValue(PlayerPrefsWrapper.LAST_PURCHASE_DECK_SERIES_ID);
	}

	private void OnBuildDeckInfoRequestFinished(NetworkTask.ResultCode error)
	{
		List<int> seriesIdList = GetSeriesIdList();
		Dictionary<int, BaseSeriesData> seriesMasterDic = GetSeriesDataDictionary();
		List<BuildDeckSeriesPurchaseInfo> seriesList = Wizard.Data.BuildDeckPurchaseInfo.seriesList;
		DisposeResource();
		foreach (BuildDeckSeriesPurchaseInfo item in seriesList)
		{
			foreach (BuildDeckProductInfo product in item.productList)
			{
				if (product.saleInfo.costTicket.HasValue && product.saleInfo.costTicketItemId.HasValue)
				{
					_loadResource.Add(ShopCommonUtility.GetTicketIconPath(product.saleInfo.costTicketItemId.Value.ToString(), isFetch: false));
					_loadResource.Add(ShopCommonUtility.GetTicketIconRightDownPath(product.saleInfo.costTicketItemId.Value.ToString(), isFetch: false));
				}
			}
		}
		StartCoroutine(Toolbox.ResourcesManager.LoadAssetGroupAsync(_loadResource, delegate
		{
			StartCoroutine(loadSeriesImages(ResourcesManager.AssetLoadPathType.ShopBuildDeck, seriesIdList, seriesMasterDic, delegate
			{
				if (_drumrollSeriesImageList.Count <= 0)
				{
					UIManager.GetInstance().OnReadyViewScene(isFadein: true);
				}
				else
				{
					int viewSeriesId = GetViewSeriesId();
					int seriesIndex = seriesList.FindIndex((BuildDeckSeriesPurchaseInfo data) => data._seriesId == viewSeriesId);
					if (seriesIndex < 0)
					{
						seriesIndex = 0;
					}
					List<ShopDrumrollScrollManager.DrumrollItem> itemList = _drumrollSeriesImageList.Select((Texture tex, int index) => new ShopDrumrollScrollManager.DrumrollItem(tex, seriesList[index]._isNew)).ToList();
					StartCoroutine(_drumrollManager.CreateDrumrollScroll_Coroutine(itemList, seriesIndex, onSelectSeries, delegate
					{
						onSelectSeries(seriesIndex, delegate
						{
							UIManager.GetInstance().OnReadyViewScene(isFadein: true);
							if (_autoShowBuildDeckEnable)
							{
								_autoShowBuildDeckEnable = false;
								BuildDeckProductInfo productInfo = Wizard.Data.BuildDeckPurchaseInfo.GetProductInfo(_autoShowBuildDeckProductId);
								if (productInfo != null)
								{
									createBuildDeckSelectBuyMeansDialog(productInfo);
								}
							}
						});
					}));
				}
			}));
		}));
	}

	private List<int> GetSeriesIdList()
	{
		return Wizard.Data.BuildDeckPurchaseInfo.seriesList.ConvertAll((BuildDeckSeriesPurchaseInfo info) => info._seriesId);
	}

	private Dictionary<int, BaseSeriesData> GetSeriesDataDictionary()
	{
		Dictionary<int, BaseSeriesData> dictionary = new Dictionary<int, BaseSeriesData>();
		foreach (KeyValuePair<int, BuildDeckSeries> item in Wizard.Data.Master.BuildDeckSeriesIdDic)
		{
			dictionary.Add(item.Key, item.Value);
		}
		return dictionary;
	}

	private void onSelectSeries(int seriesIndex)
	{
		onSelectSeries(seriesIndex, null);
	}

	private void onSelectSeries(int seriesIndex, Action onFinish)
	{
		BuildDeckSeriesPurchaseInfo seriesInfo = Wizard.Data.BuildDeckPurchaseInfo.seriesList[seriesIndex];
		_selectSeriesInfo = seriesInfo;
		_titleLogoTexture.mainTexture = _seriesTitleImageList[seriesIndex];
		_labelSeriesDescription.text = seriesInfo._introduction;
		if (seriesInfo.SeriesRewardList.Count > 0)
		{
			_btnSeriesRewards.gameObject.SetActive(value: true);
			_btnSeriesRewards.onClick.Clear();
			_btnSeriesRewards.onClick.Add(new EventDelegate(delegate
			{
				OnClickSeriesRewardButton(seriesIndex);
			}));
		}
		else
		{
			_btnSeriesRewards.gameObject.SetActive(value: false);
		}
		int num = _cacheSeriesIdList.IndexOf(seriesInfo._seriesId);
		if (num != -1)
		{
			_cacheRefCountList[num]++;
			ResetProductListScroll(seriesInfo.productList.Count);
			onFinish.Call();
			return;
		}
		if (_cacheSeriesIdList.Count >= 4)
		{
			int num2 = _cacheRefCountList[0];
			int cacheIndex = 0;
			for (int num3 = 1; num3 < _cacheRefCountList.Count; num3++)
			{
				if (num2 > _cacheRefCountList[num3])
				{
					num2 = _cacheRefCountList[num3];
					cacheIndex = num3;
				}
			}
			DeleteCacheSeriesByCashIndex(cacheIndex);
		}
		UIManager.GetInstance().LoadingViewManager.CreateInSceneCenter();
		StartCoroutine(loadBuildDecks(delegate
		{
			UIManager.GetInstance().LoadingViewManager.CloseInSceneCenter();
			if (_selectSeriesInfo == seriesInfo)
			{
				ResetProductListScroll(seriesInfo.productList.Count);
			}
			_cacheSeriesIdList.Add(seriesInfo._seriesId);
			_cacheRefCountList.Add(1);
			onFinish.Call();
		}));
	}

	private void DeleteCacheSeriesByCashIndex(int cacheIndex)
	{
		List<string> list = new List<string>();
		BuildDeckSeriesPurchaseInfo buildDeckSeriesPurchaseInfo = Wizard.Data.BuildDeckPurchaseInfo.seriesList.Find((BuildDeckSeriesPurchaseInfo m) => m._seriesId == _cacheSeriesIdList[cacheIndex]);
		if (buildDeckSeriesPurchaseInfo != null)
		{
			for (int num = 0; num < buildDeckSeriesPurchaseInfo.productList.Count; num++)
			{
				list.Add(Toolbox.ResourcesManager.GetAssetTypePath(buildDeckSeriesPurchaseInfo.productList[num].saleInfo.path, ResourcesManager.AssetLoadPathType.ShopBuildDeckThumbnail));
			}
		}
		Toolbox.ResourcesManager.RemoveAssetGroup(list);
		_cacheSeriesIdList.RemoveAt(cacheIndex);
		_cacheRefCountList.RemoveAt(cacheIndex);
		for (int num2 = 0; num2 < list.Count; num2++)
		{
			_cacheResourceList.Remove(list[num2]);
		}
	}

	private IEnumerator loadBuildDecks(Action callBack = null)
	{
		UIManager.GetInstance().createInSceneCenterLoading();
		List<string> listResource = new List<string>();
		List<BuildDeckProductInfo> productList = _selectSeriesInfo.productList;
		for (int i = 0; i < productList.Count; i++)
		{
			listResource.Add(Toolbox.ResourcesManager.GetAssetTypePath(productList[i].saleInfo.path, ResourcesManager.AssetLoadPathType.ShopBuildDeckThumbnail));
		}
		yield return StartCoroutine(Toolbox.ResourcesManager.LoadAssetGroupAsync(listResource, null));
		UIManager.GetInstance().closeInSceneCenterLoading();
		for (int j = 0; j < listResource.Count; j++)
		{
			_cacheResourceList.Add(listResource[j]);
		}
		callBack.Call();
	}

	protected override void OnInitializeItem(GameObject go, int wrapIndex, int realIndex)
	{
		if (_selectSeriesInfo == null)
		{
			return;
		}
		if (realIndex >= _selectSeriesInfo.productList.Count || realIndex < 0)
		{
			go.SetActive(value: false);
			return;
		}
		go.SetActive(value: true);
		BuildDeckPlate plate = go.GetComponent<BuildDeckPlate>();
		EventDelegate eventDelegate = new EventDelegate(this, "onPushBuyButton");
		eventDelegate.parameters[0].value = plate;
		plate.SetData(_selectSeriesInfo.productList[realIndex], eventDelegate, delegate
		{
			_onTapBuildDeckImage(plate);
		});
	}

	private void _onTapBuildDeckImage(BuildDeckPlate plate)
	{
		if (!(_dialogProductDetail != null))
		{
			_dialogProductDetail = UIManager.GetInstance().CreateDialogClose();
			_dialogProductDetail.SetSize(DialogBase.Size.M);
			_dialogProductDetail.SetTitleLabel(Wizard.Data.SystemText.Get("Dia_BuyBuildDeck_003_Title"));
			_dialogProductDetail.SetButtonLayout(DialogBase.ButtonLayout.CloseBtn);
			_dialogProductDetail.gameObject.layer = LayerMask.NameToLayer("MyPage");
			_dialogProductDetail.SetBackViewLayer(LayerMask.NameToLayer("MyPage"));
			_dialogProductDetail.SetDepthAndSortingOrder(140, 2);
			BuildDeckDetailWindow component = UnityEngine.Object.Instantiate(_prefabDialogBuildDeckDetail).GetComponent<BuildDeckDetailWindow>();
			_dialogProductDetail.SetObj(component.gameObject);
			component.SetSingleData(_uiCardListClass, plate.ProductInfo);
			_dialogProductDetail.OnClose = component.OnCloseWindow;
		}
	}

	private void onPushBuyButton(BuildDeckPlate plate)
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		_selectPlate = plate;
		createBuildDeckSelectBuyMeansDialog(plate.ProductInfo);
	}

	private void OnClickSeriesRewardButton(int seriesIndex)
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_COMMON_BUTTON);
		DialogBase dialogBase = PurchaseRewardDialog.Create(Wizard.Data.BuildDeckPurchaseInfo.seriesList[seriesIndex].SeriesRewardList, _cardDetail, useLargeDetailDialog: false, PurchaseRewardDialog.Layout.NORMAL);
		dialogBase.SetLayer("MyPage");
		dialogBase.SetDepthAndSortingOrder(140, 2);
	}

	private void createBuildDeckSelectBuyMeansDialog(BuildDeckProductInfo pInfo)
	{
		if (_dialogSelectBuyMeans != null)
		{
			return;
		}
		_ = pInfo.is_purchased;
		_dialogSelectBuyMeans = _createBaseDialogForSelectBuyMeans(pInfo.saleInfo);
		BuildDeckSelectBuyMeansDialog component = UnityEngine.Object.Instantiate(_prefabDialogSelectBuyMeans).GetComponent<BuildDeckSelectBuyMeansDialog>();
		_dialogSelectBuyMeans.SetObj(component.gameObject);
		Action onPushBuyCrystalBtnCallBack = null;
		Action onPushBuyRupyBtnCallBack = null;
		Action onPushBuyTicketBtnCallBack = null;
		if (pInfo.saleInfo.isFree)
		{
			_dialogSelectBuyMeans.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
			_dialogSelectBuyMeans.SetButtonText(Wizard.Data.SystemText.Get("Shop_0082"));
			_dialogSelectBuyMeans.onPushButton1 = delegate
			{
				_purchaseProductInfo = pInfo;
				UIManager.GetInstance().createInSceneCenterLoading();
				StartBuyBuildDeck(ShopCommonUtility.SalesType.free, pInfo.product_id);
			};
		}
		else
		{
			_dialogSelectBuyMeans.SetButtonLayout(DialogBase.ButtonLayout.NONE);
			onPushBuyCrystalBtnCallBack = delegate
			{
				_purchaseProductInfo = pInfo;
				_createPurchaseConfirmDialog(pInfo.saleInfo, ShopCommonUtility.SalesType.crystal, delegate
				{
					StartBuyBuildDeck(ShopCommonUtility.SalesType.crystal, pInfo.product_id);
				});
			};
			onPushBuyRupyBtnCallBack = delegate
			{
				_purchaseProductInfo = pInfo;
				_createPurchaseConfirmDialog(pInfo.saleInfo, ShopCommonUtility.SalesType.rupy, delegate
				{
					StartBuyBuildDeck(ShopCommonUtility.SalesType.rupy, pInfo.product_id);
				});
			};
			onPushBuyTicketBtnCallBack = delegate
			{
				_purchaseProductInfo = pInfo;
				_createPurchaseConfirmDialog(pInfo.saleInfo, ShopCommonUtility.SalesType.ticket, delegate
				{
					StartBuyBuildDeck(ShopCommonUtility.SalesType.ticket, pInfo.product_id);
				});
			};
		}
		component.Init(pInfo, _dialogSelectBuyMeans, onPushBuyCrystalBtnCallBack, onPushBuyRupyBtnCallBack, onPushBuyTicketBtnCallBack);
	}

	private DialogBase _createBaseDialogForSelectBuyMeans(ShopCommonSaleInfo info)
	{
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetSize(DialogBase.Size.M);
		dialogBase.SetTitleLabel(Wizard.Data.SystemText.Get("Dia_BuyBuildDeck_001_Title"));
		dialogBase.SetReturnMsg(null, "");
		return dialogBase;
	}

	private void _createPurchaseConfirmDialog(ShopCommonSaleInfo info, ShopCommonUtility.SalesType costType, Action buyApiFunc)
	{
		if (!(_dialogPurchaseConfirm != null) && ShopCommonUtility.IsHaveEnoughCost(info, costType, delegate
		{
			if (_dialogCrystalShortage == null)
			{
				_dialogCrystalShortage = ShopCommonUtility.CreateCrystalShortagePopup();
			}
		}))
		{
			string warningTextId = (_purchaseProductInfo.ContainsOnlyRotationCards() ? null : "Shop_0139");
			_dialogPurchaseConfirm = ShopCommonUtility.CreatePurchaseConfirmPopup(info, costType, _prefabDialogPurchaseConfirm, buyApiFunc, warningTextId);
			_dialogPurchaseConfirm.SetTitleLabel(Wizard.Data.SystemText.Get("Dia_BuyBuildDeck_002_Title"));
		}
	}

	private void _OnFailurePurchase(NetworkTask.ResultCode code)
	{
		_isBuyConnect = false;
		UIManager.GetInstance().closeInSceneCenterLoading();
	}

	private void _OnResultCodeError(int code)
	{
		if (code != 110)
		{
			_isBuyConnect = false;
			UIManager.GetInstance().closeInSceneCenterLoading();
			_ReloadBuildDeckInfo();
		}
	}

	private void ShowRewardDialog(Action onFinish)
	{
		if (_buyTask.LotteryRewardList.Count == 0)
		{
			onFinish.Call();
			return;
		}
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetSize(DialogBase.Size.M);
		dialogBase.SetTitleLabel(Wizard.Data.SystemText.Get("Story_0029"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
		RewardBase component = NGUITools.AddChild(dialogBase.gameObject, UIManager.GetInstance().GetRewardDialogPrefab().gameObject).GetComponent<RewardBase>();
		foreach (ReceivedReward lotteryReward in _buyTask.LotteryRewardList)
		{
			component.AddReward(lotteryReward);
			if (!string.IsNullOrEmpty(lotteryReward.reward_message))
			{
				dialogBase.SetTitleLabel(lotteryReward.reward_message);
			}
		}
		component.EndCreate();
		dialogBase.OnClose = delegate
		{
			onFinish.Call();
		};
	}

	private void ShowLotteryApplyDialog(Action onFinish)
	{
		UIManager.GetInstance().LoadingViewManager.CreateInSceneCenter();
		string lotteryTexturePath = LotteryApplyDialog.GetLotteryTexturePath(_buyTask.LotteryData, isFetch: false);
		_loadResource.Add(lotteryTexturePath);
		StartCoroutine(Toolbox.ResourcesManager.LoadAssetAsync(lotteryTexturePath, delegate
		{
			UIManager.GetInstance().closeInSceneCenterLoading();
			LotteryApplyDialog.Create(_buyTask.LotteryData, autoClose: false).OnClose = delegate
			{
				ShowRewardDialog(delegate
				{
					onFinish.Call();
				});
			};
		}));
	}

	private void onSuccessPurchase(NetworkTask.ResultCode error, ShopCommonUtility.SalesType salesType)
	{
		_isBuyConnect = false;
		BuildDeckProductInfo savePurchaseProductInfo = _purchaseProductInfo;
		if (_purchaseProductInfo != null)
		{
			PlayerPrefsWrapper.SetValue(PlayerPrefsWrapper.LAST_PURCHASE_DECK_SERIES_ID, _selectSeriesInfo._seriesId);
			if (salesType == ShopCommonUtility.SalesType.ticket)
			{
				_addShowSeriesId = _selectSeriesInfo._seriesId;
			}
			if (!_buyTask.LotteryData.IsEnable && _buyTask.MissionRewardList.Count == 0)
			{
				ShowCreateDeckDialog(savePurchaseProductInfo);
			}
			else if (_buyTask.LotteryData.IsEnable)
			{
				ShowLotteryApplyDialog(delegate
				{
					ShowCreateDeckDialog(savePurchaseProductInfo);
				});
			}
			else if (_buyTask.MissionRewardList.Count > 0)
			{
				ShowMissionRewardDialog(delegate
				{
					ShowCreateDeckDialog(savePurchaseProductInfo);
				});
			}
		}
		_ReloadBuildDeckInfo();
	}

	private void ShowCreateDeckDialog(BuildDeckProductInfo savePurchaseProductInfo)
	{
		DialogBase diaChange = UIManager.GetInstance().CreateDialogClose();
		bool hasResurgentCard = savePurchaseProductInfo.HasResurgentCard;
		string empty = string.Empty;
		empty = ((_buyTask._seriesRewardList.Count > 0) ? Wizard.Data.SystemText.Get("Shop_0144", savePurchaseProductInfo.saleInfo.name.Replace("\n", "")) : ((!hasResurgentCard) ? Wizard.Data.SystemText.Get("Shop_0124", savePurchaseProductInfo.saleInfo.name.Replace("\n", "")) : Wizard.Data.SystemText.Get("Shop_0256", savePurchaseProductInfo.saleInfo.name.Replace("\n", ""))));
		diaChange.SetText(empty);
		diaChange.SetTitleLabel(Wizard.Data.SystemText.Get("Dia_BuyBuildDeck_004_Title"));
		diaChange.SetButtonLayout(DialogBase.ButtonLayout.BlueBtn_CancelBtn);
		diaChange.SetButtonText(Wizard.Data.SystemText.Get("Dia_BuyBuildDeck_001_Button"));
		_purchaseDeckName = savePurchaseProductInfo.saleInfo.name;
		_purchaseDeckClassId = savePurchaseProductInfo.leader_id;
		_purchaseDeckCardIds = savePurchaseProductInfo.CardIdList;
		if (hasResurgentCard)
		{
			diaChange.onPushButton1 = delegate
			{
				CheckEmptyDeck(Format.Rotation);
			};
		}
		else
		{
			diaChange.onPushButton1 = OpenSelectFormatDialog;
		}
		diaChange.onPushButton2 = delegate
		{
			diaChange.CloseWithoutSelect();
		};
		diaChange.onCloseWithoutSelect = delegate
		{
			UIManager.GetInstance().StartCoroutine(ShowAchieveLog(_buyTask.NotificatonAnimationParams));
			_buyTask.NotificatonAnimationParams = null;
		};
	}

	private void ShowMissionRewardDialog(Action onFinish)
	{
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetSize(DialogBase.Size.M);
		dialogBase.SetTitleLabel(Wizard.Data.SystemText.Get("Story_0029"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
		dialogBase.OnClose = delegate
		{
			onFinish.Call();
		};
		RewardBase component = NGUITools.AddChild(dialogBase.gameObject, UIManager.GetInstance().GetRewardDialogPrefab().gameObject).GetComponent<RewardBase>();
		for (int num = 0; num < _buyTask.MissionRewardList.Count; num++)
		{
			component.AddReward(_buyTask.MissionRewardList[num]);
		}
		component.EndCreate();
	}

	private IEnumerator ShowAchieveLog(List<NotificatonAnimation.Param> paramList)
	{
		if (paramList != null)
		{
			if (_notificationAnimation != null)
			{
				UnityEngine.Object.Destroy(_notificationAnimation.gameObject);
				_notificationAnimation = null;
			}
			_notificationAnimation = NGUITools.AddChild(_achieveLog, _notificationAnimationPrefab.gameObject).GetComponent<NotificatonAnimation>();
			yield return StartCoroutine(_notificationAnimation.Exec(paramList));
		}
	}

	private void CheckEmptyDeck(Format format)
	{
		_deckCreateFormat = format;
		EmptyDeckInfoTask emptyDeckInfoTask = new EmptyDeckInfoTask();
		emptyDeckInfoTask.SetParameter(_deckCreateFormat);
		StartCoroutine(Toolbox.NetworkManager.Connect(emptyDeckInfoTask, OnSuccessDeckListCheck));
	}

	private void OpenSelectFormatDialog()
	{
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		SystemText systemText = Wizard.Data.SystemText;
		dialogBase.SetText(systemText.Get("Shop_0138"));
		dialogBase.SetTitleLabel(systemText.Get("Dia_BuyBuildDeck_004_Title"));
		dialogBase.AddButton(DialogBase.ButtonType.Blue, isReflect: true, systemText.Get("Common_0155"));
		dialogBase.AddButton(DialogBase.ButtonType.Blue, isReflect: true, systemText.Get("Common_0154"));
		dialogBase.onPushButton1 = delegate
		{
			CheckEmptyDeck(Format.Unlimited);
		};
		dialogBase.onPushButton2 = delegate
		{
			CheckEmptyDeck(Format.Rotation);
		};
		dialogBase.onCloseWithoutSelect = delegate
		{
			UIManager.GetInstance().StartCoroutine(ShowAchieveLog(_buyTask.NotificatonAnimationParams));
			_buyTask.NotificatonAnimationParams = null;
		};
	}

	private void OnSuccessDeckListCheck(NetworkTask.ResultCode errorcode)
	{
		if (Wizard.Data.EmptyDeckInfo.CanDeckCreate)
		{
			SetUpDeckDataAndChangeViewDeckEdit();
			return;
		}
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetText(Wizard.Data.SystemText.Get("Dia_BuyBuildDeck_005_Body"));
		dialogBase.SetTitleLabel(Wizard.Data.SystemText.Get("Dia_BuyBuildDeck_005_Title"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
		dialogBase.SetButtonText(Wizard.Data.SystemText.Get("Dia_BuyBuildDeck_005_Button"));
		dialogBase.onPushButton1 = delegate
		{
			UIManager.ChangeViewSceneParam param = new UIManager.ChangeViewSceneParam
			{
				IsUpdateFooterMenuTexture = true
			};
			DeckListUI.ChangeSceneToDeckList(_deckCreateFormat, param);
		};
	}

	private void SetUpDeckDataAndChangeViewDeckEdit()
	{
		DeckData deckData = new DeckData();
		deckData.SetDeckClassID(_purchaseDeckClassId);
		deckData.SetDeckSleeveID(3000011L);
		deckData.SetDeckIsComplete(isComplete: true);
		deckData.SetCardIdList(_purchaseDeckCardIds);
		DeckData deckData2 = new DeckData(_deckCreateFormat, DeckAttributeType.CustomDeck);
		deckData2.SetDeckID(Wizard.Data.EmptyDeckInfo.EmptyDeckID);
		DeckCardEditUI.SetBuildDeckEditParameter(deckData, _purchaseDeckName, deckData2);
		UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.DeckCardEdit);
	}

	private void _ReloadBuildDeckInfo()
	{
		if (MyPageMenu.Instance != null)
		{
			MyPageMenu.Instance.UpdateCrystalCount();
			MyPageMenu.Instance.UpdateRupyCount();
		}
		else
		{
			UIManager.GetInstance().UpDateCrystalNum();
		}
		List<BuildDeckSeriesPurchaseInfo> oldSeriesList = new List<BuildDeckSeriesPurchaseInfo>(Wizard.Data.BuildDeckPurchaseInfo.seriesList);
		StartGetBuildDeckInfo(delegate
		{
			bool flag = false;
			List<BuildDeckSeriesPurchaseInfo> seriesList = Wizard.Data.BuildDeckPurchaseInfo.seriesList;
			for (int i = 0; i < seriesList.Count; i++)
			{
				if (oldSeriesList[i]._seriesId != seriesList[i]._seriesId)
				{
					flag = true;
				}
				if (seriesList[i]._seriesId == _selectSeriesInfo._seriesId)
				{
					if (_selectPlate != null)
					{
						if (_selectPlate.ProductInfo.product_id == _purchaseProductInfo.product_id)
						{
							_selectSeriesInfo = seriesList[i];
							BuildDeckPlate[] componentsInChildren = _wrapContent.gameObject.GetComponentsInChildren<BuildDeckPlate>();
							foreach (BuildDeckPlate plate in componentsInChildren)
							{
								int realIndex = _selectSeriesInfo.productList.FindIndex((BuildDeckProductInfo p) => p.product_id == plate.ProductInfo.product_id);
								OnInitializeItem(plate.gameObject, 0, realIndex);
							}
						}
						else
						{
							onSelectSeries(i);
						}
					}
					else
					{
						onSelectSeries(i);
					}
				}
			}
			if (oldSeriesList.Count != seriesList.Count)
			{
				flag = true;
			}
			_purchaseProductInfo = null;
			_selectPlate = null;
			if (flag)
			{
				List<int> seriesIdList = GetSeriesIdList();
				Dictionary<int, BaseSeriesData> seriesDataDictionary = GetSeriesDataDictionary();
				StartCoroutine(loadSeriesImages(ResourcesManager.AssetLoadPathType.ShopBuildDeck, seriesIdList, seriesDataDictionary, delegate
				{
					List<ShopDrumrollScrollManager.DrumrollItem> itemList = _drumrollSeriesImageList.ConvertAll((Texture tex) => new ShopDrumrollScrollManager.DrumrollItem(tex));
					StartCoroutine(_drumrollManager.CreateDrumrollScroll_Coroutine(itemList, 0, onSelectSeries, delegate
					{
						onSelectSeries(0);
						UIManager.GetInstance().closeInSceneCenterLoading();
					}));
				}));
			}
			else
			{
				UIManager.GetInstance().closeInSceneCenterLoading();
			}
		});
	}
}
