76 lines
2.1 KiB
C#
76 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class PetCell : ListCell
|
|
{
|
|
public Action<int> DelPurchase;
|
|
public Action<int> DelAd;
|
|
public Action<int> DelUse;
|
|
|
|
[SerializeField] Text mTxtName;
|
|
[SerializeField] Image mImgIcon;
|
|
|
|
[SerializeField] Text mTxtPrice;
|
|
[SerializeField] Button mBtnPurchase;
|
|
|
|
[SerializeField] Text mTxtProgress;
|
|
[SerializeField] Button mBtnAd;
|
|
|
|
[SerializeField] Button mBtnUse;
|
|
[SerializeField] GameObject mGobInUse;
|
|
|
|
private DataPet mData;
|
|
|
|
private void Awake()
|
|
{
|
|
UIUtils.BindBtn(mBtnPurchase, OnClickPuchase);
|
|
UIUtils.BindBtn(mBtnAd, OnClickAd);
|
|
UIUtils.BindBtn(mBtnUse, OnClickUse);
|
|
}
|
|
|
|
public void ConfigCell(DataPet pData, bool pOwned, bool pInUse)
|
|
{
|
|
mData = pData;
|
|
|
|
mTxtName.text = LanguageConfig.Instance.GetText(mData.PetName);
|
|
mImgIcon.sprite = ResourceManager.Instance.LoadRes<Sprite>(Const.Path.GetPetIcon(mData.PetName));
|
|
mImgIcon.SetNativeSize();
|
|
|
|
if (GameConfig.Instance.UseDiamond)
|
|
{
|
|
mTxtPrice.text = mData.Price.ToString();
|
|
mTxtPrice.color = PlayerData.Instance.Diamond >= mData.Price ? Color.white : Color.red;
|
|
|
|
mBtnPurchase.gameObject.SetActive(!pOwned);
|
|
mBtnAd.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
int tOnlineCount = TKGSDKManager.Instance.GetConfigInt(TKGParamKey.SkinAdCount);
|
|
mTxtProgress.text = PlayerData.Instance.GetPetProgress(mData.PetID) + "/" + (tOnlineCount > 0 ? tOnlineCount : mData.AdCount);
|
|
|
|
mBtnAd.gameObject.SetActive(!pOwned);
|
|
mBtnPurchase.gameObject.SetActive(false);
|
|
}
|
|
|
|
mBtnUse.gameObject.SetActive(pOwned && !pInUse);
|
|
mGobInUse.SetActive(pOwned && pInUse);
|
|
}
|
|
|
|
private void OnClickPuchase()
|
|
{
|
|
DelPurchase?.Invoke(mData.PetID);
|
|
}
|
|
|
|
private void OnClickAd()
|
|
{
|
|
DelAd?.Invoke(mData.PetID);
|
|
}
|
|
|
|
private void OnClickUse()
|
|
{
|
|
DelUse?.Invoke(mData.PetID);
|
|
}
|
|
} |