123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- ---@class KLTradeCommonGoodsPanel:UIKmlLuaPanelBase
- ---@field view KLTradeCommonGoodsPanelView
- local KLTradeCommonGoodsPanel = class(UIKmlLuaPanelBase)
- local this = KLTradeCommonGoodsPanel
- ---创建时调用一次
- function this:Init()
- --初始化商品列表配置
- GUI:DataListInitData(self.view.datalist_goods, function()
- return self:ItemCountFunc()
- end, function(realIndex)
- return self:ItemGetFunc(realIndex)
- end, nil, function(realIndex, kmlCtrl)
- return self:ItemUpdateFunc(realIndex, kmlCtrl)
- end)
- ---@type table<UIKmlLuaControl,KLTradeGoodsItem>
- self.goodsItems = {}
- self.goodsItemDataList = {}
- self.tickTimer = SL:Schedule(self.tickTimer, 0, 1, -1, function()
- return self:Tick()
- end)
- end
- function this:ItemCountFunc()
- return #self.goodsItemDataList
- end
- function this:ItemGetFunc(realIndex)
- ---@type KLTradeGoodsItem
- local item = GUI:UIPanel_Open("dev/outui/Trade/Item/KLTradeGoods/KLTradeGoodsItem", self.view.datalist_goods, self, nil, true)
-
- self.goodsItems[item.view.root] = item
- return item.view.root
- end
- function this:ItemUpdateFunc(realIndex, kmlCtrl)
- local data = self.goodsItemDataList[realIndex + 1]
- local item = self.goodsItems[kmlCtrl]
- item:UpdateData(data)
- end
- ---注册UI事件和服务器消息
- function this:RegistEvents()
- SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_GET_TRADE_GOODS, self.RES_GET_TRADE_GOODS, self)
- end
- function this:RES_GET_TRADE_GOODS(_, message)
- if not message then
- return
- end
- local type = 0
- table.clear(self.goodsItemDataList)
- local tempMessage = {}
- for k, v in pairs(message) do
- tempMessage[tonumber(k)] = v
- end
- for k, v in pairs(tempMessage) do
- local stallTbl = SL:GetConfig("cfg_stall", v.itemcfgid)
- if stallTbl and stallTbl.type ~= 1 and stallTbl.type ~= 5 then ---月卡时间和奇迹币类型不在这里显示
- table.insert(self.goodsItemDataList, v)
- end
- end
- GUI:DataListUpdateData(self.view.datalist_goods)
- end
- ---创建或者刷新界面数据时调用
- function this:Refresh()
- end
- function this:Close()
- SL:UnSchedule(self.tickTimer)
- table.clear(self.goodsItemDataList)
- GUI:DataListUpdateData(self.view.datalist_goods)
- end
- function this:RequestRefreshGoodsList(type, subType, sortType, careerType, filterLevel, filterQuality)
- if self.last then
- if type == nil then
- type = self.last.type
- end
- if subType == nil then
- subType = self.last.subType
- end
- if sortType == nil then
- sortType = self.last.sortType
- end
- if careerType == nil then
- careerType = self.last.careerType
- end
- if filterLevel == nil then
- filterLevel = self.last.filterLevel
- end
- if filterQuality == nil then
- filterQuality = self.last.filterQuality
- end
- end
- self.last = { type = type, subType = subType, sortType = sortType, careerType = careerType, filterLevel = filterLevel, filterQuality = filterQuality }
- SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_GET_TRADE_GOODS, { type, subType, sortType, careerType, filterLevel, filterQuality })
- end
- function this:Tick()
- local refresh = false
- for i, v in pairs(self.goodsItems) do
- refresh = refresh or v:Tick()
- end
- if refresh then
- self:RequestRefreshGoodsList()
- end
- end
- return this
|