shaoxiadiablo/Assets/AGame/Scripts/UI/BoxShopPanel/BoxShopPanel.ExchangeWidget.cs
2025-05-18 01:04:31 +08:00

119 lines
3.9 KiB
C#

// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2020-12-07
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "ShopBoxPanel.ExchangeWidget" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace G.UI
{
partial class BoxShopPanel
{
/// <summary>
/// 每日礼包
/// </summary>
public class ExchangeWidget : KUIWidget
{
#region Field
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
GameObject __goProp;
[KUIFlag]
Button _btnGet;
[KUIFlag]
GameObject __goPrice;
[KUIFlag]
GameObject __goFree;
[KUIFlag]
GameObject _goExchanged;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
private PropWidget _propWidget;
private CostWidget _costWidget;
private SmartCostWidget _smartCostWidget;
#endregion
#region Method
public override void Refresh()
{
if (this.data is BoxShopProxy.ExchangeInfo exchangeInfo)
{
_goExchanged.SetActive(exchangeInfo.exchanged);
_propWidget.SetItem(exchangeInfo.prop);
if (exchangeInfo.price.id == Item.Id.kAds)
{
__goFree.SetActive(true);
_smartCostWidget.SetAdTicket(MoneyProxy.Instance.GetMoney(Item.Id.kAdTicket));
__goPrice.SetActive(false);
}
else
{
__goFree.SetActive(false);
__goPrice.SetActive(true);
_costWidget.SetPrice(exchangeInfo.price);
}
}
}
private void OnGetBtnClick()
{
if (this.data is BoxShopProxy.ExchangeInfo exchangeInfo)
{
BoxShopProxy.Instance.Exchange(exchangeInfo.id,
(error, message) =>
{
if (error == 0)
{
Refresh();
}
else if (error == ErrorCode.MONEY_NOT_ENOUGH)
{
int moneyId = exchangeInfo.price.id;
if (moneyId == Item.Id.kGem && KPlatform.Instance.QueryPay())
KUIWindow.OpenWindow<RmbShopWindow>();
else
AdMoneyBox.ShowAdMoney(moneyId, true);
}
else
{
ToastBox.ShowText(message);
}
});
}
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
#endregion
#region Unity
/// <summary>
///
/// </summary>
private void Awake()
{
SetViewData();
_propWidget = __goProp.AddComponent<PropWidget>();
_costWidget = __goPrice.AddComponent<CostWidget>();
_smartCostWidget = __goFree.AddComponent<SmartCostWidget>();
_btnGet.onClick.AddListener(this.OnGetBtnClick);
}
#endregion
}
}
}