KLTradeCrossServerGoodsPanel.lua 3.1 KB

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