完善抽卡界面以及根据优化意见和功能缺失做出调整

This commit is contained in:
YiHan0621
2025-10-13 01:41:20 +08:00
parent 2e4a318ca3
commit f14b8d6ac6
14 changed files with 702 additions and 304 deletions

View File

@@ -102,7 +102,7 @@ namespace TcgEngine.UI
{
base.Start();
//Set power abilities hover text
// 设置点击能力悬停文本
foreach (IconButton btn in hero_powers)
{
CardData icard = CardData.Get(btn.GetValue());
@@ -117,10 +117,6 @@ namespace TcgEngine.UI
hover.text += " <size=16>Mana: " + iability.mana_cost + "</size>";
}
}
if (!spawned)
{
SpawnCards();
}
}
protected override void Update()
@@ -149,7 +145,7 @@ namespace TcgEngine.UI
}
}
}
private void SpawnCards()
{
spawned = true;
@@ -200,7 +196,7 @@ namespace TcgEngine.UI
//----- Refresh UI --------
private void RefreshAll()
public void RefreshAll()
{
RefreshFilters();
RefreshCards();

View File

@@ -1,7 +1,10 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using TcgEngine.UI;
using UnityEngine;
using Random = UnityEngine.Random;
namespace TcgEngine.Client
{
@@ -12,7 +15,10 @@ namespace TcgEngine.Client
public class OpenPackMenu : MonoBehaviour
{
public GameObject card_prefab;
public PackBuyPanel packBuyPanel;
private bool revealing = false;
private static OpenPackMenu instance;
@@ -20,6 +26,7 @@ namespace TcgEngine.Client
void Awake()
{
instance = this;
packBuyPanel.SetPack(PlayerPrefs.GetString("pack_id"));
}
void Update()

View File

@@ -0,0 +1,90 @@
using System.Collections;
using System.Collections.Generic;
using TcgEngine.Client;
using UnityEngine;
using UnityEngine.UI;
namespace TcgEngine.UI
{
/// <summary>
/// 简化卡包购买面板只提供“买1包”和“买2包”按钮保留API购买逻辑
/// </summary>
public class PackBuyPanel : UIPanel
{
public Button buy_five_btn; // 购买1张按钮
public Button buy_ten_btn; // 购买2张按钮
[Header("准备购买数据!")]
public PackData pack; // 当前购买的卡包数据
protected override void Awake()
{
base.Awake();
this.Show();
buy_five_btn.onClick.AddListener(() => OnClickBuy(1));
buy_ten_btn.onClick.AddListener(() => OnClickBuy(2));
}
private void OnDestroy()
{
buy_five_btn.onClick.RemoveAllListeners();
buy_ten_btn.onClick.RemoveAllListeners();
}
/// <summary>
/// id传输
/// </summary>
/// <param name="pack">卡牌id</param>
public void SetPack(string packId)
{
pack = PackData.Get(packId);
}
public void SetPack(PackData pack)
{
this.pack = pack;
Show();
}
private async void BuyPackApi(int quantity)
{
if (pack == null || quantity <= 0) return;
BuyPackRequest req = new BuyPackRequest
{
pack = pack.id,
quantity = quantity
};
string url = ApiClient.ServerURL + "/users/packs/buy/";
string jdata = ApiTool.ToJson(req);
WebResponse res = await ApiClient.Get().SendPostRequest(url, jdata);
if (res.success)
{
if (PackPanel.Get() != null)
{
PackPanel.Get()?.ReloadUserPack();
PackPanel.Get()?.RefreshCurrency();
}
if (HandPackArea.Get() != null)
{
HandPackArea.Get().LoadPacks();
}
}
else
{
Debug.LogError(res.error);
}
}
private void OnClickBuy(int quantity)
{
BuyPackApi(quantity);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ff8ebde9cba8f9548a236d8789ee537e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -19,9 +19,12 @@ namespace TcgEngine.UI
[Header("货币")]
public Text coin;
public Text crystal;
[Header("当前选择准备卡组")]
public Toggle standard_toggle;
public Toggle elite_toggle;
public PackData preparePack;
public PackBuyPanel packBuyPanel;
private List<GameObject> pack_list = new List<GameObject>();
@@ -40,6 +43,15 @@ namespace TcgEngine.UI
protected override void Start()
{
base.Start();
if (standard_toggle != null)
standard_toggle.onValueChanged.AddListener(OnToggleStandard);
if (elite_toggle != null)
elite_toggle.onValueChanged.AddListener(OnToggleElite);
// 默认设置卡组
OnToggleStandard(standard_toggle.isOn);
}
protected override void Update()
@@ -80,10 +92,6 @@ namespace TcgEngine.UI
pack_ui.onClick += OnClickPack;
pack_ui.onClickRight += OnClickPack;
pack_list.Add(nPack);
if (pack.title == "白银卡包")
{
SetPackData(pack);
}
}
}
@@ -100,16 +108,6 @@ namespace TcgEngine.UI
}
}
private void OnClickPack()
{
if (preparePack != null)
{
PackZoomPanel.Get().OnClickBuy(preparePack);
}
}
/// <summary>
/// 刷新货币
/// </summary>
@@ -118,20 +116,6 @@ namespace TcgEngine.UI
coin.text = MainMenu.Get().credits_txt.text;
crystal.text = MainMenu.Get().crystalText.text;
}
/// <summary>
/// 设置即将打开卡包的数据
/// </summary>
private string SetPackData(PackData pack)
{
PlayerPrefs.SetString("SetPack",pack.id);
if (PlayerPrefs.GetString("SetPack") != null)
{
string setPack = PlayerPrefs.GetString("SetPack");
Debug.Log($"已设置{setPack},准备就绪");
}
return PlayerPrefs.GetString("SetPack");
}
public void OnClickPack(PackUI pack)
{
@@ -147,6 +131,35 @@ namespace TcgEngine.UI
{
MainMenu.Get().FadeToScene("OpenPack");
}
private void OnToggleStandard(bool value)
{
if (value)
{
// 设置当前卡组为标准卡组
preparePack = PackData.Get("standard");
SetBuyPack("standard");
Debug.Log("当前选择标准卡组");
}
}
private void OnToggleElite(bool value)
{
if (value)
{
// 设置当前卡组为精英卡组
preparePack = PackData.Get("elite");
SetBuyPack("elite");
Debug.Log("当前选择精英卡组");
}
}
private void SetBuyPack(string packId)
{
packBuyPanel.SetPack(packId);
PlayerPrefs.SetString("pack_id", packId);
}
public override void Show(bool instant = false)
{

View File

@@ -120,19 +120,6 @@ namespace TcgEngine.UI
}
}
public void OnClickBuy(PackData setPack)
{
pack = setPack;
if (Authenticator.Get().IsTest())
{
BuyPackTest();
}
if (Authenticator.Get().IsApi())
{
BuyPackApi();
}
}
private void OnClickTab(TabButton btn)
{
if (btn.group == "menu")