shaoxiadiablo/Assets/AGame/Scripts/UI/RmbShopWindow/RmbShopWindow.Charge.cs

133 lines
2.9 KiB
C#
Raw 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.ChargePanel" company="Kunpo"></copyright>
// <summary></summary>
// ***********************************************************************
namespace G.UI
{
using TMPro;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
///
/// </summary>
partial class RmbShopWindow
{
class ChargeItemWidget : KUIWidget
{
[KUIFlag]
KUIImage _imgIcon;
[KUIFlag]
TextMeshProUGUI _tmpName;
[KUIFlag]
Button _btnBuy;
[KUIFlag]
TextMeshProUGUI _tmpBuy;
[KUIFlag]
Image _imgMoneyIcon;
[KUIFlag]
TextMeshProUGUI _tmpFlag;
public override void Refresh()
{
if (this.data is RmbShopProxy.ChargeInfo chargeInfo)
{
_tmpName.text = chargeInfo.item.name;
_imgIcon.SetDefaultSprite(chargeInfo.id - 1);
if (chargeInfo.id >2)
{
_imgIcon.transform.GetComponent<RectTransform>().sizeDelta = new Vector2(180, 180);
}
if (chargeInfo.rmbPrice > 0)
{
//if (chargeInfo.chargeCount > 0)
//{
// _tmpFlag.text = "";
//}
//else
//{
// _tmpFlag.text = "(首充翻倍)";
//}
_tmpFlag.text = "(首充翻倍)";
_imgMoneyIcon.gameObject.SetActive(true);
_tmpBuy.text = chargeInfo.rmbPrice.ToString();
}
else
{
_imgMoneyIcon.gameObject.SetActive(false);
_tmpFlag.text = "";
if (chargeInfo.remainTimes > 0)
{
_tmpBuy.text = "免费";
}
else
{
_tmpBuy.text = "今日已领";
}
}
}
}
void Awake()
{
SetViewData();
_btnBuy.onClick.AddListener(this.OnBuyBtnClick);
}
void OnBuyBtnClick()
{
if (this.data is RmbShopProxy.ChargeInfo chargeInfo)
{
if (chargeInfo.remainTimes > 0)
RmbShopProxy.Instance.Recharge(chargeInfo.id, (error, message) =>
{
if (error == ErrorCode.SUCCESS)
{
Refresh();
PostNotification(GlobalDefine.EVENT_MONEY_CHANGED, chargeInfo.exchange.id, "charge");
}
});
}
}
}
class ChargePanel : KUIWidget
{
[KUIFlag]
KUIList __goCharges;
public override void Refresh()
{
__goCharges.Clear();
var chargeInfos = RmbShopProxy.Instance.GetChargeInfos();
if (chargeInfos != null)
{
foreach (var item in chargeInfos)
{
if (item.item.type == 1)
__goCharges.GetItem().SetData(item);
}
}
}
private void Awake()
{
SetViewData();
__goCharges.AddTemplate<ChargeItemWidget>(true);
}
private void OnEnable()
{
this.Refresh();
}
}
}
}