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

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

@@ -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);
}
}
}