增加新版出战卡组选定功能和删除功能
This commit is contained in:
@@ -35,12 +35,13 @@ namespace TcgEngine.UI
|
||||
|
||||
deck_dropdown.AddOption("random", "Random");
|
||||
|
||||
//Add standard decks
|
||||
// 添加标准卡组
|
||||
foreach (DeckData deck in GameplayData.Get().free_decks)
|
||||
{
|
||||
deck_dropdown.AddOption(deck.id, deck.title);
|
||||
}
|
||||
|
||||
// 添加自定义卡组
|
||||
UserData udata = Authenticator.Get().UserData;
|
||||
if (udata != null)
|
||||
{
|
||||
@@ -98,6 +99,7 @@ namespace TcgEngine.UI
|
||||
|
||||
public void SelectDeck(string deck)
|
||||
{
|
||||
Debug.Log($"111{deck}");
|
||||
//Make sure deck exists, to prevent assigning invalid deck
|
||||
UserData udata = Authenticator.Get().UserData;
|
||||
UserDeckData udeck = udata?.GetDeck(deck);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@@ -16,17 +17,30 @@ namespace TcgEngine.UI
|
||||
public GameObject deck_lines_prefab;
|
||||
public RectTransform deck_line_content;
|
||||
|
||||
[Header("预设面板")]
|
||||
[Header("展示卡组")]
|
||||
public GameObject card_lines_prefab;
|
||||
public GridLayoutGroup deck_display_grid;
|
||||
|
||||
[Header("预设面板")]
|
||||
public Button deleteDeckButton;
|
||||
public DeckSelector deckSelector;
|
||||
public DropdownValue dropdownValue;
|
||||
|
||||
public int currentSelect;
|
||||
public Button selectDeckButton;
|
||||
|
||||
private Button hide_panel_button;
|
||||
|
||||
// 选择卡组面板
|
||||
private Dictionary<int, DropdownValueItem> desk_lines = new Dictionary<int, DropdownValueItem>();
|
||||
// 卡组管理
|
||||
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<DeckLine> card_pool = new List<DeckLine>();
|
||||
private List<DeckLine> card_lines = new List<DeckLine>();
|
||||
private List<UserCardData> deck_cards = new List<UserCardData>();
|
||||
|
||||
private UserData lastUserData;
|
||||
private int currIndex = 0;
|
||||
|
||||
private static PresetDeck instance;
|
||||
|
||||
@@ -34,44 +48,132 @@ namespace TcgEngine.UI
|
||||
{
|
||||
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);
|
||||
DeckLine line = card.GetComponent<DeckLine>();
|
||||
line.gameObject.SetActive(false);
|
||||
card_pool.Add(line);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
for (int i = 0; i < deck_line_content.transform.childCount; i++)
|
||||
Destroy(deck_line_content.transform.GetChild(i).gameObject);
|
||||
|
||||
preset_lineup_button.onClick.AddListener(OnPresetLineupPanle);
|
||||
hide_panel_button = hide_panel.GetComponent<Button>();
|
||||
hide_panel_button.onClick.AddListener(OffPresetLineupPanle);
|
||||
|
||||
deleteDeckButton.onClick.AddListener(OnDeleteDeck);
|
||||
}
|
||||
|
||||
public void SetupUserDeckList()
|
||||
#region 卡组
|
||||
|
||||
/// <summary>
|
||||
/// 设置卡组
|
||||
/// </summary>
|
||||
private void SetupUserDeckList()
|
||||
{
|
||||
desk_lines.Clear();
|
||||
if (dropdownValue == null)
|
||||
UserData udata = Authenticator.Get().UserData;
|
||||
if (udata == null || udata.decks == null || udata.decks.Length == 0)
|
||||
return;
|
||||
|
||||
int index = 0;
|
||||
foreach (DropdownValueItem item in dropdownValue.Items)
|
||||
foreach (var line in active_pool)
|
||||
line.ResetLine();
|
||||
|
||||
active_lines.Clear();
|
||||
|
||||
for (int i = 0; i < udata.decks.Length; i++)
|
||||
{
|
||||
desk_lines.Add(index,item);
|
||||
index++;
|
||||
DeckLine line = active_pool[i];
|
||||
line.Refresh(udata,udata.decks[i]);
|
||||
line.gameObject.SetActive(true);
|
||||
active_lines.Add(line);
|
||||
}
|
||||
|
||||
if (desk_lines != null)
|
||||
if (active_lines.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < desk_lines.Count; i++)
|
||||
{
|
||||
GameObject deckLine = Instantiate(deck_lines_prefab, deck_line_content.transform);
|
||||
var line = deckLine.GetComponent<DeckLine>();
|
||||
line.title.text = desk_lines[i].text;
|
||||
line.onClick += OnSelectDeck;
|
||||
}
|
||||
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();
|
||||
//
|
||||
// for (int i = 0; i < active_lines[GetCurrIndex()].GetUserDeck().cards.Length; i++)
|
||||
// {
|
||||
// DeckLine line = card_pool[i];
|
||||
// }
|
||||
// }
|
||||
|
||||
// private CardData GetCardData(string id)
|
||||
// {
|
||||
// CardData card = CardData.Get();
|
||||
// return null;
|
||||
// }
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 打开预设面板
|
||||
/// </summary>
|
||||
@@ -89,14 +191,13 @@ namespace TcgEngine.UI
|
||||
hide_panel.Hide();
|
||||
}
|
||||
|
||||
private void OnSelectDeck(DeckLine line)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Show(bool instant = false)
|
||||
{
|
||||
base.Show(instant);
|
||||
|
||||
SetupUserDeckList();
|
||||
|
||||
|
||||
preset_lineup.Hide();
|
||||
hide_panel.Hide();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user