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

public class MyPageMenu : UIBase
{
	private const float TRANSITIONAL_BGM_DELAY_TIME = 0.5f;

	private static readonly string MYPAGE_LAYER_NAME = "MyPage";

	private const int TUTORIAL_DIALOG_DEPTH = 3000;

	private static MyPageMenu _instance;

	public const int HOME_INDEX = 0;

	public const int STORY_INDEX = 1;

	public const int BATTLE_INDEX = 2;

	public const int ARENA_INDEX = 3;

	public const int DECK_INDEX = 4;

	public const int SHOP_INDEX = 5;

	public const int OTHER_INDEX = 6;

	private const int MYPAGE_ITEM_MAX = 7;

	private const float TWEEN_DISTANCE_X_MOVE_NAME_FRAME = 450f;

	private const float TWEEN_DELAY_MOVE_NAME_FRAME = 0f;

	private const float TWEEN_DISTANCE_Y_BACK_BUTTON = 500f;

	private const float TWEEN_DELAY_BACK_BUTTON = 0.1f;

	private const float TWEEN_TIME_TOP_BAR = 0.3f;

	private GameObject[] _pagePrefab;

	private const int MYPAGE_TREASURE_CP_REWARD_DIALOG = 37;

	private const int BG_REMAKE_RELEASE_MEMORY_COUNT = 50;

	[SerializeField]
	private GameObject _pagePrefabHome;

	[SerializeField]
	private GameObject _pagePrefabSoroPlay;

	[SerializeField]
	private GameObject _pagePrefabBattle;

	[SerializeField]
	private GameObject _pagePrefabArena;

	[SerializeField]
	private GameObject _pagePrefabCard;

	[SerializeField]
	private GameObject _pagePrefabShop;

	[SerializeField]
	private GameObject _pagePrefabOther;

	[SerializeField]
	private GameObject _myPageLayerRoot;

	[SerializeField]
	private MyPageHomeStatic _homeStatic;

	[SerializeField]
	private MyPageCustomBGControl _customBGControlOriginal;

	private MyPageCustomBGControl _customBGControl;

	[SerializeField]
	private RewardBase _rewardBase;

	[SerializeField]
	private BoxCollider _notTouchMypageCollider;

	[SerializeField]
	private MyPageMaintenanceNotification _maintenanceNotificationPrefab;

	private MyPageMaintenanceNotification _maintenanceNotification;

	private GameObject[] _pageInstance;

	private MyPageItem[] _pageItem;

	private int _currentIndex;

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

	private MyPageItemBattle _pageItemBattle;

	private MyPageItemHome _pageItemHome;

	private MyPageItemSoroPlay _pageItemSoroPlay;

	private MyPageItemShop _pageItemShop;

	private MyPageItemArena _pageItemArena;

	private MyPageItemCard _pageItemCard;

	private bool _isEnableRoomInvite;

	private float _nameWindowDefaultX;

	private bool _changeMenuCalled;

	private bool _isSetupFinish;

	private bool _isFirstLoad = true;

	private Transform _firstGuidEffectParent;

	private GameObject _boxOpenEffectObj;

	private GameObject _treasureEffectObj;

	private int _remakeCustomBgCount;

	private bool _loadResourceFinish;

	private bool _isFirstChangeMenuCall = true;

	private bool _isStopMyPageRefreshOnce;

	public static bool IsMyPageRequestEnd { get; set; }

	public static MyPageMenu Instance => _instance;

	public bool _treasureBoxCpRewardDialogClosed { get; private set; } = true;

	public bool IsEnableRoomInvite => _isEnableRoomInvite;

	public TopBar TopBar { get; set; }

	public MyPageItemHome HomeMenu => _pageItemHome;

	public MyPageItemBattle BattleMenu => _pageItemBattle;

	public MyPageCustomBGControl CustomBGControl => _customBGControl;

	public bool IsCardLoadFinish => _homeStatic.CardLoadFinish;

	public bool IsFirstGuid => Data.Load.data._userTutorial.TutorialStep != 100;

	public Effect FirstGuidEffect { get; private set; }

	public bool IsEnableFooterCurrentMenu => _pageItem[_currentIndex].IsEnableFooterCurrentMenu;

	public int currentIndex => _currentIndex;

	public bool IsVisible => _myPageLayerRoot.activeInHierarchy;

	public bool IsSetupComplete { get; private set; }

	public bool IsFadeoutEnd { get; private set; }

	public List<CampaignRewardInfo> WinnerRewardInfoCopy { get; private set; } = new List<CampaignRewardInfo>();

	private void Awake()
	{
		_instance = this;
		_pagePrefab = new GameObject[7];
		_pagePrefab[0] = _pagePrefabHome;
		_pagePrefab[1] = _pagePrefabSoroPlay;
		_pagePrefab[2] = _pagePrefabBattle;
		_pagePrefab[3] = _pagePrefabArena;
		_pagePrefab[4] = _pagePrefabCard;
		_pagePrefab[5] = _pagePrefabShop;
		_pagePrefab[6] = _pagePrefabOther;
		_pageInstance = new GameObject[_pagePrefab.Length];
		_pageItem = new MyPageItem[_pagePrefab.Length];
		TopBar = UIManager.GetInstance().CreateTopBar(base.gameObject, "");
		UIManager.GetInstance().SetLayerRecursive(TopBar.transform, LayerMask.NameToLayer("MyPage"));
		TopBar.BackButtonLabel.text = Data.SystemText.Get("Common_0137");
		TopBar.transform.parent = _myPageLayerRoot.transform;
		UIManager.SetObjectToGrey(TopBar.BuyCrystalButton.gameObject, b: true);
		TopBar.BuyCrystalButton.isEnabled = false;
		UIEventListener.Get(TopBar.NameWindowBg).onClick = delegate
		{
			OnClickNameWindow();
		};
		_nameWindowDefaultX = TopBar.NameWindowObject.transform.localPosition.x;
		_customBGControlOriginal.gameObject.SetActive(value: false);
	}

	public override void onFirstStart()
	{
		_instance = this;
		base.onFirstStart();
	}

