|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
public class DanDrugShopCell : MonoBehaviour
|
{
|
[SerializeField] ItemCell itemCell;
|
[SerializeField] Text nameText;
|
[SerializeField] Image moneyIcon;
|
[SerializeField] Text moneyCntText;
|
[SerializeField] Button shopCellBtn;
|
[SerializeField] Image sellOutImg;
|
|
StoreModel _storeModel;
|
StoreModel m_storeModel
|
{
|
get { return _storeModel ?? (_storeModel = ModelCenter.Instance.GetModel<StoreModel>()); }
|
}
|
ItemTipsModel tipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
|
public void SetModel(StoreConfig storeConfig)
|
{
|
ItemConfig itemConfig = ItemConfig.Get(m_storeModel.GetReplaceId(storeConfig.ID,storeConfig.ItemID));
|
if (itemConfig == null) return;
|
|
ItemCellModel cellModel = new ItemCellModel(itemConfig.ID, false, 0, storeConfig.IsBind);
|
itemCell.Init(cellModel);
|
int canBuyCnt = 0;
|
int addBuyCnt = 0;
|
bool isLimitBuy = BuyItemPopModel.Instance.CheckIsLimitBuyCnt(storeConfig, out canBuyCnt, out addBuyCnt);
|
sellOutImg.gameObject.SetActive(false);
|
if (canBuyCnt > 0)
|
{
|
itemCell.countText.gameObject.SetActive(true);
|
BuyShopItemLimit shopItemLimit = m_storeModel.GetBuyShopLimit((uint)storeConfig.ID);
|
int remainNum = canBuyCnt;
|
if (shopItemLimit != null)
|
{
|
remainNum = canBuyCnt - shopItemLimit.BuyCnt;
|
}
|
|
if (remainNum > 0)
|
{
|
itemCell.countText.text = StringUtility.Contact(remainNum.ToString(),
|
"/" + canBuyCnt.ToString());
|
}
|
else
|
{
|
itemCell.countText.text = StringUtility.Contact(UIHelper.AppendStringColor(TextColType.Red, remainNum.ToString()),
|
"/" + canBuyCnt.ToString());
|
sellOutImg.gameObject.SetActive(true);
|
}
|
}
|
else
|
{
|
itemCell.countText.gameObject.SetActive(false);
|
}
|
nameText.text = itemConfig.ItemName;
|
nameText.color = UIHelper.GetUIColor(itemConfig.ItemColor, true);
|
moneyIcon.SetIconWithMoneyType(storeConfig.MoneyType);
|
ulong shopCost = (ulong)(storeConfig.MoneyNumber);
|
moneyCntText.text = UIHelper.ReplaceLargeNum(shopCost);
|
shopCellBtn.RemoveAllListeners();
|
shopCellBtn.AddListener(() =>
|
{
|
BuyItemPopModel.Instance.SetModel(storeConfig.ID);
|
//SetOpenBuyType(chinModel);
|
ItemAttrData attrData = new ItemAttrData(itemConfig.ID, true, (ulong)storeConfig.ItemCnt, -1, storeConfig.IsBind, true, PackType.rptDeleted
|
, "", null, ItemTipChildType.Buy);
|
tipsModel.SetItemTipsModel(attrData);
|
});
|
}
|
|
private void ClickBuyBtn(StoreConfig storeConfig)
|
{
|
m_storeModel.SendBuyShopItem(storeConfig, 1);
|
}
|
}
|
}
|