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

public class MyPageItemSoroPlay : MyPageItem
{
	private readonly Vector3 CARD_POS_LEFT = new Vector3(-203f, 0f, 0f);

	private readonly Vector3 CARD_POS_RIGHT = new Vector3(203f, 0f, 0f);

	private readonly Vector3 CARD_POS_QUEST_EXIST_LEFT = new Vector3(-367f, 0f, 0f);

	private readonly Vector3 CARD_POS_QUEST_EXIST_CENTER = new Vector3(0f, 20f, 0f);

	private readonly Vector3 CARD_POS_QUEST_EXIST_RIGHT = new Vector3(367f, 0f, 0f);

	[SerializeField]
	private UIButton _storyButton;

	[SerializeField]
	private UIButton _practiceButton;

	[SerializeField]
	private UIButton _questButton;

	[SerializeField]
	private StoryCardPanel _storyCardPanel;

	[SerializeField]
	private MyPageCardPanel _practiceCardPanel;

	[SerializeField]
	private GameObject _practiceTypeSelectRoot;

	[SerializeField]
	private UIButton _practiceBattleButton;

	[SerializeField]
	private UIButton _practiceBattlePazzle;

	[SerializeField]
	private UILabel _practiceTypePuzzleLabel;

	[SerializeField]
	private MyPageCardPanel _questCardPanel;

	[SerializeField]
	private GameObject _questExtraIcon;

	[SerializeField]
	private GameObject _questBand;

	[SerializeField]
	private UILabel _questBandLabel;

	[SerializeField]
	private GameObject _questEndTimeRoot;

	[SerializeField]
	private UILabel _questEndTimeLabel;

	[SerializeField]
	private GameObject _practiceBadge;

	[SerializeField]
	private GameObject _puzzleBadge;

	public static readonly Quaternion EFFECT_ROTATION = Quaternion.Euler(0f, 0f, -38f);

	private CardPanelMaintenancePlate _puzzleMaintenancePlate;

	private void Start()
	{
		_storyButton.onClick.Add(new EventDelegate(delegate
		{
			OnPushMainStory();
		}));
		_questButton.onClick.Add(new EventDelegate(delegate
		{
			OnPushQuest();
		}));
		_practiceBattleButton.onClick.Add(new EventDelegate(delegate
		{
			OnClickPracticeTypeBattle();
		}));
		_practiceBattlePazzle.onClick.Add(new EventDelegate(delegate
		{
			OnClickPracticeTypePuzzle();
		}));
	}

	public override void Initialize(MyPageMenu parent)
	{
		base.Initialize(parent);
		SaveDefaultPosition(_practiceTypeSelectRoot);
	}

	public override void Show(bool skipCardAnimation = false)
	{
		base.Show(skipCardAnimation);
		SetCardPanelAnimation();
		StartCardPanelAppearAnimation();
		_practiceButton.onClick.Clear();
		_practiceButton.onClick.Add(new EventDelegate(delegate
		{
			OnPushPractive();
		}));
		UpdateQuestBadgeIcon();
		_questBandLabel.text = Data.MyPageNotifications.data.QuestOpenInfo.QuestPanelBandText;
		_questBand.SetActive(value: true);
		_questEndTimeRoot.SetActive(value: true);
		_practiceTypeSelectRoot.SetActive(value: false);
		_storyCardPanel.DispAppealRibbon(Data.MyPageNotifications.data.StoryNotification.IsDisplayRibbon);
		_storyCardPanel.DispAppealBadge(Data.MyPageNotifications.data.StoryNotification.IsDisplayBadge);
		_practiceBadge.SetActive(Data.MyPageNotifications.data.IsPracticePuzzleBadgeEnable);
		_puzzleBadge.SetActive(Data.MyPageNotifications.data.IsPracticePuzzleBadgeEnable);
		UIManager.GetInstance().CheckFirstTips(FirstTips.TipsType.SoroPlay2);
	}

