285 lines
8.3 KiB
C#
285 lines
8.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TcgEngine;
|
|
using Unity.VisualScripting;
|
|
|
|
namespace TcgEngine.UI
|
|
{
|
|
public class PresetDeck : UIPanel
|
|
{
|
|
public Button start_game_button;
|
|
public TabButton close;
|
|
|
|
[Header("卡组面板")]
|
|
public UIPanel preset_lineup;
|
|
public Button preset_lineup_button;
|
|
public UIPanel hide_panel;
|
|
public GameObject deck_lines_prefab;
|
|
public RectTransform deck_line_content;
|
|
|
|
[Header("展示卡组")]
|
|
public GameObject card_lines_prefab;
|
|
public GridLayoutGroup deck_display_grid;
|
|
|
|
[Header("预设面板")]
|
|
public Button deleteDeckButton;
|
|
public DeckSelector deckSelector;
|
|
|
|
private Button hide_panel_button;
|
|
|
|
// 卡组管理
|
|
public int active_lines_size = 12;
|
|
private List<DeckLine> active_pool = new List<DeckLine>();
|
|
private List<DeckLine> active_lines = new List<DeckLine>();
|
|
|
|
// 卡组展示管理
|
|
public int card_lines_size = 12;
|
|
private List<CardUI> card_pool = new List<CardUI>();
|
|
private List<CardUI> card_lines = new List<CardUI>();
|
|
|
|
private bool _isRankData;
|
|
|
|
private UserData lastUserData;
|
|
private int currIndex = 0;
|
|
|
|
private static PresetDeck instance;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
instance = this;
|
|
for (int i = 0; i < deck_line_content.transform.childCount; i++)
|
|
Destroy(deck_line_content.transform.GetChild(i).gameObject);
|
|
for (int i = 0; i < deck_display_grid.transform.childCount; i++)
|
|
Destroy(deck_display_grid.transform.GetChild(i).gameObject);
|
|
|
|
for (int i = 0; i < active_lines_size; i++)
|
|
{
|
|
GameObject deckLine = Instantiate(deck_lines_prefab, deck_line_content.transform);
|
|
DeckLine line = deckLine.GetComponent<DeckLine>();
|
|
line.gameObject.SetActive(false);
|
|
line.onClick += OnClickLine;
|
|
active_pool.Add(line);
|
|
}
|
|
|
|
for (int i = 0; i < card_lines_size; i++)
|
|
{
|
|
GameObject card = Instantiate(card_lines_prefab, deck_display_grid.transform);
|
|
CardUI line = card.GetComponent<CardUI>();
|
|
line.gameObject.SetActive(false);
|
|
card_pool.Add(line);
|
|
}
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
|
|
preset_lineup_button.onClick.AddListener(OnPresetLineupPanle);
|
|
hide_panel_button = hide_panel.GetComponent<Button>();
|
|
hide_panel_button.onClick.AddListener(OffPresetLineupPanle);
|
|
|
|
deleteDeckButton.onClick.AddListener(OnDeleteDeck);
|
|
start_game_button.onClick.AddListener(OnStartGame);
|
|
|
|
close.onClick += HidePanel;
|
|
}
|
|
|
|
#region 卡组
|
|
|
|
/// <summary>
|
|
/// 设置卡组
|
|
/// </summary>
|
|
private void SetupUserDeckList()
|
|
{
|
|
UserData udata = Authenticator.Get().UserData;
|
|
if (udata == null || udata.decks == null || udata.decks.Length == 0)
|
|
return;
|
|
|
|
foreach (var line in active_pool)
|
|
line.ResetLine();
|
|
|
|
active_lines.Clear();
|
|
|
|
for (int i = 0; i < udata.decks.Length; i++)
|
|
{
|
|
DeckLine line = active_pool[i];
|
|
line.Refresh(udata,udata.decks[i]);
|
|
line.gameObject.SetActive(true);
|
|
active_lines.Add(line);
|
|
}
|
|
|
|
if (active_lines.Count > 0)
|
|
{
|
|
deck_line_content.sizeDelta = new Vector2(0, active_lines.Count * (160 + 25));
|
|
}
|
|
|
|
// 默认选中第一个
|
|
if (currIndex == 0 && active_lines.Count > 0)
|
|
{
|
|
deckSelector.SelectDeck(active_lines[0].GetUserDeck().tid);
|
|
currIndex += 1;
|
|
SetupUserCardList();
|
|
}
|
|
}
|
|
|
|
private void OnClickLine(DeckLine line)
|
|
{
|
|
Debug.Log(line.title.text);
|
|
deckSelector.SelectDeck(line.GetUserDeck().tid);
|
|
// 获取索引
|
|
currIndex = active_lines.IndexOf(line) + 1;
|
|
SetupUserCardList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除卡组
|
|
/// </summary>
|
|
private void OnDeleteDeck()
|
|
{
|
|
if (active_lines.Count > 0)
|
|
{
|
|
CollectionPanel.Get().DeleteDeck(active_lines[GetCurrIndex()].GetUserDeck().tid);
|
|
SetupUserDeckList();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 当前选中卡组索引
|
|
/// </summary>
|
|
private int GetCurrIndex()
|
|
{
|
|
return currIndex - 1;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 展示卡组
|
|
|
|
private void SetupUserCardList()
|
|
{
|
|
foreach (var line in card_pool)
|
|
line.ResetLine();
|
|
|
|
card_lines.Clear();
|
|
|
|
UserDeckData udeck = active_lines[GetCurrIndex()].GetUserDeck();
|
|
int index = 0; // 对象池索引
|
|
foreach (var ucard in udeck.cards)
|
|
{
|
|
for (int q = 0; q < ucard.quantity; q++)
|
|
{
|
|
if (index >= card_pool.Count)
|
|
break;
|
|
|
|
CardUI line = card_pool[index++];
|
|
CardData cdata = CardData.Get(ucard.tid);
|
|
VariantData variant = VariantData.Get(ucard.variant);
|
|
|
|
line.Refresh(cdata, variant);
|
|
line.gameObject.SetActive(true);
|
|
card_lines.Add(line);
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 天梯排行榜使用
|
|
/// </summary>
|
|
public void SetupUserCardList(UserDeckData udeck, string name)
|
|
{
|
|
_isRankData = true;
|
|
Show();
|
|
foreach (var line in card_pool)
|
|
line.ResetLine();
|
|
|
|
card_lines.Clear();
|
|
|
|
int index = 0; // 对象池索引
|
|
foreach (var ucard in udeck.cards)
|
|
{
|
|
for (int q = 0; q < ucard.quantity; q++)
|
|
{
|
|
if (index >= card_pool.Count)
|
|
break;
|
|
|
|
CardUI line = card_pool[index++];
|
|
CardData cdata = CardData.Get(ucard.tid);
|
|
VariantData variant = VariantData.Get(ucard.variant);
|
|
|
|
line.Refresh(cdata, variant);
|
|
line.gameObject.SetActive(true);
|
|
card_lines.Add(line);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
private void OnStartGame()
|
|
{
|
|
MainMenu.Get().OnClickPvP();
|
|
}
|
|
/// <summary>
|
|
/// 打开预设面板
|
|
/// </summary>
|
|
private void OnPresetLineupPanle()
|
|
{
|
|
preset_lineup.Show();
|
|
hide_panel.Show();
|
|
}
|
|
/// <summary>
|
|
/// 关闭预设面板
|
|
/// </summary>
|
|
public void OffPresetLineupPanle()
|
|
{
|
|
preset_lineup.Hide();
|
|
hide_panel.Hide();
|
|
}
|
|
|
|
public override void Show(bool instant = false)
|
|
{
|
|
base.Show(instant);
|
|
|
|
if (!_isRankData)
|
|
{
|
|
SetupUserDeckList();
|
|
preset_lineup_button.gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
preset_lineup_button.gameObject.SetActive(false);
|
|
}
|
|
|
|
if (currIndex != 0)
|
|
{
|
|
SetupUserCardList();
|
|
}
|
|
preset_lineup.Hide();
|
|
hide_panel.Hide();
|
|
}
|
|
|
|
private void HidePanel()
|
|
{
|
|
if (_isRankData)
|
|
{
|
|
LeaderboardPanel.Get().Show();
|
|
_isRankData = false;
|
|
}
|
|
}
|
|
|
|
public override void Hide(bool instant = false)
|
|
{
|
|
base.Hide(instant);
|
|
}
|
|
|
|
public static PresetDeck Get()
|
|
{
|
|
return instance;
|
|
}
|
|
}
|
|
} |