	protected override void onOpen()
	{
		base.onOpen();
		LocalLog.AddRoomCreateLog("onOpen ");
		_myPageLayerRoot.SetActive(value: true);
		if (!_isSetupFinish)
		{
			_isSetupFinish = true;
			IsSetupComplete = false;
			IsFadeoutEnd = false;
			OpenSetup();
			StartCoroutine(Setup());
			CommonBackGround.Instance.ChangeMyPageBG();
			assetSetting();
		}
		_notTouchMypageCollider.enabled = false;
	}

	protected override void onClose()
	{
		base.onClose();
		_myPageLayerRoot.SetActive(value: false);
		DestroyMyPageItem();
		if (CommonBackGround.Instance != null)
		{
			CommonBackGround.Instance.EffectVisible = true;
		}
		_isSetupFinish = false;
	}

	public void OpenSetup()
	{
		CreateMyPageItem();
		MyPageItem[] pageItem = _pageItem;
		for (int i = 0; i < pageItem.Length; i++)
		{
			pageItem[i].AttachAtlas();
		}
	}

	public static IEnumerator OnMyPageOpen(UIManager uiManager, UIManager.ChangeViewSceneParam param)
	{
		IsMyPageRequestEnd = false;
		while (!IsMyPageRequestEnd)
		{
			yield return null;
		}
		if (Data.MyPage.CardUpdateFlag)
		{
			if (Instance != null)
			{
				Instance.ReloadCardCircle();
			}
			Data.MyPage.CardUpdateFlag = false;
		}
		if (Instance != null)
		{
			Instance.ChangeMenu(param.MyPageMenuIndex, param.IsCutCardMotion);
			if (param.MyPageMenuIndex != 0 && Instance._customBGControl != null)
			{
				Instance._customBGControl.SetEnable(enable: false);
			}
		}
		else
		{
			uiManager._Footer.UpdateCurrentIndex(param.MyPageMenuIndex);
		}
	}

	private void CreateMyPageItem()
	{
		for (int i = 0; i < _pagePrefab.Length; i++)
		{
			if (!(_pageItem[i] != null))
			{
				_pageInstance[i] = UnityEngine.Object.Instantiate(_pagePrefab[i]);
				_pageInstance[i].transform.parent = _myPageLayerRoot.transform;
				_pageInstance[i].transform.localPosition = Vector3.zero;
				_pageInstance[i].transform.localScale = Vector3.one;
				_pageInstance[i].transform.localRotation = Quaternion.identity;
				_pageItem[i] = _pageInstance[i].GetComponent<MyPageItem>();
				_pageItem[i].Initialize(this);
				_pageInstance[i].SetActive(value: false);
			}
		}
		_pageItemHome = _pageInstance[0].GetComponent<MyPageItemHome>();
		_pageItemBattle = _pageInstance[2].GetComponent<MyPageItemBattle>();
		_pageItemShop = _pageInstance[5].GetComponent<MyPageItemShop>();
		_pageItemArena = _pageInstance[3].GetComponent<MyPageItemArena>();
		_pageItemCard = _pageInstance[4].GetComponent<MyPageItemCard>();
		_pageItemSoroPlay = _pageInstance[1].GetComponent<MyPageItemSoroPlay>();
		_pageItemHome.SetHomeStatic(_homeStatic);
		if (_loadResourceFinish)
		{
			AttachCardPanelTexture();
		}
	}

	public void ChangeMyPageBG(MyPageDetail.BGType type, string id)
	{
		if (type == MyPageDetail.BGType.Deck)
		{
			_pageItemHome.OnUpdateCustomMyPageEnable(isHomeActive: true);
			if (_customBGControl != null)
			{
				_customBGControl.FadeOutDestroy();
				_customBGControl = null;
				_homeStatic.StartCardUpAnimation();
			}
		}
		else
		{
			ChangeBGToCustomBG(id);
		}
	}

	private void ChangeBGToCustomBG(string id)
	{
		string text = ((_customBGControl != null) ? _customBGControl.Id : string.Empty);
		if (id == text)
		{
			return;
		}
		MyPageCustomBGControl oldControl = _customBGControl;
		if (oldControl != null)
		{
			oldControl.FadeoutStandby();
		}
		_customBGControl = NGUITools.AddChild(_customBGControlOriginal.transform.parent.gameObject, _customBGControlOriginal.gameObject).GetComponent<MyPageCustomBGControl>();
		_customBGControl.gameObject.SetActive(value: true);
		_customBGControl.Load(id, isDisplaySoon: true, delegate
		{
			_pageItemHome.OnUpdateCustomMyPageEnable(isHomeActive: true);
			if (oldControl != null)
			{
				oldControl.FadeOutDestroy();
			}
			OnRemakeCustomBg();
		});
	}

	private void DestroyMyPageItem()
	{
		if (FirstGuidEffect != null)
		{
			FirstGuidEffect.transform.parent = _firstGuidEffectParent;
		}
		for (int i = 0; i < _pageItem.Length; i++)
		{
			if (_pageItem[i] != null)
			{
				_pageItem[i].OnClose();
				UnityEngine.Object.Destroy(_pageItem[i].gameObject);
				_pageItem[i] = null;
			}
		}
		_pageItemHome = null;
		_pageItemBattle = null;
		_pageItemShop = null;
		_pageItemArena = null;
		_pageItemCard = null;
		if (_customBGControl != null)
		{
			UnityEngine.Object.Destroy(_customBGControl.gameObject);
		}
		_customBGControl = null;
		_remakeCustomBgCount = 0;
		ReleaseMemory(runGCCollect: true);
	}