	private void SetCardPanelAnimation()
	{
		for (int i = 0; i < base.CardPanelList.Length; i++)
		{
			MyPageCardPanel obj = base.CardPanelList[i];
			obj.gameObject.SetActive(value: true);
			obj.EffectActive = false;
			obj.EffectActive = true;
			obj.CheckMaintenanceType();
		}
		if (Data.MyPageNotifications.data.QuestOpenInfo.IsOpen)
		{
			_questCardPanel.gameObject.SetActive(value: true);
			_storyCardPanel.transform.localPosition = CARD_POS_QUEST_EXIST_LEFT;
			_questCardPanel.transform.localPosition = CARD_POS_QUEST_EXIST_CENTER;
			_practiceCardPanel.transform.localPosition = CARD_POS_QUEST_EXIST_RIGHT;
			_questEndTimeLabel.text = Data.SystemText.Get("MyPage_0048", ConvertTime.ToLocal(Data.MyPageNotifications.data.QuestOpenInfo.EndTime));
		}
		else
		{
			_questCardPanel.gameObject.SetActive(value: false);
			_storyCardPanel.transform.localPosition = CARD_POS_LEFT;
			_practiceCardPanel.transform.localPosition = CARD_POS_RIGHT;
		}
		List<GameObject> list = new List<GameObject>();
		for (int j = 0; j < base.CardPanelList.Length; j++)
		{
			MyPageCardPanel myPageCardPanel = base.CardPanelList[j];
			if (myPageCardPanel.isActiveAndEnabled)
			{
				list.Add(myPageCardPanel.gameObject);
			}
		}
		SaveCardPanelDefaultPosition();
		base.CardAnimation.PanelClear();
		base.CardAnimation.SetCardPanelList(list.ToArray());
		base.CardAnimation.SetCardPanelAngle();
	}

	private void OnPushMainStory()
	{
		if (!base.IsCardMoving)
		{
			base.CardAnimation.OnClicked(_storyCardPanel.Index);
			Data.SelectedStoryInfo = new SelectedStoryInfo(StoryEntranceType.AllStory);
			UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.StorySelectionWorld);
		}
	}

	public void GotoPracticeTypeSelect()
	{
		ShowPracticeTypeSelect();
	}

	private void OnPushPractive()
	{
		if (!base.IsCardMoving)
		{
			base.CardAnimation.OnClicked(_practiceCardPanel.Index);
			ShowPracticeTypeSelect();
		}
	}

	private void ShowPracticeTypeSelect()
	{
		_practiceButton.onClick.Clear();
		bool isMaintenance = Data.MaintenanceCodeList.Contains(NetworkDefine.MAINTENANCE_TYPE.PRACTICE_PUZZLE);
		_puzzleMaintenancePlate = MyPageItem.SetMaintenanceVisible(isMaintenance, _practiceBattlePazzle, _puzzleMaintenancePlate, _practiceTypePuzzleLabel.depth);
		base.TopBar.SetTitleLabel(Data.SystemText.Get("MyPage_0009"));
		base.IsEnableFooterCurrentMenu = true;
		FadeOutCardPanel(_storyCardPanel, null);
		if (Data.MyPageNotifications.data.QuestOpenInfo.IsOpen)
		{
			FadeOutCardPanel(_questCardPanel, null);
		}
		MoveCardPanelLeftPosition(_practiceCardPanel.gameObject);
		_practiceTypeSelectRoot.SetActive(value: true);
		RestoreDefaultPosition(_practiceTypeSelectRoot.gameObject);
		AppearAnimationFromRight(_practiceTypeSelectRoot);
		base.Parent.SetBackButtonEnable();
	}

	private void OnClickPracticeTypeBattle()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		GameMgr.GetIns().GetDataMgr().m_BattleType = DataMgr.BattleType.Practice;
		PracticeDeckInfoTask task = new PracticeDeckInfoTask();
		UIManager.GetInstance().StartCoroutine(Toolbox.NetworkManager.Connect(task, delegate
		{
			Format value = (Format)PlayerPrefsWrapper.GetValue(PlayerPrefsWrapper.LAST_SELECT_DECK_FORMAT);
			DeckSelectUIDialog.Create(Data.SystemText.Get("Story_0017"), task.DeckGroupListData, value, DeckSelectUIDialog.eFormatChangeUIType.UseOtherCategory, isVisibleCreateNew: true, delegate(DialogBase dialog, DeckData deck)
			{
				PracticeDeckSelectConfirmDialog.Create(dialog, deck, isBattleAgain: false);
			});
		}));
	}

	private void OnClickPracticeTypePuzzle()
	{
		GameMgr.GetIns().GetSoundMgr().PlaySe(Se.TYPE.SYS_BTN_DECIDE);
		UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.PracticePuzzle);
	}

	private void OnPushQuest()
	{
		if (!base.IsCardMoving)
		{
			_questExtraIcon.SetActive(value: false);
			base.CardAnimation.OnClicked(_questCardPanel.Index);
			UIManager.GetInstance().ChangeViewScene(UIManager.ViewScene.QuestSelectionPage);
		}
	}

	public void UpdateQuestBadgeIcon()
	{
		bool active = false;
		if (Data.Load.data._userTutorial.TutorialStep == 100)
		{
			active = Data.MyPageNotifications.data.QuestOpenInfo.IsDisplayBadge;
		}
		_questExtraIcon.SetActive(active);
	}
}
