local UIShopMain = UIViewClass() local EventSystem = require('Event/EventSystem') local Imgtopbg = ConstAssetPathConfig.ItemBg --local str = "购买条件:%d" 回主干加IDS local function SortTabFunc(storeTypeData_1, storeTypeData_2) return storeTypeData_1.StoreSortID < storeTypeData_2.StoreSortID end local TypeID = 1 function UIShopMain:OnCreated() self.EnumTabType = { Shop = 0,--商城 Pay = 1,--充值 } self.cacheCount = {} self.curBuyCount = 1 self.lastLoopCell = nil self.curShopTypeId = nil self.isShowLimitInfo = false self.keyBoardView = nil self:RegistSystemEvent(EventID.UI_Shop_Pay, self.OpenPay) self.tabEnumToIndex = {} self.tabDataArray = {} end function UIShopMain:OnOpened(context) --self:RegistSystemEvent(EventID.UI_Shop_Buy_Success, self.DisplayDetailsInfo) self:RegistSystemEvent(EventID.UI_Shop_RefreshShopInfo, self.ReSortItem) self:RegistSystemEvent(EventID.UI_DrawCard_OnCloseGamePlay, self.OnCloseGamePlay) --静态数据如果变更,需要刷新 self:RegistSystemEvent(EventID.UI_OperationActivity_DataChanged, self.OnDataChanged) self:RegistSystemEvent(EventID.UI_Shop_ForceClose, self.OnCloseGamePlay) if GameAppInfo.IsJapanesePackage() then self:RegistSystemEvent(EventID.FunctionUnlockUpdate, self.OnFunctionUnlockUpdate) end self:InitTxt() -- 界面标题 UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS["IDS_Storesystem"]) UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, false) if Localization.IsEnglish() then self.txt_Prompt.text = string.format(UIUtils.GetLocalizedTxt(Const_IDS.IDS_Store_ResetTime),UTL.Time.GetDiffLocalStrById(1)).." "..UIUtils.GetLocalizedTxt(Const_IDS.IDS_Daily) else self.txt_Prompt.text = UIUtils.GetLocalizedTxt(Const_IDS.IDS_Daily) .. string.format(UIUtils.GetLocalizedTxt(Const_IDS.IDS_Store_ResetTime),UTL.Time.GetDiffLocalStrById(1)) end self.CurTab = self.EnumTabType.Shop if context then self.context = context end self:OnDataChanged() end function UIShopMain:OnFunctionUnlockUpdate(id, state) if id == MDL.Unlock.FunctionType.ClimbTower then --爬塔功能关闭,需要关掉百战页签 self:OnDataChanged() end end --更新页签列表 function UIShopMain:UpdateTabArray() table.clearArray(self.tabDataArray) if not GameAppInfo.IsJapanesePackage() then for i ,v in MDL.OperationActivity.StoreTypeData:GetEnumerator() do if v.TypeID == TypeID and CTL.PayMall.IsShowPurchase(v) then table.insert(self.tabDataArray, v) end end else --日本的百战页签要在公平页签下边 local targetIndex local targetInfo for i ,v in MDL.OperationActivity.StoreTypeData:GetEnumerator() do if v.TypeID == TypeID and CTL.PayMall.IsShowPurchase(v) then if v.enum ~= CTL.PayMall.ShopMainTabEnum.JPBaiZhan then table.insert(self.tabDataArray, v) if v.enum == CTL.PayMall.ShopMainTabEnum.GongPing then targetIndex = #self.tabDataArray + 1 end else if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.ClimbTower) then targetInfo = v end end end end if targetInfo then if targetIndex then table.insert(self.tabDataArray, targetIndex, targetInfo) else table.insert(self.tabDataArray, targetInfo) end end end table.sort(self.tabDataArray, SortTabFunc) for i, v in ipairs(self.tabDataArray) do self.tabEnumToIndex[v.enum] = i - 1 end end function UIShopMain:OnDataChanged() self:UpdateTabArray() self.loop_Tab:ReloadAll(self.tabDataArray) if self.curGoodsData then local data = MDL.OperationActivity.StoreGoodsData:GetDataByID(self.curGoodsData.ID) if data then self:ReSortItem(self.curGoodsData.ID) else self.CurTab = self.EnumTabType.Shop self:ReSortItem() end else self:ReSortItem() end end function UIShopMain:OnCloseGamePlay() self:CloseView(true) end function UIShopMain:LocateItemPosition() if self.context.itemId then local itemId = self.context.itemId local tabId = MDL.Shop.GetTabIDByItemId(itemId, MDL.ItemSources.SourceType.Store) local tabEnum = MDL.OperationActivity.StoreTypeData:GetDataByTabID(tabId).enum local tabIndex = self.tabEnumToIndex[tabEnum] self.loop_Tab:SelectIndex(tabIndex) local index = MDL.Shop.GetItemIndexInStore(itemId, MDL.ItemSources.SourceType.Store) if index then local offset = index % 2 self.ShopScroll:MoveIndex(index - offset) self.ShopScroll:SelectIndex(index, false) else logging.error(LTAG.ERROR, "没有在该商品类中找到物品ID:", itemId) end end -- 添加打开界面页签跳转参数 local tabTypeId = self.context.tabTypeId if tabTypeId then self.toggle_LeftGroup:SelectIndex(tabTypeId) end local subIndex = self.context.SubIndex if subIndex then self.CurTab = subIndex self.loop_Tab:SelectIndex(self.CurTab) end local tabEnum = self.context.TabEnum if tabEnum and self.tabEnumToIndex[tabEnum] then self.CurTab = self.tabEnumToIndex[tabEnum] self.loop_Tab:SelectIndex(self.CurTab, true) end self.context = nil end --打开支付 function UIShopMain:OpenPay() self.toggle_LeftGroup:SelectIndex(self.EnumTabType.Pay) end function UIShopMain:InitTxt() self.ToggleTxt = {} table.insert(self.ToggleTxt, self.txt_1) table.insert(self.ToggleTxt, self.txt_2) table.insert(self.ToggleTxt, self.txt_3) table.insert(self.ToggleTxt, self.txt_4) table.insert(self.ToggleTxt, self.txt_5) table.insert(self.ToggleTxt, self.txt_6) end function UIShopMain:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.ShopScroll then local goodsInfo = data.OriData UIUtils.SetLabel(cellTable.txt_ItemName, UTL.Item.GetItemDataSpliceByType(goodsInfo.ItemID).Name) cellTable.txt_Cost.text = goodsInfo.BuyPrice UTL.Item.SetCurrencyImageIcon(cellTable.icon_Cost, goodsInfo.MoneyID) UTL.Item.SetItemCell(cellTable.Item, goodsInfo.ItemID, goodsInfo.ItemNum) local isUnlock, des = CTL.PayMall.IsUnlockPurchase(goodsInfo, true) local isSoldout = CTL.PayMall.IsSoldOut(goodsInfo) local canBuy = isUnlock and not isSoldout if canBuy then cellTable.state_Item:SetState(1) elseif not isUnlock then --未解锁 cellTable.state_Item:SetState(2) UIUtils.SetLabel(cellTable.txt_Lock, des) else --售罄 cellTable.state_Item:SetState(0) UIUtils.SetLabel(cellTable.txt_SellOut, CTL.PayMall.GetLimitedSoldout(goodsInfo)) end cellTable.cell:SetRedPoint(CTL.PayMall.IsShowRpByGoodData(goodsInfo)) self:DiscountInfo(cellTable, goodsInfo) local isShowMain, isShowAssist = CTL.PayMall.GetItemUseState(goodsInfo.ItemID) UIUtils.SetActive(cellTable.img_OnMain, isShowMain) UIUtils.SetActive(cellTable.img_OnAssist, isShowAssist) elseif scrollRect == self.loop_Tab then cellTable.loc_txt1:SetState(1) local tabName = MDL.Shop.GetStoreTypeTabName(data.TabID) cellTable.txt_1.text= UIUtils.GetLocalizedTxt(Const_IDS[tabName]) cellTable.cell:SetRedPoint(CTL.PayMall.IsShowTabRedPoint(data.enum)) if data.enum == CTL.PayMall.ShopMainTabEnum.JPBaiZhan then UIUtils.SetActive(cellTable.img_JPNew, CTL.PayMall.GetNewSymbolState_JPBaiZhan()) else UIUtils.SetActive(cellTable.img_JPNew, false) end elseif scrollRect == self.scroll_Num then local buildingLimitData = string.split(data[1].Tigger_Table[1].TriggerParam,";") local color = data.ChangeColorIndex == index and UTL.Color.yellow or UTL.Color.ModelNameColor.White cellTable.txt_Level.text = UTL.Color.FormatTextByColor(color, buildingLimitData[2]) cellTable.txt_Num.text = UTL.Color.FormatTextByColor(color, tostring(data[1].BuyLimit)) end end function UIShopMain:GetConstMoney(goodsInfo) if goodsInfo.ItemDiscount <= 0 then return 0 else if not self:IsInDiscountTime(goodsInfo) then return goodsInfo.BuyPrice else return math.floor(UTL.String.GetDiscountedValue(goodsInfo.ItemDiscount, goodsInfo.BuyPrice)) end end end function UIShopMain:DiscountInfo(cellTable, goodsInfo) local isInDiscount, timeStr, singlePrice = CTL.PayMall.IsInDiscount(goodsInfo) UIUtils.SetActive(cellTable.bg_Discount, isInDiscount) UIUtils.SetActive(cellTable.txt_Cost, isInDiscount) UIUtils.SetLabel(cellTable.txt_Discount, UTL.String.GetDiscountStrByIdsId(goodsInfo.ItemDiscount)) UIUtils.SetLabel(cellTable.txt_CostDisCount, singlePrice) end function UIShopMain:IsInDiscountTime(goodsInfo) if goodsInfo.DiscountOnTime == nil or goodsInfo.DiscountOnTime <= 0 or goodsInfo.DiscountOffTime == nil or goodsInfo.DiscountOffTime <= 0 then return true else local isDisplay = UTL.Time.IsServerInOpeningTime(goodsInfo.DiscountOnTime, goodsInfo.DiscountOffTime) return isDisplay end end function UIShopMain:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.ShopScroll then self.curSelectGood = index self:DisplayDetailsInfo(data) elseif scrollRect == self.loop_Tab then self:SwitchMainType(0) cellTable.loc_txt1:SetState(0) UIUtils.SetActive(cellTable.mark_1,true) if self.lastLoopCell ~=nil and self.lastLoopCell~=cellTable then self.lastLoopCell.loc_txt1:SetState(1) end self.lastLoopCell=cellTable if self.MainTypeIndex == self.EnumTabType.Shop then self.curShopTypeId = self.tabDataArray[index + 1].TabID local goodsInfo = MDL.Shop.GetShopGoodsCfgByTypeID(self.curShopTypeId) self.ShopScroll:ReloadAll(goodsInfo) if self.ShopScroll.Count > 0 then if not self.flagSelectGood then self.ShopScroll:SelectIndex(0, true) self:DisplayDetailsInfo(goodsInfo[1]) end local currencyInfo = MDL.OperationActivity.StoreTypeData:GetDataByTabID(self.curShopTypeId).MoneyTypeHUD if #currencyInfo > 0 then EventSystem.Dispatch(EventID.UI_Shop_Refresh_Currency, currencyInfo) else currencyInfo = CTL.Currency.GetCurrentTypeIds(self.__viewName) if currencyInfo then EventSystem.Dispatch(EventID.UI_Shop_Refresh_Currency, currencyInfo) end end end end if data.enum == CTL.PayMall.ShopMainTabEnum.MonthCard then --处理双月卡商城激活的一次性红点 if MDL.RedPoint.GetOneTimeRedPointInfoByType(MDL.RedPoint.RedPointType.MonthCard) == 0 then CTL.RedPoint.RemoveRedPoint(CTL.RedPoint.RedPointKey.Shop_MonthCard) MDL.RedPoint.OneTimeRedPointRequest(MDL.RedPoint.RedPointType.MonthCard, 1) end cellTable.cell:SetRedPoint(CTL.PayMall.IsShowTabRedPoint(data.enum)) end if GameAppInfo.IsJapanesePackage() then if data.enum == CTL.PayMall.ShopMainTabEnum.JPBaiZhan then CTL.PayMall.RemoveBaizhanNewState() UIUtils.SetActive(cellTable.img_JPNew, false) end end end end --右侧购买详情界面 function UIShopMain:DisplayDetailsInfo(data) if data ~= nil then self.curGoodsData = data.OriData end self.LimitInfoBtnShow = false UIUtils.SetActive(self.group_LimitInfo.gameObject,false) ------------------------------- self.curBuyCount = 1 self:RefreshCount(0) local goodsItem = DataSheetManager.ItemData:GetDataByID(self.curGoodsData.ItemID) local qualityData = DataSheetManager.QualityColor:GetDataByID(goodsItem.Color) local colorBg = qualityData.EquipFragmentComposeBase local colorPrint = qualityData.EquipRefineIcon UIUtils.SetImageByAssetBundle(self.img_TopBg, string.format(Imgtopbg, colorBg)) UIUtils.SetImageByAssetBundle(self.img_Print, string.format(Imgtopbg, colorPrint)) UTL.Item.SetItemCell(self.ItemDetails, self.curGoodsData.ItemID) UIUtils.SetGray(self.ItemDetails.img_Item, not CTL.PayMall.IsUnlockPurchase(self.curGoodsData, false)) self.ItemDetails.event_Click:SetGray(false, false) UIUtils.SetLabel(self.txt_ItemName, UTL.Item.GetItemDataSpliceByType(self.curGoodsData.ItemID).Name) for k, v in MDL.OperationActivity.StoreGoodsLimitBuyDetail:GetEnumerator() do if v.ID==self.curGoodsData.ID then self.LimitInfoBtnShow = true self.LimitbuildID = tonumber(string.split(v.Tigger_Table[1].TriggerParam,";")[1]) break end end -- 设置title必要信息 local isLimit, limitStr = CTL.PayMall.IsLimitedGood(self.curGoodsData) UIUtils.SetLabel(self.limit_txt_Num, limitStr) UIUtils.SetActive(self.lab_PurchaseNum, isLimit) UIUtils.SetLabel(self.lab_PurchaseNum, CTL.PayMall.GetLimitedTitle(self.curGoodsData)) UIUtils.SetLabel(self.des_txt_Info, UTL.Item.GetItemDataSpliceByType(self.curGoodsData.ItemID).Des) UIUtils.SetActive(self.btn_LimitInfo.gameObject,self.LimitInfoBtnShow) self.own_txt_Num.text = UTL.Item.GetItemStockCount(self.curGoodsData.ItemID) -- 判断是否可购买 local isSoldOut = CTL.PayMall.IsSoldOut(self.curGoodsData) local isUnlock, des = CTL.PayMall.IsUnlockPurchase(self.curGoodsData, true) local canBuy = isUnlock and not isSoldOut UIUtils.SetActive(self.group_NumSelect.gameObject, canBuy) UIUtils.SetActive(self.event_Count.gameObject, canBuy) if canBuy then UTL.Item.SetCurrencyImageIcon(self.DetailMoneyIcon, self.curGoodsData.MoneyID) end self.event_Buy:SetGray(not canBuy, canBuy) UIUtils.SetActive(self.event_Buy.gameObject, canBuy) UIUtils.SetActive(self.txt_Lock, not isUnlock) if not isUnlock then UIUtils.SetLabel(self.txt_Lock, des) UIUtils.SetActive(self.txt_SellOut.gameObject, false) CTL.Sound.PlayGameSound("UI_invalid") else UIUtils.SetActive(self.txt_SellOut.gameObject, isSoldOut) UIUtils.SetLabel(self.txt_SellOut, CTL.PayMall.GetLimitedSoldout(self.curGoodsData)) end -- 判断折扣 local isInDiscount, timeStr, singlePrice = CTL.PayMall.IsInDiscount(self.curGoodsData) UIUtils.SetActive(self.group_Discount, isInDiscount and self.curGoodsData.DiscountOnTime ~= 0) UIUtils.SetLabel(self.txt_DiscountTime, timeStr) local isShow, showStr = CTL.PayMall.GetItemUpgradeInfo(self.curGoodsData.ItemID) UIUtils.SetActive(self.group_NeedNum, isShow) if isShow then UIUtils.SetLabel(self.txt_Need, showStr) end end function UIShopMain:OnValueChanged(comp, index) if comp == self.toggle_LeftGroup then self:SwitchMainType(index) end end function UIShopMain:SwitchMainType(mainTypeIndex) self.MainTypeIndex = mainTypeIndex if mainTypeIndex == self.EnumTabType.Shop then --加载二级页签 if #self.tabDataArray == #self.ToggleTxt then for i = 1, #self.tabDataArray do local storeTypeData = MDL.OperationActivity.StoreTypeData:GetDataByTabID(self.tabDataArray[i]) local tabName = MDL.Shop.GetStoreTypeTabName(storeTypeData.TabID) UIUtils.SetLabelText(self.ToggleTxt[i], Const_IDS[tabName]) end else local beginHideIndex = #self.tabDataArray + 1 for i = beginHideIndex, #self.ToggleTxt do UIUtils.SetActive(self.ToggleTxt[i].transform.parent.gameObject, false) end end elseif mainTypeIndex == self.EnumTabType.Pay then self:ShowPayPage() end end function UIShopMain:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIShopMain:OnButtonClicked(comp) local _, _, availablePurchaseCount = CTL.PayMall.IsLimitedGood(self.curGoodsData) if comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.event_Buy then self:Buy() elseif comp == self.event_Plus then if self.curBuyCount + 1 <= availablePurchaseCount then self:RefreshCount(1) end elseif comp == self.event_Minus then if self.curBuyCount - 1 > 0 then self:RefreshCount(-1) end elseif comp == self.event_Max then --购买上限 self.curBuyCount = 0 self:RefreshCount(availablePurchaseCount) elseif comp == self.event_Count then if not self.keyBoardView then local _, _, availablePurchaseCount = CTL.PayMall.IsLimitedGood(self.curGoodsData) self.keyBoardView = self.subView:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIKeypad), {parentView = self, x = 731, y = 110, minNum = 1, maxNum = availablePurchaseCount}) end elseif comp == self.btn_LimitInfo then if self.isShowLimitInfo then self.isShowLimitInfo = false else self.isShowLimitInfo = true end self:RefreshShowLimitInfo(self.isShowLimitInfo) elseif comp == self.btn_LimitInfoClose then self.isShowLimitInfo = false self:RefreshShowLimitInfo(self.isShowLimitInfo) end end function UIShopMain:ExcuteKeyBoardBack(count, paramData) self:keyPadCallback(count) end function UIShopMain:CloseKeyBoardView() self.keyBoardView:CloseView() self.keyBoardView = nil end function UIShopMain:Buy() local isDiscount, des, singlePrice = CTL.PayMall.IsInDiscount(self.curGoodsData) -- 折扣变更 if self.singlePrice ~= singlePrice then self.ShopScroll:RefreshCells(false) self:DisplayDetailsInfo() CTL.Tips.AddTipsMsg(Const_IDS.IDS_Store_ResetPrice) return end if CTL.PayMall.IsCanPurchase(self.curGoodsData, self.curBuyCount) then MDL.Purchase.PurchaseItemsReq(self.curGoodsData.ID, self.curBuyCount) end end --数字键盘回调 function UIShopMain:keyPadCallback(value) if value <= 0 then self:RefreshCount(1) else self.curBuyCount = 0 self:RefreshCount(value) end end function UIShopMain:RefreshCount(count) local canBuyCount, isEnough, costNum = CTL.PayMall.CalculateAvailablePurchase(self.curGoodsData, self.curBuyCount + count) self.curBuyCount = canBuyCount local isInDiscount, timeStr, singlePrice = CTL.PayMall.IsInDiscount(self.curGoodsData) self.singlePrice = singlePrice UIUtils.SetLabel(self.txt_NumCost, isEnough and UTL.Color.FormatGreenColor(costNum) or UTL.Color.FormatRedColor(costNum)) UIUtils.SetLabel(self.txt_NumSelect, self.curBuyCount) self:CheckBuyNumButtonsSetGray() end --JWS2-30663 购买次数到最大最小值时置灰,货币数量不够也置灰 function UIShopMain:CheckBuyNumButtonsSetGray() local curNum = self.curBuyCount local _, _, availablePurchaseCount = CTL.PayMall.IsLimitedGood(self.curGoodsData) local isCantMinus = curNum <= 1 local notEnoughStockToBuyMore = CTL.PayMall.CalculateIsStockNotEnoughToBuyMore(self.curGoodsData,curNum + 1) local isCantPlus = curNum >= availablePurchaseCount or notEnoughStockToBuyMore self.event_Minus:SetGray(isCantMinus, not isCantMinus) self.event_Plus:SetGray(isCantPlus, not isCantPlus) self.event_Max:SetGray(isCantPlus, not isCantPlus) end function UIShopMain:ReSortItem(goodId) if self.context then self:LocateItemPosition() else if self.CurTab ~= nil then self.loop_Tab:SelectIndex(self.CurTab) self.CurTab = nil end if goodId and MDL.OperationActivity.StoreGoodsData:GetDataByID(goodId) then self.curGoodsData = MDL.OperationActivity.StoreGoodsData:GetDataByID(goodId) self.curShopTypeId = self.curGoodsData.TabID local storeTypeData = MDL.OperationActivity.StoreTypeData:GetDataByTabID(self.curShopTypeId) self.flagSelectGood = true self.loop_Tab:RefreshCells(true) local goodsInfo = MDL.Shop.GetShopGoodsCfgByTypeID(self.curShopTypeId) for i, v in ipairs (goodsInfo) do if v.OriData.ID == goodId then if not CTL.PayMall.IsSoldOut(v.OriData) then self.curSelectGood = i - 1 end end end self.ShopScroll:ReloadAll(goodsInfo) local offset = self.curSelectGood % 2 self.ShopScroll:MoveIndex(self.curSelectGood - offset) self.flagSelectGood = false self.ShopScroll:SelectIndex(self.curSelectGood, false) self:DisplayDetailsInfo(goodsInfo[self.curSelectGood + 1]) end end end function UIShopMain:RefreshShowLimitInfo(isShow) UIUtils.SetActive(self.group_LimitInfo.gameObject, isShow) if isShow then --满足条件的cell计数 self.LevelCount = 0 self.scroll_Num:ClearCells() local BuildingName= UIUtils.GetLocalizedTxt(Const_IDS[MDL.Guild.GetBuildName(self.LimitbuildID)]) self.lab_Level.text = string.format(UIUtils.GetLocalizedTxt(Const_IDS.IDS_GuildShop_BuildingLevel),BuildingName) self.ChangeColorIndex = -1 for k, v in MDL.OperationActivity.StoreGoodsLimitBuyDetail:GetEnumerator() do if MDL.Guild.CheckBuildLevel(v.Tigger_Table[1].TriggerParam) and self.curGoodsData.ID == v.ID then self.ChangeColorIndex = self.ChangeColorIndex + 1 end end for k, v in MDL.OperationActivity.StoreGoodsLimitBuyDetail:GetEnumerator() do if self.curGoodsData.ID == v.ID then self.scroll_Num:AddData({v, ChangeColorIndex = self.ChangeColorIndex},0) end end end end function UIShopMain:OnClosed() UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) if self.lastLoopCell then self.lastLoopCell.loc_txt1:SetState(1) end self.lastLoopCell = nil self.keyBoardView = nil end return UIShopMain