197 lines
4.2 KiB
C#
Raw Permalink Normal View History

2025-05-18 01:04:31 +08:00
// ***********************************************************************
// Assembly : Game
// Author : Kimch
// Created : 2021-10-26
// Description :
// Last Modified By :
// Last Modified On :
// ***********************************************************************
// <copyright file= "ShopWindow.GiftPanel" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
namespace G.UI
{
using TMPro;
using UnityEngine.UI;
/// <summary>
///
/// </summary>
partial class RmbShopWindow
{
class GiftItemWidget : KUIWidget
{
#region Field
#pragma warning disable CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
[KUIFlag]
TextMeshProUGUI _tmpName;
[KUIFlag]
Button _btnBuy;
[KUIFlag]
KUIList __listProps;
[KUIFlag]
TextMeshProUGUI _tmpPricePointer;
[KUIFlag]
Image _imgMoneyIcon;
[KUIFlag]
TextMeshProUGUI _tmpBuy;
[KUIFlag]
KUIImage _imgPricePointer;
#pragma warning restore CS0649 // 从未对字段赋值,字段将一直保持其默认值 null
#endregion
#region Method
public override void Refresh()
{
if (this.data is RmbShopProxy.GiftBoxInfo giftBoxInfo)
{
_tmpName.text = giftBoxInfo.name;
if (giftBoxInfo.remainTimes > 0)
{
_btnBuy.interactable = true;
if (giftBoxInfo.rmbPrice > 0)
{
_imgMoneyIcon.gameObject.SetActive(true);
_tmpBuy.text = giftBoxInfo.rmbPrice.ToString();
}
else
{
_imgMoneyIcon.gameObject.SetActive(false);
_tmpBuy.text = "免费";
}
}
else
{
_imgMoneyIcon.gameObject.SetActive(false);
_btnBuy.interactable = false;
_tmpBuy.text = "已购买";
}
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<PropWidget>().SetItem(exchangeProps[i]);
}
}
}
private void OnBuyBtnClick()
{
if (this.data is RmbShopProxy.GiftBoxInfo giftBoxInfo)
{
RmbShopProxy.Instance.BuyGiftBox(giftBoxInfo.id,
(error, message) =>
{
if (error == 0)
GetWindow<RmbShopWindow>().RefreshGift();
//Refresh();
else
ToastBox.ShowText(message);
});
}
SoundProxy.PlayFxAsync(GlobalDefine.BUTTON_CLICK_SOUND);
}
#endregion
#region Unity
/// <summary>
///
/// </summary>
private void Awake()
{
SetViewData();
__listProps.AddTemplate<PropWidget>(true);
_btnBuy.onClick.AddListener(this.OnBuyBtnClick);
}
#endregion
}
class GiftPanel : KUIWidget
{
[KUIFlag]
KUIList __listGifts;
GiftItemWidget _specialGift;
public override void Refresh()
{
int giftType = 2;
if ("daily".Equals(this.data))
{
giftType = 2;
}
else
{
giftType = 3;
}
RefreshGift(giftType);
}
void RefreshGift(int giftType)
{
__listGifts.Clear();
var giftBoxInfos = RmbShopProxy.Instance.GetGiftBoxInfos();
if (giftBoxInfos != null)
{
foreach (var item in giftBoxInfos)
{
if (item.type == giftType)
{
if (item.item.extraFlag == 1)
{
_specialGift.SetData(item);
}
else if (item.isValid)
{
__listGifts.GetItem().SetData(item);
}
}
}
foreach (var item in giftBoxInfos)
{
if (item.type == giftType && item.remainTimes <= 0 && item.item.extraFlag != 1)
{
__listGifts.GetItem().SetData(item);
}
}
}
}
private void Awake()
{
SetViewData();
__listGifts.AddTemplate<GiftItemWidget>(true);
_specialGift = __listGifts.transform.Find("specialGift").gameObject.AddComponent<GiftItemWidget>();
}
private void OnEnable()
{
if (this.data == null)
SetData("daily");
}
}
}
}