---@class KLShopMallPanel:UIKmlLuaPanelBase ---@field view KLShopMallPanelView local KLShopMallPanel = class(UIKmlLuaPanelBase) local this =KLShopMallPanel local subTabItemPath = "dev/ui/ShopMall/Item/KLShopMallSubTab/KLShopMallSubTabItem" ---创建时调用一次 function this:Init() ---@type MallProtos.MallGoods[] self.goodsList = {} ---@type table self.goodsItem = {} ---@type table self.goodsListMap = {} ---@type table self.goodsItemMap = {} self.homeToggleMap = {} if self.args then ---@type cfg_menu_layer_column local jumpTbl = nil if type(self.args) == "table" then jumpTbl = SL:GetConfig("cfg_menu_layer",tonumber(self.args[1])) else jumpTbl = SL:GetConfig("cfg_menu_layer",tonumber(self.args)) end if jumpTbl then self.jumpHomeTabId = jumpTbl.parentID self.jumpSubTabId = jumpTbl.id end end local level = SL:GetMetaValue(EMetaVarGetKey.LEVEL) ---@type cfg_menu_layer_column[] local homeTabConfigs = {} ---@type cfg_menu_layer_column[] local tblList = SL:GetConfigTable("cfg_menu_layer") for _, v in pairs(tblList) do if v.parentID == 1000 and v.level <= level then table.insert(homeTabConfigs,v) end end for k,homeTabConfig in pairs(homeTabConfigs) do ---@type KLShopMallHomeTabItem local homeTab = GUI:UIPanel_Open("dev/ui/ShopMall/Item/KLShopMallHomeTab/KLShopMallHomeTabItem",self.view.TopHomeToggleGroup,self,homeTabConfig,true, function(homeTab) local jump = (self.jumpHomeTabId and self.jumpHomeTabId == homeTabConfig.id) or (not self.jumpHomeTabId and k == 1) if jump then GUI:Toggle_setIsOn(homeTab.view.KmlShopMallHomeTab,true) self:RefreshSubTab(homeTabConfig.id) end GUI:SetToggleOnValueChange(homeTab.view.KmlShopMallHomeTab,self,self.HomeTabOnToggle,homeTabConfig.id) self.homeToggleMap[homeTabConfig.id] = homeTab.view.KmlShopMallHomeTab end) end self.jumpHomeTabId = nil GUI:DataListInitData(self.view.ShopMallGoodsList, function() return self:ShopMallCountGetFun() end, function(realIndex) return self:ShopMallItemGetFun(realIndex) end, nil, function(realIndex,item) self:ShopMallItemUpdateFun(realIndex,item) end, nil) GUI:OSAScrollView_Initialized(self.view.osa_money_list,nil,self.ItemUpdateFun,self) self.hasInit = true; end ---@param item UIKmlLuaControl function this:ItemUpdateFun(item,index) local moneyId = self.curSelectSubTabTbl.money[index + 1] local moneyIcon = GUI:GetChildById(item,"img_money_icon") GUI:Image_loadTexture(moneyIcon,moneyId,"Atlas/TS_Common.spriteatlas") local btnTip = GUI:GetChildById(item,"btn_money_tip") GUI:AddOnClickEvent(btnTip,self,self.BtnAddOnClick,moneyId) local textMoneyCount = GUI:GetChildById(item,"text_money_count") GUI:Text_setString(textMoneyCount,tostring(SL:GetTotalCoinBaseId(moneyId))) end function this:ShopMallCountGetFun() return #self.goodsList end function this:ShopMallItemGetFun(realIndex) ---@type KLShopMallGoodsItem local item = GUI:UIPanel_Open("dev/ui/ShopMall/Item/KLShopMallGoods/KLShopMallGoodsItem",self.view.ShopMallGoodsList,self,nil,true,function(item) local needRefresh = self.goodsItem[item.view.root] == false --经历过刷新失败的情况 self.goodsItem[item.view.root] = item if needRefresh then self:ShopMallItemUpdateFun(realIndex,item.view.root) end end ) return item.view.root end function this:ShopMallItemUpdateFun(realIndex,item) if not self.goodsItem[item] then self.goodsItem[item] = false return end local data = self.goodsList[realIndex + 1] local goodsItem = self.goodsItem[item] goodsItem:RefreshItem(data) GUI:SetID(goodsItem.view.ButtonBg, "ButtonBg"..tostring(data.goodsId)) self.goodsListMap[data.goodsId] = data self.goodsItemMap[data.goodsId] = goodsItem end function this:HomeTabOnToggle(_,customData,eventData) if eventData[1] then self:RefreshSubTab(customData) end end function this:RefreshSubTab(homeTabId) if self.subWins[subTabItemPath] then for _, win in pairs(self.subWins[subTabItemPath]) do GUI:UIPanel_Close(subTabItemPath,win) end table.clear(self.subWins[subTabItemPath]) end local level = SL:GetMetaValue(EMetaVarGetKey.LEVEL) ---@type cfg_menu_layer_column[] local subTabConfigs = {} ---@type cfg_menu_layer_column[] local tblList = SL:GetConfigTable("cfg_menu_layer") for _, v in pairs(tblList) do if v.parentID == homeTabId and v.level <= level then table.insert(subTabConfigs,v) end end for k,subTabConfig in pairs(subTabConfigs) do ---@type KLShopMallSubTabItem GUI:UIPanel_Open(subTabItemPath,self.view.LeftSubToggleGroup,self,subTabConfig,true, function(subTab) if (self.jumpSubTabId and self.jumpSubTabId == subTabConfig.id) or (not self.jumpSubTabId and k == 1) then GUI:Toggle_setIsOn(subTab.view.ToggleLevel,true) self:SubTabOnToggle(_,subTabConfig,{true}) self.jumpSubTabId = nil end GUI:SetToggleOnValueChange(subTab.view.ToggleLevel,self,self.SubTabOnToggle,subTabConfig) end) end end ---@param customData cfg_menu_layer_column function this:SubTabOnToggle(_,customData,eventData) if eventData[1] then SL:RequestShopMallGoodsInfo(customData.id) self.curSelectSubTabTbl = customData self:RefreshMoneyInfo() end end ---创建或者刷新界面数据时调用 function this:Refresh() SL.HideMainPanel() self:RefreshMoneyInfo() end function this:RefreshMoneyInfo() if self.curSelectSubTabTbl then GUI:OSAScrollView_RefreshList(self.view.osa_money_list,#self.curSelectSubTabTbl.money) end --[[ GUI:Text_setString(self.view.GoldCount,tostring(SL:GetBagItemCount(10010001))) GUI:Text_setString(self.view.QjCount,tostring(SL:GetBagItemCount(10020001))) GUI:Text_setString(self.view.QjBindCount,tostring(SL:GetBagItemCount(10030001))) GUI:Text_setString(self.view.DiamondCount,tostring(SL:GetBagItemCount(10040001)))]] end ---注册UI事件和服务器消息 function this:RegistEvents() GUI:AddOnClickEvent(self.view.CloseBtn,self,self.CloseBtnOnClick) SL:RegisterLuaNetMsg(MessageDef.ResMallGoodsInfoMessage,self.ResMallGoodsInfoMessage,self) SL:RegisterLuaNetMsg(MessageDef.ResBuyMallGoodsMessage,self.ResBuyMallGoodsMessage,self) SL:RegisterLUAEvent(LUA_EVENT_MONEYCHANGE,self.RefreshMoneyInfo,self) --[[ GUI:AddOnClickEvent(self.view.BtnGoldGetWayTip,self,self.BtnAddOnClick,10010001) GUI:AddOnClickEvent(self.view.BtnQjGetWayTip,self,self.BtnAddOnClick,10020001) GUI:AddOnClickEvent(self.view.BtnQjBindGetWayTip,self,self.BtnAddOnClick,10030001) GUI:AddOnClickEvent(self.view.BtnDiamondGetWayTip,self,self.BtnAddOnClick,10040001)]] end function this:BtnAddOnClick(_,cfgId) SL:CommonItemGetPath(nil,cfgId,nil,nil,self) end function this:CoinOnClick(_,cfgId) SL:OpenTips(nil,cfgId) end ---@param message MallProtos.MallGoodsInfoRes function this:ResMallGoodsInfoMessage(_,message) self.goodsList = message.goodsList GUI:DataListUpdateData(self.view.ShopMallGoodsList) if self.guideId then KLGuideManager.HidePointControlGuide(self.guideId) end end ---@param message MallProtos.BuyMallGoodsRes function this:ResBuyMallGoodsMessage(_,message) self:Refresh() local goodsItem = self.goodsItemMap[message.goodsId] local goodsData = self.goodsListMap[message.goodsId] goodsData.limitCount = goodsData.limitCount - message.count goodsData.limitCount = goodsData.limitCount < 0 and 0 or goodsData.limitCount goodsItem:RefreshItem(goodsData) ---@type cfg_shopMall_column local shopTbl = SL:GetConfig("cfg_shopMall",message.goodsId) SL:OpenRewardTips({[goodsItem.config.itemId] = (message.count * shopTbl.count)},0) end function this:CloseBtnOnClick() GUI:UIPanel_Close("dev/ui/ShopMall/Panel/KLShopMall/KLShopMallPanel") GUI:UIPanel_Close("dev/outui/ShopMain/Panel/KLShopMain/KLShopMainPanel") SL.ShowMainPanel() end function this:Close() SL:UnRegisterLuaNetMsg(MessageDef.ResMallGoodsInfoMessage,self.ResMallGoodsInfoMessage,self) end function this:GotoItemSubPage(itemId, guideId) local shopMallItem ---@type cfg_shopMall_column[] local tblList = SL:GetConfigTable("cfg_shopMall") for _, v in pairs(tblList) do if v.itemId == itemId then shopMallItem = v break end end if not shopMallItem then return end local subTabId = shopMallItem.subTab[1] self.jumpSubTabId = subTabId ---@type cfg_menu_layer_column local menuLayer = SL:GetConfig("cfg_menu_layer",subTabId) local homeTabId = menuLayer.parentID if self.homeToggleMap[homeTabId] then GUI:Toggle_setIsOn(self.homeToggleMap[homeTabId],true) --self:RefreshSubTab(homeTabId) end if guideId then self.guideId = guideId Coroutine.Start(function() Coroutine.WaitForEndOfFrame() KLGuideManager.AddPointControlGuide("KLShopMallPanel", "ButtonBg"..tostring(shopMallItem.id), guideId) end) end end return this