Files
tcg-client/Assets/TcgEngine/Scripts/UI/PresetDeck.cs
2025-09-19 14:07:19 +08:00

109 lines
3.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TcgEngine;
using Unity.VisualScripting;
namespace TcgEngine.UI
{
public class PresetDeck : UIPanel
{
[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 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>();
private static PresetDeck instance;
protected override void Awake()
{
base.Awake();
instance = this;
}
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);
}
public void SetupUserDeckList()
{
desk_lines.Clear();
if (dropdownValue == null)
return;
int index = 0;
foreach (DropdownValueItem item in dropdownValue.Items)
{
desk_lines.Add(index,item);
index++;
}
if (desk_lines != null)
{
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;
}
}
}
/// <summary>
/// 打开预设面板
/// </summary>
private void OnPresetLineupPanle()
{
preset_lineup.Show();
hide_panel.Show();
}
/// <summary>
/// 关闭预设面板
/// </summary>
private void OffPresetLineupPanle()
{
preset_lineup.Hide();
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();
}
public static PresetDeck Get()
{
return instance;
}
}
}