KLTradeCommonGoodsPanel.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ---@class KLTradeCommonGoodsPanel:UIKmlLuaPanelBase
  2. ---@field view KLTradeCommonGoodsPanelView
  3. local KLTradeCommonGoodsPanel = class(UIKmlLuaPanelBase)
  4. local this = KLTradeCommonGoodsPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. --初始化商品列表配置
  8. GUI:DataListInitData(self.view.datalist_goods, function()
  9. return self:ItemCountFunc()
  10. end, function(realIndex)
  11. return self:ItemGetFunc(realIndex)
  12. end, nil, function(realIndex, kmlCtrl)
  13. return self:ItemUpdateFunc(realIndex, kmlCtrl)
  14. end)
  15. ---@type table<UIKmlLuaControl,KLTradeGoodsItem>
  16. self.goodsItems = {}
  17. self.goodsItemDataList = {}
  18. self.tickTimer = SL:Schedule(self.tickTimer, 0, 1, -1, function()
  19. return self:Tick()
  20. end)
  21. end
  22. function this:ItemCountFunc()
  23. return #self.goodsItemDataList
  24. end
  25. function this:ItemGetFunc(realIndex)
  26. ---@type KLTradeGoodsItem
  27. local item = GUI:UIPanel_Open("dev/outui/Trade/Item/KLTradeGoods/KLTradeGoodsItem", self.view.datalist_goods, self, nil, true)
  28. self.goodsItems[item.view.root] = item
  29. return item.view.root
  30. end
  31. function this:ItemUpdateFunc(realIndex, kmlCtrl)
  32. local data = self.goodsItemDataList[realIndex + 1]
  33. local item = self.goodsItems[kmlCtrl]
  34. item:UpdateData(data)
  35. end
  36. ---注册UI事件和服务器消息
  37. function this:RegistEvents()
  38. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_GET_TRADE_GOODS, self.RES_GET_TRADE_GOODS, self)
  39. end
  40. function this:RES_GET_TRADE_GOODS(_, message)
  41. if not message then
  42. return
  43. end
  44. local type = 0
  45. table.clear(self.goodsItemDataList)
  46. local tempMessage = {}
  47. for k, v in pairs(message) do
  48. tempMessage[tonumber(k)] = v
  49. end
  50. for k, v in pairs(tempMessage) do
  51. local stallTbl = SL:GetConfig("cfg_stall", v.itemcfgid)
  52. if stallTbl and stallTbl.type ~= 1 and stallTbl.type ~= 5 then ---月卡时间和奇迹币类型不在这里显示
  53. table.insert(self.goodsItemDataList, v)
  54. end
  55. end
  56. GUI:DataListUpdateData(self.view.datalist_goods)
  57. end
  58. ---创建或者刷新界面数据时调用
  59. function this:Refresh()
  60. end
  61. function this:Close()
  62. SL:UnSchedule(self.tickTimer)
  63. table.clear(self.goodsItemDataList)
  64. GUI:DataListUpdateData(self.view.datalist_goods)
  65. end
  66. function this:RequestRefreshGoodsList(type, subType, sortType, careerType, filterLevel, filterQuality)
  67. if self.last then
  68. if type == nil then
  69. type = self.last.type
  70. end
  71. if subType == nil then
  72. subType = self.last.subType
  73. end
  74. if sortType == nil then
  75. sortType = self.last.sortType
  76. end
  77. if careerType == nil then
  78. careerType = self.last.careerType
  79. end
  80. if filterLevel == nil then
  81. filterLevel = self.last.filterLevel
  82. end
  83. if filterQuality == nil then
  84. filterQuality = self.last.filterQuality
  85. end
  86. end
  87. self.last = { type = type, subType = subType, sortType = sortType, careerType = careerType, filterLevel = filterLevel, filterQuality = filterQuality }
  88. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_GET_TRADE_GOODS, { type, subType, sortType, careerType, filterLevel, filterQuality })
  89. end
  90. function this:Tick()
  91. local refresh = false
  92. for i, v in pairs(self.goodsItems) do
  93. refresh = refresh or v:Tick()
  94. end
  95. if refresh then
  96. self:RequestRefreshGoodsList()
  97. end
  98. end
  99. return this