	private IEnumerator Setup()
	{
		LocalLog.AddRoomCreateLog("Setup1 ");
		Offline.IsConventionMode = false;
		if (UIManager.GetInstance() != null)
		{
			TopBar.SetBackButtonEnable(enable: true);
			if (UIManager.GetInstance()._Footer != null)
			{
				UIManager.GetInstance()._Footer.ShowFooterMenu(isShow: true);
			}
		}
		bool finishTutorialResouce = true;
		if (Data.Load.data._userTutorial.TutorialStep != 100)
		{
			finishTutorialResouce = false;
			_loadFileList.AddRange(GameMgr.GetIns().GetEffectMgr().InitCommonEffect("Json/EffectTutorialData", isBattle: true, isField: false, isBattleEffect: false, delegate
			{
				finishTutorialResouce = true;
				FirstGuidEffect = GameMgr.GetIns().GetEffectMgr().Start(EffectMgr.EffectType.CMN_TUTORIAL_TAP_1, Vector3.zero, Quaternion.identity);
				FirstGuidEffect.gameObject.SetActive(value: false);
			}));
		}
		while (!finishTutorialResouce)
		{
			yield return null;
		}
		LocalLog.AddRoomCreateLog("Setup2 ");
		GameMgr.GetIns().GetPrefabMgr().Load("Prefab/UI/Menu/CardPanelMaintenancePlate");
		RefreshStaticData();
		yield return StartCoroutine(GetMyPageInfo());
		if (Data.MyPage.data.BGInfo.BGType != MyPageDetail.BGType.Deck)
		{
			_customBGControl = NGUITools.AddChild(_customBGControlOriginal.transform.parent.gameObject, _customBGControlOriginal.gameObject).GetComponent<MyPageCustomBGControl>();
			_customBGControl.gameObject.SetActive(value: true);
			CommonBackGround.Instance.EffectVisible = false;
			if (!_customBGControl.IsLoadRequestEnd)
			{
				string id = Data.MyPage.data.BGInfo.Id;
				if (Data.MyPage.data.BGInfo.BGType == MyPageDetail.BGType.RandomBG)
				{
					id = MyPageItemHome.DecideRandomBG(Data.MyPage.data.BGInfo.RandomIdList);
				}
				_customBGControl.Load(id, isDisplaySoon: false, null);
			}
		}
		if (!_loadResourceFinish)
		{
			LoadResource();
		}
		while (!_loadResourceFinish || (_customBGControl != null && _customBGControl.IsLoading))
		{
			yield return null;
		}
		LocalLog.AddRoomCreateLog("Setup3 ");
		if (Data.Load.data._userTutorial.TutorialStep == 31)
		{
			StartCoroutine(OpenFirstTipsAndGuid(FirstTips.TipsType.MyPage));
		}
		while (!IsCardLoadFinish)
		{
			yield return null;
		}
		while (!CommonBackGround.Instance.IsFinishLod)
		{
			yield return null;
		}
		LocalLog.AddRoomCreateLog("Setup4 ");
		yield return StartCoroutine(SetupFinish());
	}

	private void RefreshStaticData()
	{
		GameMgr.GetIns().GetDataMgr().SetQuestBattleData(null);
		PracticePuzzleUI.ClearInMyPageScene();
		GameMgr.GetIns().GetDataMgr().QuestFirstSelectType = QuestSelectionPage.FirstSelectType.NONE;
		Data.RedEtherCampaignResultData = null;
	}

	private IEnumerator SetupFinish()
	{
		LocalLog.AddRoomCreateLog("SetupFinish ");
		if (_isFirstLoad)
		{
			_isFirstLoad = false;
			GameMgr.GetIns().GetSoundMgr().Stop_Play_BGM(Bgm.BGM_TYPE.HOME, null, 0.5f);
			ParticleSystem bgEffect = CommonBackGround.Instance.GetBgEffectNow(CommonBackGround.Instance.BGType);
			while (!bgEffect.GetComponent<EffectSetUp>().isFinished)
			{
				yield return null;
			}
			UIManager.GetInstance().DestroyView(UIManager.ViewScene.Title);
			if (0 == 0)
			{
				FadeOpen();
			}
		}
		else
		{
			FadeOpen();
		}
	}

	private void FadeOpen()
	{
		LocalLog.AddRoomCreateLog("FadeOpen ");
		IsSetupComplete = true;
		_pageItemHome.OnMyPageFadeOpen(_currentIndex == 0);
		GameMgr.GetIns().GetSoundMgr().PlayBGM(Bgm.BGM_TYPE.HOME);
		UIManager.GetInstance().OnReadyViewScene(isFadein: true, null, delegate
		{
			IsFadeoutEnd = true;
		});
	}

	protected override void OnDestroy()
	{
		base.OnDestroy();
		UnloadResource();
		DestroyMyPageItem();
		resetAssetBaundleSetting();
	}

	private void Update()
	{
	}

	private void BackKeyCheck()
	{
	}

