using UnityEngine;
|
using vnxbqy.UI;
|
|
public class CelestialPalaceShopCell : MonoBehaviour
|
{
|
[SerializeField] ItemCell itemCell;
|
[SerializeField] ImageEx imgLock;
|
[SerializeField] ImageEx imgItemMoneyIcon;
|
[SerializeField] ImageEx imgSell;
|
[SerializeField] ImageEx imgChoose;
|
[SerializeField] TextEx txtItemName;
|
[SerializeField] TextEx txtItemPrice;
|
[SerializeField] TextEx txtPurchaseLimitCount;
|
[SerializeField] TextEx txtLockTip;
|
[SerializeField] ButtonEx btnBuy;
|
[SerializeField] ButtonEx btnChoose;
|
StoreModel storeModel { get { return ModelCenter.Instance.GetModel<StoreModel>(); } }
|
CelestialPalaceModel model { get { return ModelCenter.Instance.GetModel<CelestialPalaceModel>(); } }
|
public void SetDisplay(StoreConfig storeConfig)
|
{
|
ItemConfig itemConfig = ItemConfig.Get(storeModel.GetReplaceId(storeConfig.ID, storeConfig.ItemID));
|
if (itemConfig == null) return;
|
|
ItemCellModel cellModel = new ItemCellModel(itemConfig.ID, false, (ulong)storeConfig.ItemCnt);
|
itemCell.button.enabled = false;
|
itemCell.Init(cellModel);
|
txtItemName.text = itemConfig.ItemName;
|
txtItemName.color = UIHelper.GetUIColor(itemConfig.ItemColor, true);
|
imgItemMoneyIcon.SetIconWithMoneyType(storeConfig.MoneyType);
|
txtItemPrice.text = UIHelper.ReplaceLargeNum((ulong)(storeConfig.MoneyNumber));
|
|
|
bool isLimitBuy = BuyItemController.Instance.CheckIsLimitBuyCnt(storeConfig, out var canBuyCnt, out var addBuyCnt);
|
BuyShopItemLimit shopItemLimit = storeModel.GetBuyShopLimit((uint)storeConfig.ID);
|
int remainNum = canBuyCnt;
|
int buyCnt = 0;
|
if (shopItemLimit != null)
|
{
|
buyCnt = shopItemLimit.BuyCnt;
|
remainNum = canBuyCnt - buyCnt;
|
}
|
uint allCostCount = model.GetAllCostCount();
|
bool isCanBuy = allCostCount >= storeConfig.LimitValue;
|
btnBuy.SetActive(isCanBuy && remainNum > 0);
|
imgLock.SetActive(!isCanBuy);
|
txtLockTip.SetActive(!isCanBuy);
|
txtLockTip.text = Language.Get("CelestialPalace04", storeConfig.LimitValue);
|
|
if (isLimitBuy)
|
{
|
txtPurchaseLimitCount.SetActive(isCanBuy);
|
txtPurchaseLimitCount.text = Language.Get("CelestialPalace05", buyCnt, canBuyCnt);
|
imgSell.SetActive(remainNum == 0);
|
}
|
else
|
{
|
txtPurchaseLimitCount.SetActive(false);
|
imgSell.SetActive(false);
|
}
|
bool isChoose = storeConfig.ID == model.currentSelectedShopGoodId;
|
imgChoose.SetActive(isChoose);
|
|
btnBuy.SetListener(() =>
|
{
|
if (!isCanBuy)
|
return;
|
storeModel.OnClickShopCell(storeConfig);
|
});
|
|
btnChoose.SetListener(() =>
|
{
|
model.currentSelectedShopGoodId = storeConfig.ID;
|
});
|
}
|
}
|