//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Monday, September 18, 2017 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TableConfig; using Snxxz.UI; namespace Snxxz.UI { public class StoreWin : Window { #region 成员变量 [SerializeField] private FunctionButton _weekStoreTitle; [SerializeField] private FunctionButton _commonStoreTitle; [SerializeField] private FunctionButton _growStrongerStoreTitle; [SerializeField] private FunctionButton _bindStoreTitle; [SerializeField] private FunctionButton _integralStoreTitle; [SerializeField] private FunctionButtonGroup _funcBtnGroup; [SerializeField] private Button _leftBtn; [SerializeField] private Button _rightBtn; [SerializeField] private Button _closeBtn; [SerializeField] private ScrollerController _shopCtrl; [SerializeField] private GameObject _followStoreBottom; [SerializeField] private Text _coinsType1; [SerializeField] private Text _coinsType2; [SerializeField] private Text _resetRefreshTimeText; [SerializeField] private GameObject _integralBottom; [SerializeField] private Text _coinsType3; #endregion PackModelInterface _modelInterface; PackModelInterface modelInterface { get { return _modelInterface ?? (_modelInterface = ModelCenter.Instance.GetModel()); } } StoreModel _storeModel; StoreModel m_storeModel { get { return _storeModel ?? (_storeModel = ModelCenter.Instance.GetModel()); } } private List _tagStoreModellist; private FuncConfigConfig _tagFuncModel1; private FuncConfigConfig _tagFuncModel2; private int shopId = 0; #region Built-in protected override void BindController() { } protected override void AddListeners() { _shopCtrl.OnRefreshCell += RefreshShopCell; _shopCtrl.lockType = EnhanceLockType.KeepVertical; _weekStoreTitle.onClick.AddListener(()=> { OnClickWeekStore(); }); _commonStoreTitle.onClick.AddListener(()=> { OnClickCommonStore();}); _growStrongerStoreTitle.onClick.AddListener(()=>{ OnClickStrengthStore();}); _bindStoreTitle.onClick.AddListener(()=> { OnClickBindStore(); }); _integralStoreTitle.onClick.AddListener(()=> { OnClickIntegralStore(); }); _leftBtn.onClick.AddListener(OnClickLeftBtn); _rightBtn.onClick.AddListener(OnClickRightBtn); _closeBtn.onClick.AddListener(OnClickClose); } protected override void OnPreOpen() { shopId = 0; m_storeModel.RefreshTCBPlayerDataEvent += OnRefreshPlayerInfo; m_storeModel.RefreshBuyShopLimitEvent += OnCreate; RefreshCoins(); RefreshResetTime(); } protected override void OnActived() { base.OnActived(); if(!WindowJumpMgr.Instance.IsJumpState && functionOrder == 0) { if(m_storeModel.storeFunc1Point.state == RedPointState.Simple) { functionOrder = _weekStoreTitle.order; } else if(m_storeModel.storeFunc2Point.state == RedPointState.Simple) { functionOrder = _commonStoreTitle.order; } else if (m_storeModel.storeFunc3Point.state == RedPointState.Simple) { functionOrder = _growStrongerStoreTitle.order; } else if (m_storeModel.storeFunc4Point.state == RedPointState.Simple) { functionOrder = _bindStoreTitle.order; } else if (m_storeModel.storeFunc5Point.state == RedPointState.Simple) { functionOrder = _integralStoreTitle.order; } } _funcBtnGroup.TriggerByOrder(functionOrder); GlobalTimeEvent.Instance.secondEvent += RefreshResetTime; } protected override void OnAfterOpen() { CheckJumpToModel(); } protected override void OnPreClose() { m_storeModel.shoplist.Clear(); m_storeModel.RefreshBuyShopLimitEvent -= OnCreate; GlobalTimeEvent.Instance.secondEvent -= RefreshResetTime; m_storeModel.RefreshTCBPlayerDataEvent -= OnRefreshPlayerInfo; } protected override void OnAfterClose() { if (!WindowJumpMgr.Instance.IsJumpState) { WindowCenter.Instance.Open(); } } #endregion private void CheckJumpToModel() { if (AchievementGoto.guideAchievementId != 0) { SuccessConfig successConfig = Config.Instance.Get(AchievementGoto.guideAchievementId); if(successConfig.Type == 97) { _tagStoreModellist = StoreConfig.GetTypeStoreModel((int)m_storeModel.storeFuncType); List orderlist = new List(); orderlist.AddRange(_tagStoreModellist); orderlist.Sort(CompareByMoney); for (int i = 0; i < _tagStoreModellist.Count; i++) { if (_tagStoreModellist[i].ID == orderlist[0].ID) { shopId = _tagStoreModellist[i].ID; int index = i / 2; _shopCtrl.JumpIndex(index); _shopCtrl.m_Scorller.RefreshActiveCellViews(); break; } } AchievementGoto.guideAchievementId = 0; } } } private void RefreshResetTime() { if(_tagStoreModellist == null || _tagStoreModellist.Count < 1) { _tagStoreModellist = StoreConfig.GetTypeStoreModel((int)m_storeModel.storeFuncType); } if(_tagStoreModellist.Count > 0) { if (_tagStoreModellist[0].RefreshType == 0) { _resetRefreshTimeText.gameObject.SetActive(false); } else { _resetRefreshTimeText.gameObject.SetActive(true); _resetRefreshTimeText.text = m_storeModel.GetStoreRefreshTimeByType(_tagStoreModellist[0].RefreshType); } } } public int CompareByMoney(StoreConfig start,StoreConfig end) { int money1 = start.MoneyNumber; int money2 = end.MoneyNumber; if (money1.CompareTo(money2) != 0) return money1.CompareTo(money2); int index1 = _tagStoreModellist.IndexOf(start); int index2 = _tagStoreModellist.IndexOf(end); if (index1.CompareTo(index2) != 0) return index1.CompareTo(index2); return 0; } private void RefreshUI() { if (_tagStoreModellist.Count < 1) return; if(m_storeModel.showCoinsUIDict != null && m_storeModel.showCoinsUIDict.ContainsKey(_tagStoreModellist[0].ShopType)) { if(m_storeModel.showCoinsUIDict[_tagStoreModellist[0].ShopType] == 1) { _followStoreBottom.gameObject.SetActive(true); _integralBottom.gameObject.SetActive(false); } else if(m_storeModel.showCoinsUIDict[_tagStoreModellist[0].ShopType] == 2) { _followStoreBottom.gameObject.SetActive(false); _integralBottom.gameObject.SetActive(true); } } } public void RefreshCoins() { _coinsType1.text = UIHelper.GetMoneyCnt(1).ToString(); _coinsType2.text = UIHelper.GetMoneyCnt(2).ToString(); _coinsType3.text = modelInterface.OnChangeCoinsUnit(UIHelper.GetMoneyCnt(16)); } private void OnCreate() { shopId = 0; _tagStoreModellist = StoreConfig.GetTypeStoreModel((int)m_storeModel.storeFuncType); _shopCtrl.Refresh(); if (_tagStoreModellist.Count > 0) { int i = 0; int remain = _tagStoreModellist.Count % 2; int line = (int)_tagStoreModellist.Count / 2; if (remain > 0) { line += 1; } for (i = 0; i < line; i++) { _shopCtrl.AddCell(ScrollerDataType.Header, i); } } _shopCtrl.Restart(); _shopCtrl.JumpIndex(0); RefreshUI(); } private void OnRefreshPlayerInfo(PlayerDataRefresh refreshType) { if (refreshType == PlayerDataRefresh.VIPLv) OnCreate(); else if (refreshType == PlayerDataRefresh.Gold) RefreshCoins(); else if (refreshType == PlayerDataRefresh.GoldPaper) RefreshCoins(); else if(refreshType == PlayerDataRefresh.FBHelpPoint) RefreshCoins(); } 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 (_tagStoreModellist.Count >= cellCount) { StoreConfig shopInfo = _tagStoreModellist[cellCount - 1]; if(m_storeModel.shopRedDict.ContainsKey(shopInfo.ID)) { shopItemCell.redpoint.redpointId = m_storeModel.shopRedDict[shopInfo.ID].id; } cell.transform.GetChild(childCode).gameObject.SetActive(true); if (shopInfo.SalesStatus.Trim() != "") { shopItemCell.stateImage.gameObject.SetActive(true); shopItemCell.stateImage.SetSprite(shopInfo.SalesStatus); } else { shopItemCell.stateImage.gameObject.SetActive(false); } ItemConfig chinModel = Config.Instance.Get(m_storeModel.ReplaceItemIdByJob(shopInfo.ID,shopInfo.ItemID)); if(chinModel != null) { ItemCellModel cellModel = new ItemCellModel(chinModel.ID,true,0,shopInfo.IsBind,"",PackType.rptDeleted,true); shopItemCell.itemCell.Init(cellModel); shopItemCell.itemNameText.text = chinModel.ItemName; 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.GetTextColorByItemColor(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.ClearMustBuyRedpoint(shopInfo); m_storeModel.OnClickShopCell(shopInfo); }); } else { cell.transform.GetChild(childCode).gameObject.SetActive(false); } } } #region 点击事件 private void OnClickIntegralStore() { m_storeModel.shoplist.Clear(); m_storeModel.storeFuncType = StoreFunc.IntegralStore; OnCreate(); RefreshResetTime(); functionOrder = _integralStoreTitle.order; } private void OnClickBindStore() { m_storeModel.shoplist.Clear(); m_storeModel.storeFuncType = StoreFunc.BindStore; OnCreate(); RefreshResetTime(); functionOrder = _bindStoreTitle.order; } private void OnClickStrengthStore() { m_storeModel.shoplist.Clear(); m_storeModel.storeFuncType = StoreFunc.GrowStrongerStore; OnCreate(); RefreshResetTime(); functionOrder = _growStrongerStoreTitle.order; } private void OnClickCommonStore() { m_storeModel.shoplist.Clear(); m_storeModel.storeFuncType = StoreFunc.CommonStore; OnCreate(); RefreshResetTime(); functionOrder = _commonStoreTitle.order; } private void OnClickWeekStore() { m_storeModel.storeFuncType = StoreFunc.WeekStore; OnCreate(); RefreshResetTime(); functionOrder = _weekStoreTitle.order; } private void OnClickRightBtn() { _funcBtnGroup.TriggerNext(); } private void OnClickLeftBtn() { _funcBtnGroup.TriggerLast(); } private void OnClickClose() { CloseImmediately(); } #endregion } }