	private IEnumerator OpenFirstTipsAndGuid(FirstTips.TipsType type)
	{
		SetTutorialMode();
		_pageItemHome.SetGiftReceiveTutorialMode();
		bool finishTips = false;
		UIManager.GetInstance().StartFirstTips(type, delegate
		{
			finishTips = true;
		});
		while (!finishTips)
		{
			yield return null;
		}
		DialogBase dialogBase = CreateDialogForTutorial();
		dialogBase.SetTitleLabel(Data.SystemText.Get("Dia_Home_001_Title"));
		dialogBase.SetText(Data.SystemText.Get("Tutorial_0010"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
		dialogBase.OnClose = delegate
		{
			_pageItemHome.SetGuideEffectToGiftButton();
		};
		SetGuideToOkOnlyDialog(dialogBase);
		_pageItemHome.SetFirstTips();
	}

	private IEnumerator FirstGuideDelay(DialogBase dialog, float delayTime)
	{
		yield return new WaitForSeconds(delayTime);
		if (dialog != null)
		{
			SetGuideToOkOnlyDialog(dialog);
		}
	}

	public void SetGuideToOkOnlyDialog(DialogBase dialog)
	{
		SetGuideEffect(dialog.Btn1GameObject.transform, new Vector3(-95f, 0f, 0f), -90f);
		dialog.OnCloseStart = (Action)Delegate.Combine(dialog.OnCloseStart, (Action)delegate
		{
			FirstGuidEffect.transform.parent = base.transform.parent;
			FirstGuidEffect.gameObject.SetActive(value: false);
		});
	}

	public void SetTutorialMode()
	{
		Footer footer = UIManager.GetInstance()._Footer;
		for (int i = 0; i < footer._underButtons.Length; i++)
		{
			footer.SetButtonEnableColorChange(i, btnIsEnable: false);
		}
		UIManager.SetObjectToGrey(TopBar.BuyCrystalButton.gameObject, b: true);
		TopBar.BuyCrystalButton.isEnabled = false;
		_homeStatic.SetTutorialMode();
		UIManager.GetInstance()._Footer.UpdateArenaBadgeIcon();
		UIManager.GetInstance()._Footer.SoloPlayIconDisp(inDisp: false);
	}

	public void FinishTutorialMode()
	{
		_homeStatic.FinishFirstTips();
	}

	public static DialogBase CreateDialogForTutorial()
	{
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		int num = LayerMask.NameToLayer(MYPAGE_LAYER_NAME);
		dialogBase.SetPanelDepth(3000);
		dialogBase.gameObject.SetLayer(num, isSetChildren: true);
		dialogBase.SetBackViewLayer(num);
		return dialogBase;
	}

	public void FinishFirstTips()
	{
		if (IsFirstGuid)
		{
			ResetFirstGuide();
			Footer footer = UIManager.GetInstance()._Footer;
			for (int i = 0; i < footer._underButtons.Length; i++)
			{
				footer.SetButtonEnableColorChange(i);
			}
			_pageItemHome.FinishFirstTips();
		}
	}

	public void ResetFirstGuide()
	{
		if (FirstGuidEffect != null)
		{
			FirstGuidEffect.Stop();
			FirstGuidEffect.transform.parent = _firstGuidEffectParent;
		}
	}

	private IEnumerator GetMyPageInfo()
	{
		LocalLog.AddRoomCreateLog("GetMyPageInfo1 ");
		while (Toolbox.NetworkManager == null && !Global.IS_LOAD_ALLDONE)
		{
			yield return null;
		}
		TopBar.NameLabel.text = PlayerStaticData.UserName;
		TopBar.RupyLabel.gameObject.SetActive(value: false);
		TopBar.CrystalLabel.gameObject.SetActive(value: false);
		TopBar.RankTexture.gameObject.SetActive(value: false);
		TopBar.SetActiveBattlePoint(isActive: false);
		UIManager uiMgr = UIManager.GetInstance();
		uiMgr.createInSceneCenterLoading();
		if (TaskManager.GetInstance().IsMyPageSend())
		{
			LocalLog.SendLastTraceLog(null);
		}
		LocalLog.AddRoomCreateLog("GetMyPageInfo2 ");
		yield return StartCoroutine(MasterResetMonthTask.MasterReset());
		MyPageTask task = GameMgr.GetIns().GetMyPageTask();
		task.SetParameter();
		yield return StartCoroutine(Toolbox.NetworkManager.Connect(task, OnRequestMyPageLoad));
		while (!task.isServerResultCodeOK() || task.IsResourceVersionUpError)
		{
			yield return null;
		}
		LocalLog.AddRoomCreateLog("GetMyPageInfo3 ");
		WinnerRewardInfoCopy.Clear();
		foreach (CampaignRewardInfo reward in Data.MyPageNotifications.data.CampaignBattleWin.RewardList)
		{
			WinnerRewardInfoCopy.Add(reward);
		}
		bool finishDeckInfoTask = false;
		_homeStatic.CenterCardCreateStart(delegate
		{
			finishDeckInfoTask = true;
		});
		while (!finishDeckInfoTask)
		{
			yield return null;
		}
		yield return StartCoroutine(_pageItemShop.CrystalAppeal.Initialize(Data.MyPage.data.ServerUnixTime));
		TopBar.RupyLabel.gameObject.SetActive(value: true);
		TopBar.CrystalLabel.gameObject.SetActive(value: true);
		LocalLog.AddRoomCreateLog("GetMyPageInfo4 ");
		if (Data.MyPage.data.IsExistUnfinishedBattle)
		{
			DateTime startTime = DateTime.Now;
			while ((DateTime.Now - startTime).TotalMilliseconds < (double)Data.MyPage.data.BattleFinishWaitTime)
			{
				yield return null;
			}
			MyPageFinishBattleTask myPageFinishBattleTask = new MyPageFinishBattleTask();
			myPageFinishBattleTask.SetParameter();
			if (Data.TreasureBoxCp.IsReceivable)
			{
				_treasureBoxCpRewardDialogClosed = false;
				myPageFinishBattleTask.UnfinishedBattleDialogCloseCallBack = delegate
				{
					UIManager.GetInstance().StartCoroutine(OpenTreasureBoxCpTreasureBox());
				};
			}
			yield return StartCoroutine(Toolbox.NetworkManager.Connect(myPageFinishBattleTask));
			while (!task.isServerResultCodeOK())
			{
				yield return null;
			}
		}
		else
		{
			_ = Data.MyPage.data.IsExistUnfinishedRoom;
		}
		if (Data.TreasureBoxCp.IsReceivable && !Data.MyPage.data.CanGiveDailyLoginBonus && !Data.MyPage.data.IsExistUnfinishedBattle)
		{
			_treasureBoxCpRewardDialogClosed = false;
			UIManager.GetInstance().StartCoroutine(OpenTreasureBoxCpTreasureBox());
		}
		LocalLog.AddRoomCreateLog("GetMyPageInfo5 ");
		uiMgr.closeInSceneCenterLoading();
		TopBar.RankTexture.gameObject.SetActive(value: true);
		TopBar.SetActiveBattlePoint(isActive: true);
		Format inFormat = PlayerStaticData.HighRankFormat();
		PlayerStaticData.LoadUserRankTexture(inFormat);
		PlayerStaticData.AttachUserEmblemTexture(TopBar.EmblemTexture, PlayerStaticData.EmblemTexSize.M);
		PlayerStaticData.AttachUserRankTexture(TopBar.RankTexture, PlayerStaticData.RankTexSize.S);
		if (PlayerStaticData.IsMasterRank(inFormat))
		{
			TopBar.SetBattlePoint(PlayerStaticData.UserMasterPointHighAllFormat(), PlayerStaticData.IsMasterRank(inFormat));
		}
		else
		{
			TopBar.SetBattlePoint(PlayerStaticData.UserBattlePointHighFormat(), PlayerStaticData.IsMasterRank(inFormat));
		}
		while (!_changeMenuCalled)
		{
			yield return null;
		}
		_changeMenuCalled = false;
		MyPageItem[] pageItem = _pageItem;
		for (int num = 0; num < pageItem.Length; num++)
		{
			pageItem[num].OnMyPageInfoReceive();
		}
	}

	private IEnumerator OpenTreasureBoxCpTreasureBox()
	{
		GameMgr.GetIns().GetInputMgr().isBackKeyEnable = false;
		int rupyNumBeforeOpenTreasureBox = PlayerStaticData.UserRupyCount;
		MypageTreasureBoxCpOpenTask treasureBoxCpOpentask = new MypageTreasureBoxCpOpenTask();
		treasureBoxCpOpentask.SetParameter();
		yield return StartCoroutine(Toolbox.NetworkManager.Connect(treasureBoxCpOpentask, delegate
		{
			string atlasName = UIManager.GetInstance().GetSceneAssetPath(UIAtlasManager.AssetBundleNames.Arena, null);
			_loadFileList.Add(atlasName);
			UIManager.GetInstance().StartCoroutine(Toolbox.ResourcesManager.LoadAssetAsync(atlasName, delegate
			{
				atlasName = UIManager.GetInstance().GetSceneAssetPath(UIAtlasManager.AssetBundleNames.Arena, null, isload: true);
				UIAtlas component = Toolbox.ResourcesManager.LoadObject<GameObject>(atlasName).GetComponent<UIAtlas>();
				UIManager.GetInstance().StartCoroutine(RunOpenBoxEffect(treasureBoxCpOpentask.Result, component, rupyNumBeforeOpenTreasureBox, delegate
				{
					CreateTreasureBoxCpRewardDialog(treasureBoxCpOpentask.Result, delegate
					{
						RunHideBoxEffect();
						UIManager.GetInstance().UpDateRupyNum();
					});
				}));
			}));
		}));
	}

	private void OnRequestMyPageLoad(NetworkTask.ResultCode error)
	{
		if (Data.Load.data._receiveInviteCount > 0)
		{
			_isEnableRoomInvite = true;
		}
		else
		{
			_isEnableRoomInvite = false;
		}
		bool flag = false;
		if (Data.MyPageNotifications.data.CampaignBattleWin.SpecialTreasureInfo != null)
		{
			flag = Data.MyPageNotifications.data.CampaignBattleWin.SpecialTreasureInfo.IsTreasureBoxReadyToOpen;
		}
		UIManager.GetInstance()._Footer.InviteIconDisp(_isEnableRoomInvite || flag);
		UpdateCrystalCount();
		UpdateRupyCount();
		IsMyPageRequestEnd = true;
	}

	private void LoadResource()
	{
		UIManager uiManager = UIManager.GetInstance();
		ResourcesManager resourceManager = Toolbox.ResourcesManager;
		List<MyPageCardPanel> cardPanelList = new List<MyPageCardPanel>();
		MyPageItem[] pageItem = _pageItem;
		for (int i = 0; i < pageItem.Length; i++)
		{
			MyPageCardPanel[] cardPanelList2 = pageItem[i].CardPanelList;
			foreach (MyPageCardPanel myPageCardPanel in cardPanelList2)
			{
				if (!string.IsNullOrEmpty(myPageCardPanel.FilePath) && !(myPageCardPanel.Texture == null))
				{
					string resourcePath = myPageCardPanel.GetResourcePath(isfetch: false);
					_loadFileList.Add(resourcePath);
					cardPanelList.Add(myPageCardPanel);
					uiManager.Force_Increment_LockCountChangeView();
				}
			}
		}
		resourceManager.StartCoroutine_LoadAssetGroupSync(_loadFileList, delegate
		{
			_loadResourceFinish = true;
			int k = 0;
			for (int count = cardPanelList.Count; k < count; k++)
			{
				MyPageCardPanel myPageCardPanel2 = cardPanelList[k];
				myPageCardPanel2.Texture.mainTexture = resourceManager.LoadObject(myPageCardPanel2.GetResourcePath(isfetch: true)) as Texture;
				uiManager.Force_Decrement_LockCountChangeView();
			}
		});
	}

	private void AttachCardPanelTexture()
	{
		MyPageItem[] pageItem = _pageItem;
		for (int i = 0; i < pageItem.Length; i++)
		{
			MyPageCardPanel[] cardPanelList = pageItem[i].CardPanelList;
			foreach (MyPageCardPanel myPageCardPanel in cardPanelList)
			{
				if (!string.IsNullOrEmpty(myPageCardPanel.FilePath) && !(myPageCardPanel.Texture == null))
				{
					myPageCardPanel.AttachCardPanelTexture();
				}
			}
		}
	}

	private void UnloadResource()
	{
		Toolbox.ResourcesManager.RemoveAssetGroup(_loadFileList);
		_loadFileList.Clear();
	}

	public void ReloadCardCircle()
	{
		_homeStatic.ReloadCardCircle();
	}

	public static void SetEnableReloadCard()
	{
		if (!(Instance == null))
		{
			Data.MyPage.CardUpdateFlag = true;
		}
	}

	public int GetDetailCardCount()
	{
		return _homeStatic.GetDetailCardCount();
	}

	private void HideNameWindow()
	{
		iTween.MoveTo(TopBar.NameWindowObject, iTween.Hash("x", TopBar.NameWindowObject.transform.localPosition.x - 450f, "time", 0.3f, "delay", 0f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
	}

	public void RemoveTween(GameObject obj)
	{
		iTween component = obj.GetComponent<iTween>();
		if (component != null)
		{
			UnityEngine.Object.Destroy(component);
		}
	}

	public void SetBackButtonEnable()
	{
		HideNameWindow();
		TopBar.SetBackButtonActive(inActive: true);
		RemoveTween(TopBar.TitleObject.gameObject);
		RemoveTween(TopBar.BackButton.gameObject);
		TopBar.RestorePosition();
		iTween.MoveFrom(TopBar.TitleObject, iTween.Hash("y", TopBar.TitleObject.transform.localPosition.y + 500f, "time", 0.3f, "delay", 0.1f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
		iTween.MoveFrom(TopBar.BackButton.gameObject, iTween.Hash("y", TopBar.BackButton.transform.localPosition.y + 500f, "time", 0.3f, "delay", 0.1f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
	}

	public void SetNameBarEnable()
	{
		iTween.MoveTo(TopBar.NameWindowObject, iTween.Hash("x", _nameWindowDefaultX, "time", 0.3f, "delay", 0, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
		TopBar.SetBackButtonActive(inActive: false);
		TopBar.ChangeNameWindowMode();
	}

	public void ChangeMenu(int index, bool isCutCardMotion = false)
	{
		UIManager.GetInstance()._Footer.UpdateCurrentIndex(index);
		SetNameBarEnable();
		SetDefaultBackButtonHandler();
		if (!_isFirstChangeMenuCall && _currentIndex >= 0 && _currentIndex < _pageItem.Length)
		{
			_pageItem[_currentIndex].Hide();
			if (_currentIndex == 0 && _currentIndex != index)
			{
				OnChangeFromHome();
			}
		}
		_currentIndex = index;
		if (index >= 0 && index < _pageItem.Length)
		{
			_pageItem[index].Show(isCutCardMotion);
		}
		bool flag = index == 0;
		CommonBackGround.Instance.SetMagicCircle(!flag);
		Offline.IsConventionMode = false;
		_changeMenuCalled = true;
		_isFirstChangeMenuCall = false;
	}

	private void OnChangeFromHome()
	{
		if (!(_customBGControl == null))
		{
			if (Data.MyPage.data.BGInfo.BGType == MyPageDetail.BGType.RandomBG)
			{
				RemakeCustomBgForRandom();
			}
			if (Data.MyPage.data.BGInfo.BGType == MyPageDetail.BGType.CustomBG)
			{
				_customBGControl.FadeOut();
			}
			CommonBackGround.Instance.EffectVisible = true;
		}
	}

	private void OnRemakeCustomBg()
	{
		_remakeCustomBgCount++;
		if (_remakeCustomBgCount >= 50)
		{
			_remakeCustomBgCount = 0;
			ReleaseMemory(runGCCollect: true);
		}
	}

	private static void ReleaseMemory(bool runGCCollect)
	{
		UIManager.GetInstance().StartCoroutine(ReleaseMemoryBody(runGCCollect));
	}

	private static IEnumerator ReleaseMemoryBody(bool runGCCollect)
	{
		yield return Resources.UnloadUnusedAssets();
		if (runGCCollect)
		{
			GC.Collect();
		}
	}

	private void RemakeCustomBgForRandom()
	{
		string text = MyPageItemHome.DecideRandomBG(Data.MyPage.data.BGInfo.RandomIdList);
		if (_customBGControl != null && text == _customBGControl.Id)
		{
			_customBGControl.FadeOut();
			return;
		}
		_customBGControl.FadeOutDestroy();
		_customBGControl = null;
		_customBGControl = NGUITools.AddChild(_customBGControlOriginal.transform.parent.gameObject, _customBGControlOriginal.gameObject).GetComponent<MyPageCustomBGControl>();
		_customBGControl.gameObject.SetActive(value: true);
		UIManager.GetInstance().OpenNotTouch();
		_customBGControl.Load(text, isDisplaySoon: false, delegate
		{
			UIManager.GetInstance().offNotTouch();
			OnRemakeCustomBg();
		});
	}

	public void SetDefaultBackButtonHandler()
	{
		TopBar.SetBackButtonEvent(null, UIManager.ViewScene.None, new EventDelegate(delegate
		{
			_pageItem[_currentIndex].Show();
			SetNameBarEnable();
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_SWITCH_MENU);
		}));
	}

	public void GoToFreeMatch()
	{
		SetBackButtonEnable();
		_pageItemBattle.GoToFreeMatch();
	}

	public void GoToRoomMatch()
	{
		SetBackButtonEnable();
		_pageItemBattle.GoToRoomMatch();
	}

	public void SetAfterSpecialWinRewardOpened()
	{
		_pageItemBattle.SpecialWinRewardIconActive(active: false);
		_pageItemBattle.RedrawBattleCampaign();
		_pageItemArena.RedrawBattleCampaign();
	}

	public void GoToPracticeTypeSelect()
	{
		_pageItemSoroPlay.GotoPracticeTypeSelect();
	}

	public void GoToChallengeMenu()
	{
		_pageItemArena.GoToChallengeMenu();
	}

	public void GoToColosseum(bool isColosseumTask = true)
	{
		_pageItemArena.GoToColosseum(isColosseumTask);
	}

	public void GoToCompetition()
	{
		_pageItemArena.GoToCompetition();
	}

	public void GoToConventionListMenu()
	{
		_pageItemArena.GoToConventionListMenu();
	}

	public void GoToConventionActionMenu(ConventionInfo conventionInfo)
	{
		_pageItemArena.GoToConventionActionMenu(conventionInfo);
	}

	public void GoToGatheringActionMenu()
	{
		_pageItemArena.GoToGatheringMenu();
	}

	public void GoToShopSupply()
	{
		_pageItemShop.GoToShopSupply();
	}

	public void GoToShopCard()
	{
		_pageItemShop.GoToShopCard();
	}

	public void GoToCardDeck()
	{
		_pageItemCard.GoToCardDeck();
	}

	private static UIManager.ChangeViewSceneParam CreateMyPageChangeParam(int index, bool isCutCard)
	{
		return new UIManager.ChangeViewSceneParam
		{
			MyPageMenuIndex = index,
			IsCutCardMotion = isCutCard,
			IsUpdateFooterMenuTexture = true
		};
	}

	public static void ChangeSceneAndBuyCard(Action onChange)
	{
		UIManager.ChangeViewSceneParam changeViewSceneParam = CreateMyPageChangeParam(5, isCutCard: true);
		changeViewSceneParam.OnFinishChangeView = delegate
		{
			Instance.GoToShopCard();
			onChange.Call();
		};
		UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.MyPage, changeViewSceneParam);
	}

	public static void ChangeSceneAndBuySupply(Action onChange)
	{
		UIManager.GetInstance()._Footer.UpdateCurrentIndex(5);
		UIManager.ChangeViewSceneParam changeViewSceneParam = CreateMyPageChangeParam(5, isCutCard: true);
		changeViewSceneParam.OnFinishChangeView = delegate
		{
			Instance.GoToShopSupply();
			onChange.Call();
		};
		UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.MyPage, changeViewSceneParam);
	}

	public void ShowBanner()
	{
		if (_pageItemHome != null)
		{
			_pageItemHome.ShowBanner();
		}
	}

	public void HideBanner()
	{
		if (_pageItemHome != null)
		{
			_pageItemHome.HideBanner();
		}
	}

	public void RoomInviteClear()
	{
		_isEnableRoomInvite = false;
	}

	public void OnReadGift()
	{
		if (_pageItemHome != null)
		{
			_pageItemHome.OnReadGift();
		}
	}

	private void OnClickCrystalBuyButton()
	{
	}

	private void OnClickNameWindow()
	{
		if (!IsFirstGuid)
		{
			GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
			UIManager.ChangeViewSceneParam changeViewSceneParam = new UIManager.ChangeViewSceneParam();
			changeViewSceneParam.IsUpdateFooterMenuTexture = true;
			changeViewSceneParam.OnChange = delegate
			{
				CommonBackGround.Instance.SetMagicCircle(isVisible: true);
			};
			UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.Profile, changeViewSceneParam);
		}
	}

	public void UpdateCrystalCount()
	{
		UIManager.GetInstance().UpDateCrystalNum();
	}

	public void UpdateRupyCount()
	{
		UIManager.GetInstance().UpDateRupyNum();
	}

	public void UpdateMissionCount()
	{
		if (_pageItemHome != null)
		{
			_pageItemHome.UpdateMissionNumber();
		}
	}

	public void ShowNotification(List<NotificatonAnimation.Param> notifications)
	{
		if (notifications.Count != 0)
		{
			if (_maintenanceNotification != null)
			{
				UnityEngine.Object.Destroy(_maintenanceNotification.gameObject);
				_maintenanceNotification = null;
			}
			_maintenanceNotification = NGUITools.AddChild(base.gameObject, _maintenanceNotificationPrefab.gameObject).GetComponent<MyPageMaintenanceNotification>();
			_maintenanceNotification.gameObject.layer = LayerMask.NameToLayer("SystemUI");
			StartCoroutine(_maintenanceNotification.Show(notifications));
		}
	}

	private IEnumerator RunOpenBoxEffect(MypageTreasureBoxCpOpenTask.MypageTreasureBoxCpOpenTaskData result, UIAtlas arenaAtlas, int rupyNumBeforeOpenTreasureBox, Action endAction)
	{
		UIManager.GetInstance().UpdateLastRupyNum(rupyNumBeforeOpenTreasureBox);
		while (!IsFadeoutEnd)
		{
			yield return null;
		}
		UIManager.GetInstance().OpenNotTouch();
		_notTouchMypageCollider.enabled = true;
		yield return new WaitForSeconds(1f);
		_boxOpenEffectObj = NGUITools.AddChild(base.gameObject, Resources.Load("UI/layoutParts/RankWinnerRewardResultPanel") as GameObject);
		NguiObjs component = _boxOpenEffectObj.GetComponent<NguiObjs>();
		UISprite bg = component.sprites[0];
		UISprite window = component.sprites[1];
		UISprite box = component.sprites[2];
		box.atlas = arenaAtlas;
		UILabel label = component.labels[0];
		label.text = Data.SystemText.Get("TreasureBoxCp_0026");
		UIPanel panel = _boxOpenEffectObj.GetComponent<UIPanel>();
		panel.alpha = 0f;
		box.spriteName = $"box_2pick_0{TreasureBoxCp.GRADE_TO_TREASURE_BOX_ID[result.Grade]}_close";
		string loadEffectName = $"cmn_arena_treasure_{TreasureBoxCp.GRADE_TO_TREASURE_BOX_ID[result.Grade] + 1}";
		List<string> list = new List<string>();
		list.Add(Toolbox.ResourcesManager.GetAssetTypePath(loadEffectName, ResourcesManager.AssetLoadPathType.Effect2D));
		yield return UIManager.GetInstance().StartCoroutine(Toolbox.ResourcesManager.LoadAssetGroupAsync(list, null));
		_treasureEffectObj = UnityEngine.Object.Instantiate(Toolbox.ResourcesManager.LoadObject(Toolbox.ResourcesManager.GetAssetTypePath(loadEffectName, ResourcesManager.AssetLoadPathType.Effect2D, isfetch: true)) as GameObject);
		_treasureEffectObj.transform.parent = _boxOpenEffectObj.transform;
		GameMgr.GetIns().GetEffectMgr().SetUIParticleShader(_treasureEffectObj, null);
		_boxOpenEffectObj.SetLayer(LayerMask.NameToLayer("SystemUI"), isSetChildren: true);
		bg.alpha = 0f;
		box.alpha = 0f;
		label.alpha = 0f;
		panel.alpha = 1f;
		TweenAlpha.Begin(bg.gameObject, 0.5f, 0.65f);
		TweenAlpha.Begin(label.gameObject, 0.5f, 1f);
		TweenAlpha.Begin(box.gameObject, 0.5f, 1f);
		label.transform.localPosition = new Vector3(100f, 0f, 0f);
		window.transform.localScale = new Vector3(1f, 0.01f, 1f);
		box.transform.localPosition = new Vector3(180f, 0f, 0f);
		iTween.MoveTo(label.gameObject, iTween.Hash("x", 20f, "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
		iTween.ScaleTo(window.gameObject, iTween.Hash("y", 1f, "time", 0.5f, "easetype", iTween.EaseType.easeInOutExpo));
		iTween.MoveTo(box.gameObject, iTween.Hash("y", 20f, "time", 0.5f, "islocal", true, "easetype", iTween.EaseType.easeOutExpo));
		yield return new WaitForSeconds(0.8f);
		TweenAlpha.Begin(label.gameObject, 0.5f, 0f);
		iTween.MoveTo(box.gameObject, iTween.Hash("x", 0f, "time", 0.7f, "islocal", true, "easetype", iTween.EaseType.easeInOutExpo));
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_2PICK_BOX_OPEN);
		yield return new WaitForSeconds(1f);
		_treasureEffectObj.transform.localPosition = box.transform.localPosition;
		_treasureEffectObj.transform.localScale = Vector3.one * 320f * 1.75f;
		_treasureEffectObj.SetActive(value: true);
		box.gameObject.SetActive(value: false);
		yield return new WaitForSeconds(1.2f);
		endAction.Call();
	}

	private void CreateTreasureBoxCpRewardDialog(MypageTreasureBoxCpOpenTask.MypageTreasureBoxCpOpenTaskData result, Action endAction)
	{
		if (result == null || result.RewardDataList.Count() <= 0)
		{
			_treasureBoxCpRewardDialogClosed = true;
			endAction.Call();
			return;
		}
		UIManager.GetInstance().createInSceneCenterLoading();
		DialogBase dialogBase = UIManager.GetInstance().CreateDialogClose();
		dialogBase.SetSize(DialogBase.Size.M);
		dialogBase.SetLayer("MyPage");
		dialogBase.SetPanelDepth(1000, isSetBackViewDepthImmediately: true);
		dialogBase.SetTitleLabel(Data.SystemText.Get("TreasureBoxCp_0001"));
		dialogBase.SetButtonLayout(DialogBase.ButtonLayout.OkBtn);
		dialogBase.SetPanelSortingOrder(37);
		dialogBase.OnClose = (Action)Delegate.Combine(dialogBase.OnClose, (Action)delegate
		{
			_treasureBoxCpRewardDialogClosed = true;
		});
		RewardBase component = NGUITools.AddChild(dialogBase.gameObject, _rewardBase.gameObject).GetComponent<RewardBase>();
		for (int num = 0; num < result.RewardDataList.Count; num++)
		{
			component.AddReward(result.RewardDataList[num]);
		}
		UIPanel component2 = component.gameObject.GetComponent<UIPanel>();
		component2.sortingOrder = 37;
		component2.depth = 1005;
		component.EndCreate();
		endAction.Call();
	}

	private void RunHideBoxEffect()
	{
		_treasureEffectObj.SetActive(value: false);
		_boxOpenEffectObj.SetActive(value: false);
		UnityEngine.Object.Destroy(_boxOpenEffectObj);
		UnityEngine.Object.Destroy(_treasureEffectObj);
		UIManager.GetInstance().offNotTouch();
		_notTouchMypageCollider.enabled = false;
		GameMgr.GetIns().GetInputMgr().isBackKeyEnable = true;
	}

	public static void SetMyPageRefreshDisableOnce()
	{
		if (!(Instance == null))
		{
			Instance._isStopMyPageRefreshOnce = true;
		}
	}

	protected void OnApplicationFocus(bool focusStatus)
	{
		if (focusStatus && _isStopMyPageRefreshOnce)
		{
			_isStopMyPageRefreshOnce = false;
		}
		else if (!UIManager.GetInstance().IsCrystalDialogExe && UIManager.GetInstance().GetCurrentScene() == UIManager.ViewScene.MyPage && focusStatus && !BattleMenu.IsStopSendMyPageRefreshTask() && !Toolbox.NetworkManager.isConnect && !Toolbox.NetworkManager.isTimeOut && !Toolbox.NetworkManager.isError && Data.MyPage != null && Data.MyPage.data != null)
		{
			MyPageRefreshTask myPageRefreshTask = new MyPageRefreshTask();
			myPageRefreshTask.SetParameter();
			StartCoroutine(Toolbox.NetworkManager.Connect(myPageRefreshTask, delegate
			{
				RefreshInviteIcon();
				RefreshGatheringNotification();
			}));
		}
	}

	private void RefreshInviteIcon()
	{
		bool isInvite = false;
		if (Data.Load.data._receiveInviteCount > 0)
		{
			isInvite = true;
		}
		bool isTreasureBoxReadyToOpen = false;
		if (Data.MyPageNotifications.data.CampaignBattleWin.SpecialTreasureInfo != null)
		{
			isTreasureBoxReadyToOpen = Data.MyPageNotifications.data.CampaignBattleWin.SpecialTreasureInfo.IsTreasureBoxReadyToOpen;
		}
		ReceivedInvite(isInvite, isTreasureBoxReadyToOpen);
	}

	private void RefreshGatheringNotification()
	{
		UIManager.GetInstance()._Footer.UpdateArenaBadgeIcon();
		if (_pageItemArena != null)
		{
			_pageItemArena.ShowGatheringBadge();
		}
	}

	public void ReceivedInvite(bool isInvite, bool isTreasureBoxReadyToOpen = false)
	{
		_isEnableRoomInvite = isInvite;
		UIManager.GetInstance()._Footer.InviteIconDisp(isInvite || isTreasureBoxReadyToOpen);
	}

	public void SpecialWinRewardOpened()
	{
		bool isEnableRoomInvite = _isEnableRoomInvite;
		UIManager.GetInstance()._Footer.InviteIconDisp(isEnableRoomInvite);
	}

	public BoxCollider GetNotTouchMypageCollider()
	{
		return _notTouchMypageCollider;
	}

	public void SetGatheringPush(bool isNotification)
	{
		Data.MyPageNotifications.data.GatheringMyPageInfo.IsMatchingNotification = isNotification;
		UIManager.GetInstance()._Footer.UpdateArenaBadgeIcon();
	}

	public void SetGuideEffect(Transform parent, Vector3 localPosition, float rotation)
	{
		if (!(FirstGuidEffect == null))
		{
			FirstGuidEffect.gameObject.SetActive(value: true);
			FirstGuidEffect.transform.parent = parent;
			FirstGuidEffect.transform.localPosition = localPosition;
			FirstGuidEffect.transform.localRotation = Quaternion.Euler(0f, 0f, rotation);
			FirstGuidEffect.gameObject.SetLayer(parent.gameObject.layer, isSetChildren: true);
		}
	}
}
