using UnityEngine; using UnityEngine.UI; using TableConfig; using System; namespace Snxxz.UI { public class XBShopCell : MonoBehaviour { [SerializeField] ItemCell itemCell; [SerializeField] Text nameText; [SerializeField] Image moneyIcon; [SerializeField] Text moneyCntText; [SerializeField] Button buyBtn; [SerializeField] Button shopCellBtn; StoreModel _storeModel; StoreModel m_storeModel { get { return _storeModel ?? (_storeModel = ModelCenter.Instance.GetModel()); } } ItemTipsModel tipsModel { get { return ModelCenter.Instance.GetModel(); } } public void SetModel(StoreConfig storeConfig) { ItemConfig itemConfig = Config.Instance.Get(m_storeModel.ReplaceItemIdByJob(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); 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.GetTextColorByItemColor(TextColType.Red, remainNum.ToString()), "/" + canBuyCnt.ToString()); } } 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(()=> { ItemAttrData attrData = new ItemAttrData(itemConfig.ID, true, 0, storeConfig.IsBind); tipsModel.SetItemTipsModel(attrData); }); buyBtn.RemoveAllListeners(); buyBtn.AddListener(()=> { ClickBuyBtn(storeConfig);}); } private void ClickBuyBtn(StoreConfig storeConfig) { m_storeModel.SendBuyShopItem(storeConfig,1); } } }