完善抽卡界面以及根据优化意见和功能缺失做出调整
This commit is contained in:
90
Assets/TcgEngine/Scripts/Menu/PackBuyPanel.cs
Normal file
90
Assets/TcgEngine/Scripts/Menu/PackBuyPanel.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user