//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Monday, September 18, 2017 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Snxxz.UI; namespace Snxxz.UI { public class BagStoreWin : StoreUIBasic { #region 成员变量 [SerializeField] private ScrollerController _shopCtrl; private FuncConfigConfig _tagFuncModel; [SerializeField] private Text _goldText; [SerializeField] private Text _goldPaperText; [SerializeField] private Text _sliverText; #endregion StoreModel _storeModel; StoreModel m_storeModel { get { return _storeModel ?? (_storeModel = ModelCenter.Instance.GetModel()); } } int shopId = 0; #region Built-in protected override void BindController() { } protected override void AddListeners() { _shopCtrl.OnRefreshCell += RefreshShopCell; _shopCtrl.lockType = EnhanceLockType.KeepVertical; } protected override void OnPreOpen() { shopId = 0; _tagFuncModel = FuncConfigConfig.Get("CarryShop"); m_storeModel.storeFuncType = StoreFunc.BagStore; InitModel(); OnFrenshMoneyInfo(); m_storeModel.RefreshBuyShopLimitEvent += InitModel; PlayerDatas.Instance.RefreshPlayerInfoEvent += OnFrenshMoneyInfo; } protected override void OnAfterOpen() { CheckJumpToModel(); } protected override void OnPreClose() { m_storeModel.RefreshBuyShopLimitEvent -= InitModel; } protected override void OnAfterClose() { PlayerDatas.Instance.RefreshPlayerInfoEvent -= OnFrenshMoneyInfo; } #endregion private void CheckJumpToModel() { if (AchievementGoto.guideAchievementId != 0) { SuccessConfig successConfig = SuccessConfig.Get(AchievementGoto.guideAchievementId); if (successConfig.Type == 96) { p_shopItemlist = m_storeModel.TryGetStoreDatas((int)m_storeModel.storeFuncType); for (int i = 0; i < p_shopItemlist.Count; i++) { var storeData = p_shopItemlist[i]; if (storeData.storeConfig.ItemID == m_storeModel.jumpToItemId) { shopId = storeData.shopId; int index = i / 2; _shopCtrl.JumpIndex(index); _shopCtrl.m_Scorller.RefreshActiveCellViews(); break; } } AchievementGoto.guideAchievementId = 0; m_storeModel.jumpToItemId = 0; } } } public void InitModel() { CreateShopItemCell(_shopCtrl,2); } protected override void CreateShopItemCell(ScrollerController shopCtrl, int row) { base.CreateShopItemCell(shopCtrl, row); } private void RefreshShopCell(ScrollerDataType type, CellView cell) { int childCode = 0; for (childCode = 0; childCode < cell.transform.childCount; childCode++) { int cellCount = (cell.transform.childCount) * cell.index + (childCode + 1); ShopItemCell shopItemCell = cell.transform.GetChild(childCode).GetComponent(); if (shopItemCell == null) { shopItemCell = cell.transform.GetChild(childCode).gameObject.AddComponent(); } if (p_shopItemlist.Count >= cellCount) { StoreConfig shopInfo = p_shopItemlist[cellCount - 1].storeConfig; cell.transform.GetChild(childCode).gameObject.SetActive(true); if (shopInfo.SalesStatus.Trim() != "") { shopItemCell.stateImage.gameObject.SetActive(true); shopItemCell.stateImage.SetSprite(shopInfo.SalesStatus); shopItemCell.stateImage.SetNativeSize(); } else { shopItemCell.stateImage.gameObject.SetActive(false); } ItemConfig chinModel = ItemConfig.Get(m_storeModel.GetReplaceId(shopInfo.ID,shopInfo.ItemID)); if (chinModel != null) { ItemCellModel cellModel = new ItemCellModel(chinModel.ID, true, 0, shopInfo.IsBind); shopItemCell.itemCell.Init(cellModel); shopItemCell.itemNameText.text = chinModel.ItemName; shopItemCell.itemNameText.color = UIHelper.GetUIColor(chinModel.ItemColor); shopItemCell.coinsIcon.SetIconWithMoneyType(shopInfo.MoneyType); ulong shopCost = (ulong)(shopInfo.MoneyNumber); shopItemCell.coinNumText.text = UIHelper.ReplaceLargeNum(shopCost); BuyItemPopModel buyItem = BuyItemPopModel.Instance; int curVipIndex = -1; int nextVipIndex = -1; bool isVipBuy = buyItem.CheckIsVipBuy(shopInfo, out curVipIndex, out nextVipIndex); int canBuyCnt = 0; int addBuyCnt = 0; bool isLimitBuy = buyItem.CheckIsLimitBuyCnt(shopInfo, out canBuyCnt, out addBuyCnt); bool isShowBuyPrice = true; if (isVipBuy) { if (curVipIndex == -1 && nextVipIndex != -1) { shopItemCell.coinsIcon.gameObject.SetActive(false); shopItemCell.vipText.gameObject.SetActive(true); shopItemCell.vipText.text = Language.Get("StoreWin101", shopInfo.VIPLV[nextVipIndex]); shopItemCell.sellImage.gameObject.SetActive(false); shopItemCell.itemNameText.color = UIHelper.GetUIColor(TextColType.Red,true); shopItemCell.vipText.color = UIHelper.GetUIColor(TextColType.Red,true); isShowBuyPrice = false; } } if (isShowBuyPrice) { shopItemCell.coinsIcon.gameObject.SetActive(true); shopItemCell.vipText.gameObject.SetActive(false); shopItemCell.sellImage.gameObject.SetActive(false); shopItemCell.itemCell.countText.gameObject.SetActive(false); if (canBuyCnt > 0) { shopItemCell.itemCell.countText.gameObject.SetActive(true); BuyShopItemLimit shopItemLimit = m_storeModel.GetBuyShopLimit((uint)shopInfo.ID); int remainNum = canBuyCnt; if (shopItemLimit != null) { remainNum = canBuyCnt - shopItemLimit.BuyCnt; } if (remainNum > 0) { shopItemCell.itemCell.countText.text = StringUtility.Contact(remainNum.ToString(), "/" + canBuyCnt.ToString()); shopItemCell.sellImage.gameObject.SetActive(false); } else { shopItemCell.itemCell.countText.text = StringUtility.Contact(UIHelper.AppendStringColor(TextColType.Red, remainNum.ToString()), "/" + canBuyCnt.ToString()); shopItemCell.sellImage.gameObject.SetActive(true); shopItemCell.stateImage.gameObject.SetActive(false); } } shopItemCell.itemNameText.color = UIHelper.GetUIColor(chinModel.ItemColor, true); shopItemCell.vipText.color = UIHelper.GetUIColor(TextColType.Black,true); } shopItemCell.LoadGuidEffectCtrl(shopInfo.ID,shopId); } shopItemCell.ShopCellBtn.RemoveAllListeners(); shopItemCell.ShopCellBtn.AddListener(() => { if (shopInfo.ID == shopId) { shopId = 0; shopItemCell.LoadGuidEffectCtrl(shopInfo.ID,shopId); } m_storeModel.OnClickShopCell(shopInfo); }); shopItemCell.buyBtn.RemoveAllListeners(); shopItemCell.buyBtn.AddListener(()=> { if(shopInfo.ID == shopId) { shopId = 0; shopItemCell.LoadGuidEffectCtrl(shopInfo.ID,shopId); } m_storeModel.SendBuyShopItem(shopInfo,1); }); } else { cell.transform.GetChild(childCode).gameObject.SetActive(false); } } } public void OnFrenshMoneyInfo() { if (PlayerDatas.Instance.baseData != null) { _goldText.text = PlayerDatas.Instance.baseData.Gold.ToString(); _goldPaperText.text = PlayerDatas.Instance.baseData.GoldPaper.ToString(); _sliverText.text = ItemLogicUtility.Instance.OnChangeCoinsUnit(PlayerDatas.Instance.baseData.allSliver); } else { _goldText.text = "0"; _goldPaperText.text = "0"; _sliverText.text = "0"; } } } }