// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2020-12-07
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
//
//
// ***********************************************************************
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace G.UI
{
partial class BoxShopPanel
{
///
/// 每日礼包
///
public class GiftBoxWidget : KUIWidget
{
#region Field
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
TextMeshProUGUI _tmpName;
[KUIFlag]
Button __btnBuy;
[KUIFlag]
KUIList __listProps;
[KUIFlag]
TextMeshProUGUI _tmpPricePointer;
[KUIFlag]
KUIImage _imgPricePointer;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
private CostWidget _costWidget;
#endregion
#region Method
public override void Refresh()
{
if (this.data is RmbShopProxy.GiftBoxInfo giftBoxInfo)
{
_tmpName.text = giftBoxInfo.name;
_costWidget.SetText(giftBoxInfo.rmbPrice.ToString());
__btnBuy.interactable = giftBoxInfo.remainTimes > 0;
if (!string.IsNullOrEmpty(giftBoxInfo.item.discount))
{
_imgPricePointer.gameObject.SetActive(true);
_imgPricePointer.ShowSprite(giftBoxInfo.item.discount);
}
else
{
_imgPricePointer.gameObject.SetActive(false);
}
__listProps.Clear();
var exchangeProps = giftBoxInfo.exchanges;
if (exchangeProps != null)
for (int i = 0; i < exchangeProps.Length; i++)
{
__listProps.GetItem().SetItem(exchangeProps[i]);
}
}
}
private void OnBuyBtnClick()
{
if (this.data is RmbShopProxy.GiftBoxInfo giftBoxInfo)
{
RmbShopProxy.Instance.BuyGiftBox(giftBoxInfo.id,
(error, message) =>
{
if (error == ErrorCode.SUCCESS)
{
PostNotification(GlobalDefine.EVENT_SHOP_GIFT_BOX_CHANGED);
}
});
}
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
#endregion
#region Unity
///
///
///
private void Awake()
{
SetViewData();
__listProps.AddTemplate(true);
_costWidget = __btnBuy.gameObject.AddComponent();
__btnBuy.onClick.AddListener(this.OnBuyBtnClick);
}
#endregion
}
}
}