238 lines
6.6 KiB
C#
238 lines
6.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Cute;
|
|
using UnityEngine;
|
|
using Wizard.DeckSelect.FirstDisplayPageIndexGetter;
|
|
|
|
namespace Wizard;
|
|
|
|
public class DeckSelectUI : MonoBehaviour
|
|
{
|
|
public class InitOptions
|
|
{
|
|
}
|
|
|
|
private enum ChangeMoveDirection
|
|
{
|
|
NONE,
|
|
RIGHT,
|
|
LEFT
|
|
}
|
|
|
|
public class PageData
|
|
{
|
|
public Format Format { get; private set; }
|
|
|
|
public DeckAttributeType AttributeType { get; private set; }
|
|
|
|
public string GroupName { get; private set; }
|
|
|
|
public List<DeckUI.DeckViewData> DeckViewList { get; private set; }
|
|
|
|
public static List<PageData> CreatePageList(List<DeckGroup> deckGroupList, bool isVisibleCreateNew)
|
|
{
|
|
List<PageData> list = new List<PageData>();
|
|
foreach (DeckGroup deckGroup in deckGroupList)
|
|
{
|
|
List<DeckUI.DeckViewData> list2 = DeckUI.DeckViewData.CreateDeckViewList(deckGroup.DeckDataList, isVisibleCreateNew);
|
|
if (!list2.Any((DeckUI.DeckViewData d) => d.ViewType != DeckUI.eViewType.Empty))
|
|
{
|
|
continue;
|
|
}
|
|
int num = 0;
|
|
for (int num2 = 0; num2 < list2.Count; num2++)
|
|
{
|
|
if (num2 % 9 == 0)
|
|
{
|
|
if (list2[num2].ViewType == DeckUI.eViewType.Empty)
|
|
{
|
|
break;
|
|
}
|
|
num++;
|
|
string groupName = DeckListUtility.DeckListHeader(deckGroup.AttributeType, num);
|
|
list.Add(new PageData(new List<DeckUI.DeckViewData>(), deckGroup.DeckFormat, deckGroup.AttributeType, groupName));
|
|
}
|
|
list.Last().AddDeckViewList(list2[num2]);
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
private PageData(List<DeckUI.DeckViewData> deckViewList, Format format, DeckAttributeType attributeType, string groupName)
|
|
{
|
|
DeckViewList = deckViewList;
|
|
Format = format;
|
|
AttributeType = attributeType;
|
|
GroupName = groupName;
|
|
}
|
|
|
|
private void AddDeckViewList(DeckUI.DeckViewData deckViewData)
|
|
{
|
|
DeckViewList.Add(deckViewData);
|
|
}
|
|
}
|
|
|
|
private class DeckTable
|
|
{
|
|
private List<DeckUI> _deckUIList = new List<DeckUI>();
|
|
|
|
private Action<DeckUI> _onUpdateDeckUICustomize;
|
|
|
|
public GameObject Obj { get; private set; }
|
|
|
|
public DeckTable(UIGrid uiGrid, DeckUI originalDeckUI, Action<DeckUI> onClick, Action<Vector2> onDrag, Action<DeckUI> onUpdateDeckUICustomize)
|
|
{
|
|
_onUpdateDeckUICustomize = onUpdateDeckUICustomize;
|
|
for (int i = 0; i < 9; i++)
|
|
{
|
|
DeckUI component = NGUITools.AddChild(uiGrid.gameObject, originalDeckUI.gameObject).GetComponent<DeckUI>();
|
|
component.Initialize(onClick);
|
|
UIEventListener uIEventListener = UIEventListener.Get(component.gameObject);
|
|
uIEventListener.onDrag = (UIEventListener.VectorDelegate)Delegate.Combine(uIEventListener.onDrag, (UIEventListener.VectorDelegate)delegate(GameObject g, Vector2 v)
|
|
{
|
|
onDrag.Call(v);
|
|
});
|
|
_deckUIList.Add(component);
|
|
component.gameObject.SetActive(value: false);
|
|
}
|
|
uiGrid.repositionNow = true;
|
|
Obj = uiGrid.gameObject;
|
|
Obj.SetActive(value: true);
|
|
}
|
|
|
|
public void UpdateDeckViewList(List<DeckUI.DeckViewData> deckViewList, bool canUseNonPossessionCard)
|
|
{
|
|
for (int i = 0; i < _deckUIList.Count; i++)
|
|
{
|
|
if (deckViewList.Count > i)
|
|
{
|
|
DeckUI deckUI = _deckUIList[i];
|
|
deckUI.gameObject.SetActive(value: true);
|
|
deckUI.UpdateView(deckViewList[i], canUseNonPossessionCard);
|
|
_onUpdateDeckUICustomize.Call(deckUI);
|
|
}
|
|
else
|
|
{
|
|
_deckUIList[i].gameObject.SetActive(value: false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private static readonly Vector3 VIEW_PAGE_POSITION = Vector3.zero;
|
|
|
|
private static readonly Vector3 OUTSIDE_RIGHT_PAGE_POSITION = VIEW_PAGE_POSITION + Vector3.right * 1400f;
|
|
|
|
private static readonly Vector3 OUTSIDE_LEFT_PAGE_POSITION = VIEW_PAGE_POSITION + Vector3.left * 1400f;
|
|
|
|
[SerializeField]
|
|
private UILabel _titleLabel;
|
|
|
|
[SerializeField]
|
|
private GameObject _deckTableRoot;
|
|
|
|
[SerializeField]
|
|
private UIPageIndicator _pageIndicatorOriginal;
|
|
|
|
private UIPageIndicator _pageIndicator;
|
|
|
|
[SerializeField]
|
|
private GameObject _pageIndicatorRoot;
|
|
|
|
[SerializeField]
|
|
private UIButton _leftButton;
|
|
|
|
[SerializeField]
|
|
private UIButton _rightButton;
|
|
|
|
[SerializeField]
|
|
private BoxCollider _flickCollider;
|
|
|
|
[SerializeField]
|
|
private UILabel _noDeckText;
|
|
|
|
private DeckTable[] _deckTables = new DeckTable[2];
|
|
|
|
private int _deckTableIndex;
|
|
|
|
private Action<Format> OnChangePage;
|
|
|
|
private List<string> _resourcePathList;
|
|
|
|
private int _currentPageIndex;
|
|
|
|
private List<PageData> _pageList;
|
|
|
|
private bool _isInitialized;
|
|
|
|
private bool _canUseNonPossessionCard;
|
|
|
|
public bool IsPageMoving { get; private set; }
|
|
|
|
private void ChangePage(int nextPageIndex, ChangeMoveDirection moveDirection)
|
|
{
|
|
if (!IsPageMoving && IsValidPageIndex(nextPageIndex))
|
|
{
|
|
PageData pageData = _pageList[nextPageIndex];
|
|
_currentPageIndex = nextPageIndex;
|
|
_titleLabel.text = pageData.GroupName;
|
|
ChangeDeckTable(pageData, moveDirection);
|
|
_pageIndicator.UpdateIndicator(_currentPageIndex + 1);
|
|
_leftButton.gameObject.SetActive(0 < nextPageIndex);
|
|
_rightButton.gameObject.SetActive(nextPageIndex < _pageList.Count - 1);
|
|
OnChangePage.Call(pageData.Format);
|
|
}
|
|
}
|
|
|
|
private bool IsValidPageIndex(int pageIndex)
|
|
{
|
|
if (_pageList.Count <= pageIndex)
|
|
{
|
|
return false;
|
|
}
|
|
if (pageIndex < 0)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void ChangeDeckTable(PageData nextPageData, ChangeMoveDirection moveDirection)
|
|
{
|
|
if (IsPageMoving)
|
|
{
|
|
return;
|
|
}
|
|
DeckTable deckTable = _deckTables[_deckTableIndex];
|
|
_deckTableIndex = 1 - _deckTableIndex;
|
|
DeckTable deckTable2 = _deckTables[_deckTableIndex];
|
|
deckTable2.UpdateDeckViewList(nextPageData.DeckViewList, _canUseNonPossessionCard);
|
|
if (moveDirection == ChangeMoveDirection.NONE)
|
|
{
|
|
deckTable2.Obj.transform.localPosition = VIEW_PAGE_POSITION;
|
|
deckTable.Obj.transform.localPosition = OUTSIDE_RIGHT_PAGE_POSITION;
|
|
return;
|
|
}
|
|
bool flag = moveDirection == ChangeMoveDirection.RIGHT;
|
|
deckTable.Obj.transform.localPosition = VIEW_PAGE_POSITION;
|
|
deckTable2.Obj.transform.localPosition = (flag ? OUTSIDE_RIGHT_PAGE_POSITION : OUTSIDE_LEFT_PAGE_POSITION);
|
|
IsPageMoving = true;
|
|
TweenPosition.Begin(deckTable.Obj, 0.2f, flag ? OUTSIDE_LEFT_PAGE_POSITION : OUTSIDE_RIGHT_PAGE_POSITION);
|
|
TweenPosition.Begin(deckTable2.Obj, 0.2f, VIEW_PAGE_POSITION).SetOnFinished(delegate
|
|
{
|
|
IsPageMoving = false;
|
|
});
|
|
|
|
}
|
|
|
|
private void DeleteResource()
|
|
{
|
|
if (_resourcePathList != null)
|
|
{
|
|
Toolbox.ResourcesManager.RemoveAssetGroup(_resourcePathList);
|
|
_resourcePathList.Clear();
|
|
}
|
|
}
|
|
}
|