Files
SVSimServer/SVSim.BattleEngine/Engine/Wizard/DeckSelectUI.cs

166 lines
4.5 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 }
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; }
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;
private UIPageIndicator _pageIndicator;
[SerializeField]
private UIButton _leftButton;
[SerializeField]
private UIButton _rightButton;
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 _canUseNonPossessionCard;
public bool IsPageMoving { get; private set; }
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;
});
}
}