//-------------------------------------------------------- // [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 StoreWin : Window { [SerializeField] FunctionButton m_DayStoreTitle; [SerializeField] FunctionButton m_WeekStoreTitle; [SerializeField] FunctionButton m_CommonStoreTitle; [SerializeField] FunctionButton m_GrowStrongerStoreTitle; //[SerializeField] FunctionButton m_BindStoreTitle; [SerializeField] FunctionButton m_IntegralStoreTitle; [SerializeField] FunctionButtonGroup m_FuncBtnGroup; [SerializeField] Button m_LeftBtn; [SerializeField] Button m_RightBtn; [SerializeField] Button m_CloseBtn; [SerializeField] ScrollerController m_ShopCtrl; [SerializeField] ScrollerController m_ShopSecondCtrl; [SerializeField] GameObject m_FollowStoreBottom; [SerializeField] Text m_CoinsType1; [SerializeField] Text m_CoinsType2; [SerializeField] Text m_CoinsType3; [SerializeField] RectTransform m_RefreshContainer; [SerializeField] Button m_RefreshCommodities; [SerializeField] Text m_RefreshTimeText; [SerializeField] GameObject m_IntegralBottom; [SerializeField] Button m_AssistBtn; StoreModel model { get { return ModelCenter.Instance.GetModel(); } } PackModel packModel { get { return ModelCenter.Instance.GetModel(); } } private List commodities; private int shopId = 0; #region Built-in protected override void BindController() { } protected override void AddListeners() { m_ShopCtrl.OnRefreshCell += RefreshShopCell; m_ShopSecondCtrl.OnRefreshCell += RefreshShopSecondCell; m_ShopCtrl.lockType = EnhanceLockType.KeepVertical; m_ShopSecondCtrl.lockType = EnhanceLockType.KeepVertical; m_DayStoreTitle.SetListener(OpenDayStore); m_WeekStoreTitle.SetListener(OpenMysteryStore); m_CommonStoreTitle.SetListener(OpenCommonStore); m_GrowStrongerStoreTitle.SetListener(OpenStrengthStore); //m_BindStoreTitle.SetListener(OpenBindGoldStore); m_IntegralStoreTitle.SetListener(OpenIntegralStore); m_AssistBtn.SetListener(ViewAssistRecorders); m_RefreshCommodities.SetListener(RefreshCommondities); m_LeftBtn.SetListener(() => { m_FuncBtnGroup.TriggerLast(); }); m_RightBtn.SetListener(() => { m_FuncBtnGroup.TriggerNext(); }); m_CloseBtn.SetListener(() => { CloseImmediately(); }); } protected override void OnPreOpen() { //必须先购买限时幼龙 var storeConfig = StoreConfig.Get(1); int count = 0; if (!model.TryGetIsSellOut(storeConfig, out count)) { functionOrder = m_IntegralStoreTitle.order; model.selectSecondType = storeConfig.SecondType[0]; model.jumpToItemId = storeConfig.ItemID; } shopId = 0; PlayerDatas.Instance.playerDataRefreshEvent += OnRefreshPlayerInfo; model.RefreshBuyShopLimitEvent += OnCreate; model.mysteryShopRefreshEvent += OnCreate; model.selectClassifyRefresh += OnSecondTypeRefresh; GlobalTimeEvent.Instance.secondEvent += UpdateRefreshTime; RefreshCoins(); UpdateRefreshTime(); model.SetPushPetAndMountWinState(true, true); } protected override void OnActived() { base.OnActived(); if (!WindowJumpMgr.Instance.IsJumpState && functionOrder == 0) { if (model.storeFunc1Point.state == RedPointState.Simple) { functionOrder = m_DayStoreTitle.order; } else if (model.storeFunc2Point.state == RedPointState.Simple) { functionOrder = m_WeekStoreTitle.order; } else if (model.storeFunc3Point.state == RedPointState.Simple) { functionOrder = m_CommonStoreTitle.order; } else if (model.storeFunc4Point.state == RedPointState.Simple) { functionOrder = m_GrowStrongerStoreTitle.order; } else if (model.storeFunc5Point.state == RedPointState.Simple) { functionOrder = m_IntegralStoreTitle.order; } } if (!WindowJumpMgr.Instance.IsJumpState && model.funcOrder != -1) { functionOrder = model.funcOrder; } m_FuncBtnGroup.TriggerByOrder(functionOrder); } protected override void OnAfterOpen() { CheckJumpToModel(); } protected override void OnPreClose() { model.CloseAllRedpoint(StoreFunc.DayStore); model.storeFuncType = StoreFunc.DayStore; model.RefreshBuyShopLimitEvent -= OnCreate; model.mysteryShopRefreshEvent -= OnCreate; model.selectClassifyRefresh -= OnSecondTypeRefresh; GlobalTimeEvent.Instance.secondEvent -= UpdateRefreshTime; PlayerDatas.Instance.playerDataRefreshEvent -= OnRefreshPlayerInfo; } protected override void OnAfterClose() { if (!WindowJumpMgr.Instance.IsJumpState) { WindowCenter.Instance.Open(); } } #endregion private void CheckJumpToModel() { if (model.jumpToItemId != 0) { var p_shopItemlist = model.TryGetStoreDatasBySecondType((int)model.storeFuncType, model.selectSecondType); if (p_shopItemlist == null) { model.ClearJump(); return; } for (int i = 0; i < p_shopItemlist.Count; i++) { var storeData = p_shopItemlist[i]; if (storeData.storeConfig.ItemID == model.jumpToItemId) { shopId = storeData.shopId; int index = i / 2; m_ShopCtrl.JumpIndex(index); m_ShopCtrl.m_Scorller.RefreshActiveCellViews(); break; } } model.ClearJump(); } } private void UpdateRefreshTime() { if (model.storeFuncType == StoreFunc.MysteryStore) { m_RefreshCommodities.SetActive(true); m_RefreshTimeText.text = model.GetMysteryStoreRefreshTime(); } else { if (commodities == null || commodities.Count < 1) { commodities = model.TryGetStoreDatasBySecondType((int)model.storeFuncType, model.selectSecondType); } if (commodities == null || commodities.Count == 0) { return; } var refreshType = commodities[0].storeConfig.RefreshType; if (model.storeFuncType == StoreFunc.IntegralStore) refreshType = 0; if (refreshType == 0) { } else { m_RefreshCommodities.SetActive(false); m_RefreshTimeText.text = model.GetStoreRefreshTimeByType(refreshType); } } } int CompareByMoney(StoreModel.StoreData start, StoreModel.StoreData end) { int money1 = start.storeConfig.MoneyNumber; int money2 = end.storeConfig.MoneyNumber; if (money1 != money2) { return money1.CompareTo(money2); } int index1 = commodities.IndexOf(start); int index2 = commodities.IndexOf(end); if (index1 != index2) { return index1.CompareTo(index2); } return 0; } private void RefreshUI() { if (commodities.Count < 1) { return; } var shopType = commodities[0].storeConfig.ShopType; var RefreshType = commodities[0].storeConfig.RefreshType; if (model.storeFuncType == StoreFunc.IntegralStore) RefreshType = 0; this.m_RefreshContainer.SetActive(RefreshType != 0); //if (model.showCoinsUIDict != null && model.showCoinsUIDict.ContainsKey(shopType)) //{ // if (model.showCoinsUIDict[shopType] == 1) // { // m_FollowStoreBottom.SetActive(true); // m_IntegralBottom.SetActive(false); // } // else if (model.showCoinsUIDict[shopType] == 2) // { // m_FollowStoreBottom.SetActive(false); // m_IntegralBottom.SetActive(true); // } //} m_FollowStoreBottom.SetActive(true); m_IntegralBottom.SetActive(false); } void RefreshCoins() { m_CoinsType1.text = UIHelper.GetMoneyCntEx(1).ToString(); if (UIHelper.GetMoneyCnt(2) > 0) m_CoinsType2.text = ItemLogicUtility.Instance.OnChangeCoinsUnit(UIHelper.GetMoneyCnt(2)); else { m_CoinsType2.text = UIHelper.GetMoneyCntEx(2).ToString(); } m_CoinsType3.text = UIHelper.ReplaceXianYuanCoinsNum(UIHelper.GetMoneyCnt(17)); } private void OnSecondTypeRefresh() { OnCreate(); m_ShopSecondCtrl.m_Scorller.RefreshActiveCellViews(); } private void OnCreateSecondType() { var arrayList = model.GetStoreSecondTypeList((int)model.storeFuncType); m_ShopSecondCtrl.Refresh(); foreach(int secondType in arrayList) { m_ShopSecondCtrl.AddCell(ScrollerDataType.Header, secondType); } m_ShopSecondCtrl.Restart(); } private void OnCreate() { shopId = 0; commodities = model.TryGetStoreDatasBySecondType((int)model.storeFuncType, model.selectSecondType); m_ShopCtrl.Refresh(); if (commodities.Count > 0) { int remain = commodities.Count % 2; int line = (int)commodities.Count / 2; if (remain > 0) { line += 1; } for (var i = 0; i < line; i++) { m_ShopCtrl.AddCell(ScrollerDataType.Header, i); } } m_ShopCtrl.Restart(); //m_ShopCtrl.JumpIndex(0); RefreshUI(); } private void OnRefreshPlayerInfo(PlayerDataType refreshType) { switch (refreshType) { case PlayerDataType.VIPLv: OnCreate(); break; case PlayerDataType.Gold: case PlayerDataType.GoldPaper: case PlayerDataType.FBHelpPoint: case PlayerDataType.default5: case PlayerDataType.default6: RefreshCoins(); break; default: break; } } private void RefreshShopSecondCell(ScrollerDataType type, CellView cell) { var secondCell = cell as ShopSecondCell; secondCell.Display(secondCell.index); } private void RefreshShopCell(ScrollerDataType type, CellView cell) { for (var i = 0; i < cell.transform.childCount; i++) { var cellCount = (cell.transform.childCount) * cell.index + (i + 1); var shopItemCell = cell.transform.GetChild(i).GetComponent(); if (shopItemCell == null) { shopItemCell = cell.transform.GetChild(i).gameObject.AddComponent(); } if (commodities.Count >= cellCount) { StoreConfig shopInfo = commodities[cellCount - 1].storeConfig; if (model.shopRedDict.ContainsKey(shopInfo.ID)) { shopItemCell.redpoint.redpointId = model.shopRedDict[shopInfo.ID].id; } cell.transform.GetChild(i).SetActive(true); if (shopInfo.SalesStatus.Trim() != "") { shopItemCell.stateImage.SetActive(true); shopItemCell.stateImage.SetSprite(shopInfo.SalesStatus); shopItemCell.stateImage.SetNativeSize(); } else { shopItemCell.stateImage.SetActive(false); } shopItemCell.buyOnceText.SetActive(false); var config = ItemConfig.Get(model.GetReplaceId(shopInfo.ID, shopInfo.ItemID)); if (config != null) { ItemCellModel cellModel = new ItemCellModel(config.ID, true, 0, "", PackType.Deleted, true); shopItemCell.itemCell.button.enabled = false; shopItemCell.itemCell.Init(cellModel); shopItemCell.itemCell.stateIcon.SetActive(false); shopItemCell.itemNameText.text = config.ItemName; shopItemCell.coinsIcon.SetIconWithMoneyType(shopInfo.MoneyType); ulong shopCost = (ulong)(shopInfo.MoneyNumber); shopItemCell.coinNumText.text = UIHelper.ReplaceLargeNum(shopCost); BuyItemController buyItem = BuyItemController.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 && curVipIndex == -1 && nextVipIndex != -1) { shopItemCell.coinsIcon.SetActive(false); shopItemCell.vipText.SetActive(true); shopItemCell.vipText.text = Language.Get("StoreWin101", shopInfo.VIPLV[nextVipIndex]); shopItemCell.sellImage.SetActive(false); shopItemCell.itemNameText.color = UIHelper.GetUIColor(TextColType.Red, true); shopItemCell.vipText.color = UIHelper.GetUIColor(TextColType.Red, true); isShowBuyPrice = false; } else if (PlayerDatas.Instance.baseData.LV < shopInfo.LV) { //等级购买限制 shopItemCell.coinsIcon.SetActive(false); shopItemCell.vipText.SetActive(true); shopItemCell.vipText.text = Language.Get("StoreWin115", shopInfo.LV); shopItemCell.sellImage.SetActive(false); shopItemCell.itemNameText.color = UIHelper.GetUIColor(TextColType.Red, true); shopItemCell.vipText.color = UIHelper.GetUIColor(TextColType.Red, true); isShowBuyPrice = false; } if (isShowBuyPrice) { shopItemCell.coinsIcon.SetActive(true); shopItemCell.vipText.SetActive(false); shopItemCell.sellImage.SetActive(false); shopItemCell.itemCell.countText.SetActive(false); int buyCntYet = canBuyCnt; if (canBuyCnt > 0) { shopItemCell.itemCell.countText.SetActive(true); BuyShopItemLimit shopItemLimit = model.GetBuyShopLimit((uint)shopInfo.ID); int remainNum = canBuyCnt; if (shopItemLimit != null) { remainNum = canBuyCnt - shopItemLimit.BuyCnt; buyCntYet = shopItemLimit.BuyCnt; } else { buyCntYet = 0; } if (shopInfo.ShopType == (int)StoreFunc.MysteryStore) { shopItemCell.itemCell.countText.text = shopInfo.ItemCnt > 1 ? shopInfo.ItemCnt.ToString() : ""; } else { var remainNumDescription = remainNum > 0 ? remainNum.ToString() : UIHelper.AppendColor(TextColType.Red, remainNum.ToString()); shopItemCell.itemCell.countText.text = shopInfo.TheOnlyShop == 1 ? "" : StringUtility.Contact(remainNumDescription, "/", canBuyCnt); } if (remainNum > 0) { shopItemCell.sellImage.SetActive(false); } else { shopItemCell.sellImage.SetActive(true); shopItemCell.stateImage.SetActive(false); } } if (shopInfo.TheOnlyShop == 1) { shopItemCell.buyOnceText.SetActive(true); shopItemCell.buyOnceText.text = Language.Get("StoreWin116", buyCntYet, canBuyCnt); } shopItemCell.itemNameText.color = UIHelper.GetUIColor(config.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); } model.CloseRedPoint(shopInfo); model.OnClickShopCell(shopInfo); }); } else { cell.transform.GetChild(i).SetActive(false); } } } private void OpenIntegralStore() { model.CloseAllRedpoint(StoreFunc.IntegralStore); model.storeFuncType = StoreFunc.IntegralStore; OnCreateSecondType(); model.selectSecondType = model.GetFirstStoreSecondType((int)model.storeFuncType); OnCreate(); UpdateRefreshTime(); functionOrder = m_IntegralStoreTitle.order; } //private void OpenBindGoldStore() //{ // model.CloseAllRedpoint(StoreFunc.BindStore); // model.storeFuncType = StoreFunc.BindStore; // OnCreate(); // UpdateRefreshTime(); // functionOrder = m_BindStoreTitle.order; //} private void OpenStrengthStore() { model.CloseAllRedpoint(StoreFunc.GrowStrongerStore); model.storeFuncType = StoreFunc.GrowStrongerStore; OnCreateSecondType(); model.selectSecondType = model.GetFirstStoreSecondType((int)model.storeFuncType); OnCreate(); UpdateRefreshTime(); functionOrder = m_GrowStrongerStoreTitle.order; } private void OpenCommonStore() { model.CloseAllRedpoint(StoreFunc.CommonStore); model.storeFuncType = StoreFunc.CommonStore; OnCreateSecondType(); model.selectSecondType = model.GetFirstStoreSecondType((int)model.storeFuncType); OnCreate(); UpdateRefreshTime(); functionOrder = m_CommonStoreTitle.order; } private void OpenMysteryStore() { model.CloseAllRedpoint(StoreFunc.MysteryStore); model.storeFuncType = StoreFunc.MysteryStore; OnCreate(); UpdateRefreshTime(); functionOrder = m_WeekStoreTitle.order; } private void OpenDayStore() { model.CloseAllRedpoint(StoreFunc.DayStore); model.storeFuncType = StoreFunc.DayStore; OnCreateSecondType(); model.selectSecondType = model.GetFirstStoreSecondType((int)model.storeFuncType); OnCreate(); UpdateRefreshTime(); functionOrder = m_DayStoreTitle.order; } private void ViewAssistRecorders() { WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.DungeonAssitCheckIn); } private void RefreshCommondities() { var config = ItemConfig.Get(GeneralDefine.mysteryShopRefreshItem); if (model.isShowMysteryRefreshHint) { var own = packModel.GetItemCountByID(PackType.Item, GeneralDefine.mysteryShopRefreshItem); var need = model.GetMysteryShopRefreshItemNeed(); var needMoney = need * GeneralDefine.mysteryShopRefreshItemValue; var description1 = Language.Get("MysteryStore1", need); ConfirmCancel.IconConfirmCancel(Language.Get("Mail101"), description1, GeneralDefine.mysteryShopRefreshItem, own, need, Language.Get("MysteryStore2", needMoney), Language.Get("ConfirmCancel102"), (bool ok, bool isToggle) => { if (ok) { model.RefreshMysteryShop(); } model.isShowMysteryRefreshHint = !isToggle; }); } else { model.RefreshMysteryShop(); } } } }