KLTradeUnionGoodsPanel.lua 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. ---@class KLTradeUnionGoodsPanel:UIKmlLuaPanelBase
  2. ---@field view KLTradeUnionGoodsPanelView
  3. local KLTradeUnionGoodsPanel = class(UIKmlLuaPanelBase)
  4. local this = KLTradeUnionGoodsPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. GUI:OSAScrollView_Initialized(self.view.osa_scrollview_union_goods, self.UnionGoodsGetFun, self.UnionGoodsUpdateFun, self)
  8. self.goodsListData = {}
  9. self.refreshTimer = SL:Schedule(self.refreshTimer, 0, 3, -1, function()
  10. return self:RequestCurRefreshGoodsList()
  11. end)
  12. ---@type KLTradeUnionGoodsItem[]
  13. self.tradeUnionGoodsItems = {}
  14. self.tickTimer = SL:Schedule(self.tickTimer, 0, 1, -1, function()
  15. return self:Tick()
  16. end)
  17. end
  18. function this:UnionGoodsGetFun()
  19. local item = GUI:UIPanel_Open("dev/outui/Trade/Item/KLTradeUnionGoods/KLTradeUnionGoodsItem", nil, self, nil, true)
  20. table.insert(self.tradeUnionGoodsItems, item)
  21. return item
  22. end
  23. ---@param item KLTradeUnionGoodsItem
  24. function this:UnionGoodsUpdateFun(item, index)
  25. local data = self.goodsListData[index + 1]
  26. item:SetData(data)
  27. end
  28. ---注册UI事件和服务器消息
  29. function this:RegistEvents()
  30. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_WAR_ALLIANCE_AUCTION_GOODS, self.RES_WAR_ALLIANCE_AUCTION_GOODS, self)
  31. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_WAR_ALLIANCE_OPT_INFO, self.RequestCurRefreshGoodsList, self)
  32. end
  33. function this:RES_WAR_ALLIANCE_AUCTION_GOODS(_, message)
  34. table.clear(self.goodsListData)
  35. if next(message) then
  36. for k, v in pairs(message) do
  37. self.goodsListData[tonumber(k)] = v
  38. end
  39. end
  40. GUI:OSAScrollView_RefreshList(self.view.osa_scrollview_union_goods, #self.goodsListData)
  41. end
  42. ---创建或者刷新界面数据时调用
  43. function this:Refresh()
  44. end
  45. function this:Close()
  46. SL:UnSchedule(self.refreshTimer)
  47. SL:UnSchedule(self.tickTimer)
  48. end
  49. function this:RequestRefreshGoodsList(type, subType, sortType, careerType, filterLevel, filterQuality)
  50. self.currentType = type
  51. self.currentSubType = subType
  52. self.currentSortType = sortType
  53. self.currentCareerType = careerType
  54. self.currentFilterLevel = filterLevel
  55. self.currentFilterQuality = filterQuality
  56. self:RequestCurRefreshGoodsList()
  57. end
  58. function this:RequestCurRefreshGoodsList()
  59. if not self.currentCareerType then
  60. return
  61. end
  62. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_WAR_ALLIANCE_UPDATE_GOODS, { self.currentType, self.currentSubType, self.currentSortType, self.currentCareerType, self.currentFilterLevel, self.currentFilterQuality })
  63. end
  64. function this:Tick()
  65. local refresh
  66. local items = GUI:OSAScrollView_GetAllItems(self.view.osa_scrollview_union_goods)
  67. for i = 0, items.Count - 1 do
  68. local item = items[i]
  69. local expireData = item:Tick()
  70. if expireData then
  71. refresh = true
  72. table.removeByValue(self.goodsListData, expireData)
  73. end
  74. end
  75. if refresh then
  76. GUI:OSAScrollView_RefreshList(self.view.osa_scrollview_union_goods, #self.goodsListData)
  77. end
  78. end
  79. return this