KLUIBagTileScrollViewItem.lua 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. ---@class KLUIBagTileScrollViewItem:UIKmlLuaPanelBase
  2. ---@field view KLUIBagTileScrollViewItemView
  3. ---@field itemList CommonProtos.Item[]
  4. ---@field indexToItem table<number,KLBagItemItem>
  5. local KLUIBagTileScrollViewItem = class(UIKmlLuaPanelBase)
  6. local this = KLUIBagTileScrollViewItem
  7. this.idToIns = {}
  8. ---创建时调用一次
  9. function KLUIBagTileScrollViewItem:Init()
  10. if not self.args then
  11. self.args = {}
  12. end
  13. self.hor = self.args.hor or 25
  14. self.vet = self.args.vet or 8
  15. self.itemList = self.args.itemList or {}
  16. self.page = self.args.page or 1
  17. if self.args.forbidCount and self.args.forbidCount > 0 then
  18. self.forbidCount = self.args.forbidCount
  19. else
  20. self.forbidCount = 0
  21. end
  22. self.id = self.args.id or EBagTileScrollViewId.Bag
  23. self.forbidClickCallback = self.args.forbidClickCallback
  24. self.dragEndCallback = self.args.dragEndCallback
  25. self.parent = self.args.parent
  26. self.itemClick = self.args.itemClick
  27. self.indexToItem = {}
  28. self.indexToForbidGrid = {}
  29. self.indexForbidList = {}
  30. self.selectList = self.args.selectList or {}
  31. ---是否显示选中特效(外置)
  32. self.isShowEffect = self.args.isShowEffect or false
  33. if self.args.JumpSelectId then
  34. self.jumpCfgId = self.args.JumpSelectId
  35. end
  36. if this.idToIns[self.id] == nil then
  37. this.idToIns[self.id] = self
  38. end
  39. end
  40. ---创建或者刷新界面数据时调用
  41. function KLUIBagTileScrollViewItem:Refresh()
  42. local x = self.args.x or 0
  43. local y = self.args.y or 0
  44. GUI:setPosition(self.view.root, x, y)
  45. local height = self.hor * 45
  46. local width = self.vet * 45
  47. GUI:setContentSize(self.view.BagTileScrollViewPrefab, 365, 534)
  48. GUI:setPosition(self.view.BagTileScrollViewPrefab, 36, -91)
  49. GUI:setContentSize(self.view.prefabBagTileScrollView_, 365, 534)
  50. GUI:setContentSize(self.view.BagTileContent, width, height)
  51. self:RefreshItem()
  52. self:RefreshForbidGrid(self.forbidCount)
  53. end
  54. ---注册UI事件和服务器消息
  55. function KLUIBagTileScrollViewItem:RegistEvents()
  56. SL:RegisterLUAEvent(LUA_EVENT_TIPS_PANEL_CLOSE, self.LUA_EVENT_TIPS_PANEL_CLOSE, self)
  57. end
  58. function KLUIBagTileScrollViewItem:LUA_EVENT_TIPS_PANEL_CLOSE()
  59. self:NoSelectItem()
  60. end
  61. function KLUIBagTileScrollViewItem:Close()
  62. for id, ins in pairs(this.idToIns) do
  63. if ins == self then
  64. this.idToIns[id] = nil
  65. end
  66. end
  67. if self.co then
  68. Coroutine.Stop(self.co)
  69. self.co = nil
  70. end
  71. end
  72. function KLUIBagTileScrollViewItem:RefreshItem(callBack,callBackUI)
  73. local canDrag = true
  74. if self.args and self.args.canDrag ~= nil then
  75. canDrag = self.args.canDrag
  76. end
  77. --local item = GUI:UIPanel_Open("dev/ui/Common/Item/KLBagItem/KLBagItemItem",self.view.BagTileContent,self,{x=0, y=0},true)
  78. self.co = Coroutine.Start(function()
  79. local count = 0
  80. for index, item in pairs(self.itemList) do
  81. count = count + 1
  82. if (count%3==0) then Coroutine.WaitForEndOfFrame() end
  83. local hor, vet = this.GetHorAndVetWithInt(index)
  84. GUI:UIPanel_Open("dev/ui/Common/Item/KLBagItem/KLBagItemItem", self.view.BagTileContent, self,
  85. {
  86. BagTileScrollViewId = self.id,
  87. item = item,
  88. x = (vet - 1) * 45,
  89. y = (hor - 1) * -45,
  90. z = -100,
  91. canDrag = canDrag,
  92. beginDrag = self.beginDrag,
  93. onDrag = self.onDrag,
  94. endDrag = self.endDrag,
  95. ins = self,
  96. index = index,
  97. click = self.itemClick,
  98. isSelect = self.selectList[item.id],
  99. callBackUI = self.args.callBackUI,
  100. isShowEffect = self.args.isShowEffect
  101. }, true,
  102. function(bagItem)
  103. self.indexToItem[index] = bagItem
  104. end)
  105. end
  106. if callBack then
  107. if callBackUI then
  108. callBack(callBackUI)
  109. else
  110. callBack()
  111. end
  112. end
  113. if self.jumpCfgId then
  114. self:SelectItem(self.jumpCfgId)
  115. end
  116. end)
  117. end
  118. -- 刷新道具列表
  119. function this:RefreshItemByItem(itemList,refreshItemCallback,refreshItemCallbackUI)
  120. self.itemList = itemList
  121. self:RefreshItem(refreshItemCallback,refreshItemCallbackUI)
  122. end
  123. -- 刷新道具信息
  124. function this:RefreshInfo()
  125. for index, klBagItem in pairs(self.indexToItem) do
  126. klBagItem:RefreshInfo()
  127. end
  128. end
  129. --根据number获取物品所在的行和列
  130. function this.GetHorAndVetWithInt(number)
  131. return number // 100, number % 100
  132. end
  133. -- 道具拖拽中
  134. function this:onDrag(eventData, systemData)
  135. -- 如果没在拖拽装备图素,则移动滑动条
  136. if eventData.dragItem == false then
  137. self:MoveScrollView(Time.deltaTime * 80 * systemData.delta.y)
  138. return
  139. end
  140. -- 如果拖到了滑动条上下方区域 滑动条自动上下
  141. self:JudgeMoveScrollView(systemData)
  142. -- 判断占位情况
  143. self:JudgeMoveUseGrid(eventData, systemData)
  144. end
  145. local redGridList
  146. local storageRedGridList
  147. local blueGridList
  148. local storageBlueGridList
  149. function this:JudgeMoveUseGrid(eventData, systemData)
  150. redGridList = {}
  151. blueGridList = {}
  152. storageRedGridList = {}
  153. storageBlueGridList = {}
  154. ---@type KLBagItemItem
  155. local dragItem = eventData.temp
  156. local bagTileScrollView = this.idToIns[EBagTileScrollViewId.Bag]
  157. if bagTileScrollView then
  158. local bool, pos = GUI:ScreenPointToLocalPointInRectangle(bagTileScrollView.view.BagTileContent, systemData["position"])
  159. local vet = pos.x // 45 + 1
  160. local hor = -pos.y // 45 + 1
  161. local holdGrid = SL:GetConfig('cfg_item', dragItem.item.cfgId).holdGrid
  162. local holdHor = holdGrid[1]
  163. local holdVet = holdGrid[2]
  164. local startVet = vet - (holdHor - 1) // 2
  165. local startHor = hor - (holdVet - 1) // 2
  166. local maxHor, maxVet = SL:GetMetaValue(EMetaVarGetKey.GET_BAG_MAX_HOR_VERT)
  167. local useGridTable = SL:GetMetaValue(EMetaVarGetKey.GET_BAG_USE_GRID_TABLE)
  168. local useTable = useGridTable[1]
  169. local index = dragItem.index
  170. local itemHor, itemVet = this.GetHorAndVetWithInt(index)
  171. -- 在背包里
  172. if hor > 0 and vet > 0 and hor <= maxHor and vet <= maxVet then
  173. -- 边界情况
  174. if startHor <= 0 or startHor + holdVet - 1 > maxHor or startVet <= 0 or startVet + holdHor - 1 > maxVet then
  175. for nowHor = startHor, startHor + holdVet - 1 do
  176. for nowVet = startVet, startVet + holdHor - 1 do
  177. table.insert(redGridList, this.GetIntWithHorAndVet(nowHor, nowVet))
  178. end
  179. end
  180. -- 通常情况
  181. else
  182. for nowHor = startHor, startHor + holdVet - 1 do
  183. for nowVet = startVet, startVet + holdHor - 1 do
  184. if useTable[this.GetIntWithHorAndVet(nowHor, nowVet)] == true then
  185. -- 还要排除下移动到拖拽的几个格子是红色的情况
  186. if nowHor < itemHor or nowHor > itemHor + holdVet - 1 or nowVet < itemVet or nowVet > itemVet + holdHor - 1 then
  187. table.insert(redGridList, this.GetIntWithHorAndVet(nowHor, nowVet))
  188. else
  189. table.insert(blueGridList, this.GetIntWithHorAndVet(nowHor, nowVet))
  190. end
  191. else
  192. table.insert(blueGridList, this.GetIntWithHorAndVet(nowHor, nowVet))
  193. end
  194. end
  195. end
  196. end
  197. end
  198. GUI:DataListInitData(bagTileScrollView.view.red_grid_, function()
  199. return table.count(redGridList)
  200. end, function()
  201. end, function(realIndex)
  202. end, function(realIndex)
  203. local root = GUI:GetChildControl(bagTileScrollView.view.red_grid_, realIndex, 'red_grid_item')
  204. local index = redGridList[realIndex + 1]
  205. local rootRectTransform = GUI:GetRectTransform(root)
  206. rootRectTransform.anchoredPosition = Vector2((index % 100 - 1) * 45, -(index // 100 - 1) * 45)
  207. rootRectTransform:SetAsLastSibling()
  208. end)
  209. GUI:DataListUpdateData(bagTileScrollView.view.red_grid_)
  210. GUI:DataListInitData(bagTileScrollView.view.green_grid_, function()
  211. return table.count(blueGridList)
  212. end, function()
  213. end, function(realIndex)
  214. end, function(realIndex)
  215. local root = GUI:GetChildControl(bagTileScrollView.view.green_grid_, realIndex, 'green_grid_item')
  216. local index = blueGridList[realIndex + 1]
  217. local rootRectTransform = GUI:GetRectTransform(root)
  218. rootRectTransform.anchoredPosition = Vector2((index % 100 - 1) * 45, -(index // 100 - 1) * 45)
  219. rootRectTransform:SetAsLastSibling()
  220. end)
  221. GUI:DataListUpdateData(bagTileScrollView.view.green_grid_)
  222. end
  223. local storageTileScrollView = this.idToIns[EBagTileScrollViewId.Storage]
  224. if storageTileScrollView then
  225. local bool, pos = GUI:ScreenPointToLocalPointInRectangle(storageTileScrollView.view.BagTileContent, systemData["position"])
  226. local vet = pos.x // 45 + 1
  227. local hor = -pos.y // 45 + 1
  228. local holdGrid = SL:GetConfig('cfg_item', dragItem.item.cfgId).holdGrid
  229. local holdHor = holdGrid[1]
  230. local holdVet = holdGrid[2]
  231. local startVet = vet - (holdHor - 1) // 2
  232. local startHor = hor - (holdVet - 1) // 2
  233. local maxHor, maxVet = SL:GetMetaValue(EMetaVarGetKey.GET_STORE_HOUSE_MAX_HV)
  234. local useTable
  235. ---@type KLDepotsPanel
  236. local panel = GUI:GetUI("dev/ui/Bag/Panel/KLDepots/KLDepotsPanel")
  237. local useGridTable = SL:GetMetaValue(EMetaVarGetKey.GET_STORE_HOUSE_USE_GRID_TABLE)
  238. if panel.bagType == "privilege" then
  239. useTable = useGridTable[panel.CurPage + panel.maxDepotsPages]
  240. else
  241. useTable = useGridTable[panel.CurPage]
  242. end
  243. if useTable == nil then
  244. useTable = {}
  245. end
  246. local index = dragItem.index
  247. local itemHor, itemVet = this.GetHorAndVetWithInt(index)
  248. -- 在仓库里
  249. if hor > 0 and vet > 0 and hor <= maxHor and vet <= maxVet then
  250. -- 边界情况
  251. if startHor <= 0 or startHor + holdVet - 1 > maxHor or startVet <= 0 or startVet + holdHor - 1 > maxVet then
  252. for nowHor = startHor, startHor + holdVet - 1 do
  253. for nowVet = startVet, startVet + holdHor - 1 do
  254. table.insert(storageRedGridList, this.GetIntWithHorAndVet(nowHor, nowVet))
  255. end
  256. end
  257. -- 通常情况
  258. else
  259. for nowHor = startHor, startHor + holdVet - 1 do
  260. for nowVet = startVet, startVet + holdHor - 1 do
  261. if useTable[this.GetIntWithHorAndVet(nowHor, nowVet)] == true then
  262. -- 还要排除下移动到拖拽的几个格子是红色的情况
  263. if nowHor < itemHor or nowHor > itemHor + holdVet - 1 or nowVet < itemVet or nowVet > itemVet + holdHor - 1 then
  264. table.insert(storageRedGridList, this.GetIntWithHorAndVet(nowHor, nowVet))
  265. else
  266. table.insert(storageBlueGridList, this.GetIntWithHorAndVet(nowHor, nowVet))
  267. end
  268. else
  269. table.insert(storageBlueGridList, this.GetIntWithHorAndVet(nowHor, nowVet))
  270. end
  271. end
  272. end
  273. end
  274. end
  275. GUI:DataListInitData(storageTileScrollView.view.red_grid_, function()
  276. return table.count(storageRedGridList)
  277. end, function()
  278. end, function(realIndex)
  279. end, function(realIndex)
  280. local root = GUI:GetChildControl(storageTileScrollView.view.red_grid_, realIndex, 'red_grid_item')
  281. local index = storageRedGridList[realIndex + 1]
  282. local rootRectTransform = GUI:GetRectTransform(root)
  283. rootRectTransform.anchoredPosition = Vector2((index % 100 - 1) * 45, -(index // 100 - 1) * 45)
  284. rootRectTransform:SetAsLastSibling()
  285. end)
  286. GUI:DataListUpdateData(storageTileScrollView.view.red_grid_)
  287. GUI:DataListInitData(storageTileScrollView.view.green_grid_, function()
  288. return table.count(storageBlueGridList)
  289. end, function()
  290. end, function(realIndex)
  291. end, function(realIndex)
  292. local root = GUI:GetChildControl(storageTileScrollView.view.green_grid_, realIndex, 'green_grid_item')
  293. local index = storageBlueGridList[realIndex + 1]
  294. local rootRectTransform = GUI:GetRectTransform(root)
  295. rootRectTransform.anchoredPosition = Vector2((index % 100 - 1) * 45, -(index // 100 - 1) * 45)
  296. rootRectTransform:SetAsLastSibling()
  297. end)
  298. GUI:DataListUpdateData(storageTileScrollView.view.green_grid_)
  299. end
  300. end
  301. --根据行列获取number
  302. -- hor=5, vet=4 返回504
  303. -- hor=14, vet=3 返回1403
  304. ---@public
  305. function this.GetIntWithHorAndVet(hor, vet)
  306. return hor * 100 + vet
  307. end
  308. this.InsToCo = {}
  309. function this:JudgeMoveScrollView(systemData)
  310. for _, bagTileIns in pairs(this.idToIns) do
  311. local rectTransform = GUI:GetRectTransform(bagTileIns.view.prefabBagTileScrollView_)
  312. local width = rectTransform.rect.width
  313. local height = rectTransform.rect.height
  314. local bool, pos = GUI:ScreenPointToLocalPointInRectangle(bagTileIns.view.prefabBagTileScrollView_, systemData["position"])
  315. if pos.x > 0 and pos.x < width then
  316. if pos.y > -45 then
  317. if this.InsToCo[bagTileIns] == nil then
  318. this.InsToCo[bagTileIns] = Coroutine.Start(
  319. function()
  320. while (true) do
  321. Coroutine.WaitForEndOfFrame()
  322. bagTileIns:MoveScrollView(Time.deltaTime * -150)
  323. end
  324. end
  325. )
  326. end
  327. elseif pos.y < -height + 45 then
  328. if this.InsToCo[bagTileIns] == nil then
  329. this.InsToCo[bagTileIns] = Coroutine.Start(
  330. function()
  331. while (true) do
  332. Coroutine.WaitForEndOfFrame()
  333. bagTileIns:MoveScrollView(Time.deltaTime * 150)
  334. end
  335. end
  336. )
  337. end
  338. else
  339. if this.InsToCo[bagTileIns] ~= nil then
  340. Coroutine.Stop(this.InsToCo[bagTileIns])
  341. this.InsToCo[bagTileIns] = nil
  342. end
  343. end
  344. else
  345. if this.InsToCo[bagTileIns] ~= nil then
  346. Coroutine.Stop(this.InsToCo[bagTileIns])
  347. this.InsToCo[bagTileIns] = nil
  348. end
  349. end
  350. end
  351. end
  352. function this:MoveScrollView(moveDelta)
  353. local position = GUI:GetRectTransform(self.view.BagTileContent).anchoredPosition
  354. position.y = position.y + moveDelta
  355. GUI:GetRectTransform(self.view.BagTileContent).anchoredPosition = position
  356. end
  357. function this:beginDrag()
  358. end
  359. function this:endDrag(eventData, systemData)
  360. if self.dragEndCallback then
  361. local mousePosition = systemData["position"]
  362. ---@type KLBagItemItem
  363. local dragItem = eventData.dragItem
  364. local panel = GUI:GetUI("dev/ui/Bag/Panel/KLUIBag/KLUIBagPanel")
  365. if panel then
  366. local bool, pos = GUI:ScreenPointToLocalPointInRectangle(panel.bagTileScrollView.view.BagTileContent, mousePosition)
  367. local vet = pos.x // 45 + 1
  368. local hor = -pos.y // 45 + 1
  369. local holdGrid = SL:GetConfig('cfg_item', dragItem.item.cfgId).holdGrid
  370. local holdHor = holdGrid[1]
  371. local holdVet = holdGrid[2]
  372. vet = vet - (holdHor - 1) // 2
  373. hor = hor - (holdVet - 1) // 2
  374. local storageScrollView = this.idToIns[EBagTileScrollViewId.Storage]
  375. local storageVet, storageHor
  376. if storageScrollView then
  377. bool, pos = GUI:ScreenPointToLocalPointInRectangle(storageScrollView.view.BagTileContent, mousePosition)
  378. storageVet = pos.x // 45 + 1
  379. storageHor = -pos.y // 45 + 1
  380. holdGrid = SL:GetConfig('cfg_item', dragItem.item.cfgId).holdGrid
  381. holdHor = holdGrid[1]
  382. holdVet = holdGrid[2]
  383. storageVet = storageVet - (holdHor - 1) // 2
  384. storageHor = storageHor - (holdVet - 1) // 2
  385. end
  386. self.dragEndCallback(self.parent, { dragItem = dragItem, bagPutHor = hor, bagPutVet = vet, storageHor = storageHor, storageVet = storageVet, index = eventData.index, raycastObj = eventData.raycastObj })
  387. end
  388. end
  389. for _, co in pairs(this.InsToCo) do
  390. Coroutine.Stop(co)
  391. this.InsToCo[_] = nil
  392. end
  393. local bagTileScrollView = this.idToIns[EBagTileScrollViewId.Bag]
  394. if bagTileScrollView then
  395. redGridList = {}
  396. blueGridList = {}
  397. GUI:DataListUpdateData(bagTileScrollView.view.red_grid_)
  398. GUI:DataListUpdateData(bagTileScrollView.view.green_grid_)
  399. end
  400. local storageTileScrollView = this.idToIns[EBagTileScrollViewId.Storage]
  401. if storageTileScrollView then
  402. storageRedGridList = {}
  403. storageBlueGridList = {}
  404. GUI:DataListUpdateData(storageTileScrollView.view.red_grid_)
  405. GUI:DataListUpdateData(storageTileScrollView.view.green_grid_)
  406. end
  407. end
  408. ---刷新选中
  409. ---@param data table<number,boolean>
  410. function this:RefreshSelect(data)
  411. for k, v in pairs(self.indexToItem) do
  412. if self.isShowEffect then
  413. v:SetSelectEffect(data[v.item.id],true)
  414. else
  415. GUI:setVisible(v.view.selectImg, data[v.item.id])
  416. GUI:setVisible(v.view.selectTagImg, data[v.item.id])
  417. end
  418. end
  419. end
  420. -- 选中cfgId的物体
  421. function this:SelectItem(cfgId)
  422. self.jumpCfgId = cfgId
  423. for k, v in pairs(self.indexToItem) do
  424. if cfgId == v.item.cfgId then
  425. local index = v.index
  426. local hor = index // 100
  427. GUI:setPosition(self.view.BagTileContent, 0, (hor-1)*45)
  428. GUI:setVisible(v.view.selectImg, true)
  429. SL:OpenTips("bag",cfgId, v.item.id)
  430. return
  431. end
  432. end
  433. end
  434. ---取消选中cfgId的物体
  435. function this:NoSelectItem()
  436. if self.jumpCfgId then
  437. for k, v in pairs(self.indexToItem) do
  438. if self.jumpCfgId == v.item.cfgId then
  439. GUI:setVisible(v.view.selectImg, false)
  440. return
  441. end
  442. end
  443. end
  444. end
  445. -- 刷新禁用格子
  446. function this:RefreshForbidGrid(count)
  447. self.indexForbidList = {}
  448. self.forbidCount = count
  449. local remainCount = count
  450. for nowHor = self.hor, 1, -1 do
  451. for nowVet = self.vet, 1, -1 do
  452. if remainCount == 0 then
  453. break
  454. end
  455. remainCount = remainCount - 1
  456. table.insert(self.indexForbidList, nowHor * 100 + nowVet)
  457. end
  458. end
  459. GUI:DataListInitData(self.view.forbid_list_, function()
  460. return table.count(self.indexForbidList)
  461. end, function()
  462. end,
  463. function()
  464. end,
  465. function(realIndex)
  466. local index = self.indexForbidList[realIndex + 1]
  467. local hor = index // 100
  468. local vet = index % 100
  469. local forbid_prefab = GUI:GetChildControl(self.view.forbid_list_, realIndex, 'forbid_item')
  470. GUI:setPosition(forbid_prefab, (vet - 1) * 45, (hor - 1) * -45)
  471. --local forbid_btn = GUI:GetChildControl(self.view.forbid_list_, realIndex, 'UIBagForbidButton')
  472. if self.forbidClickCallback then
  473. GUI:AddOnClickEvent(forbid_prefab, self.parent, self.forbidClickCallback, { index = index })
  474. end
  475. end)
  476. GUI:DataListUpdateData(self.view.forbid_list_)
  477. end
  478. function this:RefreshRedGrid(count)
  479. self.indexRedList = {}
  480. --self.redCount = count + self.forbidCount
  481. local index = 0
  482. local remainCount = count + self.forbidCount
  483. for nowHor = self.hor, 1, -1 do
  484. for nowVet = self.vet, 1, -1 do
  485. index = index + 1
  486. if remainCount == 0 then
  487. break
  488. end
  489. remainCount = remainCount - 1
  490. if index > self.forbidCount then
  491. table.insert(self.indexRedList, nowHor * 100 + nowVet)
  492. end
  493. end
  494. end
  495. GUI:DataListInitData(self.view.red_list_, function()
  496. return table.count(self.indexRedList)
  497. end, function()
  498. end,
  499. function()
  500. end,
  501. function(realIndex)
  502. local index = self.indexRedList[realIndex + 1]
  503. local hor = index // 100
  504. local vet = index % 100
  505. local red_prefab = GUI:GetChildControl(self.view.red_list_, realIndex, 'red_item')
  506. GUI:setPosition(red_prefab, (vet - 1) * 45, (hor - 1) * -45)
  507. end)
  508. GUI:DataListUpdateData(self.view.red_list_)
  509. end
  510. ---@return KLBagItemItem[]
  511. function this:Item_Change(eventData)
  512. local ksItemList = {}
  513. local addItemList = eventData
  514. for i, itemInfo in pairs(eventData) do
  515. if itemInfo.item == nil then
  516. local index = itemInfo.index % 10000
  517. local bagItem = self.indexToItem[index]
  518. GUI:UIPanel_Close(nil, bagItem)
  519. self.indexToItem[index] = nil
  520. addItemList[i] = nil
  521. end
  522. end
  523. for _, itemInfo in pairs(addItemList) do
  524. local index = itemInfo.index % 10000
  525. local item = itemInfo.item
  526. if self.indexToItem[index] then
  527. local bagItem = self.indexToItem[index]
  528. bagItem:SetItem(itemInfo.item)
  529. else
  530. local canDrag = true
  531. if self.args and self.args.canDrag ~= nil then
  532. canDrag = self.args.canDrag
  533. end
  534. local hor, vet = this.GetHorAndVetWithInt(index)
  535. GUI:UIPanel_Open("dev/ui/Common/Item/KLBagItem/KLBagItemItem", self.view.BagTileContent, self,
  536. { item = item,
  537. x = (vet - 1) * 45,
  538. y = (hor - 1) * -45,
  539. z = -100,
  540. canDrag = canDrag,
  541. beginDrag = self.beginDrag,
  542. onDrag = self.onDrag,
  543. endDrag = self.endDrag,
  544. ins = self,
  545. index = index,
  546. click = self.itemClick,
  547. callBackUI = self.args.callBackUI,
  548. isShowEffect = self.args.isShowEffect
  549. }, true,function(bagItem)
  550. self.indexToItem[index] = bagItem
  551. table.insert(ksItemList, bagItem)
  552. end)
  553. end
  554. end
  555. return ksItemList
  556. end
  557. ----清除页面item
  558. function this:ClearBagItem()
  559. if self.co then
  560. Coroutine.Stop(self.co)
  561. self.co = nil
  562. end
  563. if self.indexToItem then
  564. for index, v in pairs(self.indexToItem) do
  565. GUI:UIPanel_Close(nil, v)
  566. self.indexToItem[index] = nil
  567. end
  568. end
  569. end
  570. function this:ResetPos()
  571. GUI:setPosition(self.view.BagTileContent, 0, 0)
  572. end
  573. return KLUIBagTileScrollViewItem