KLFusionBagPanel.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. ---@class KLFusionBagPanel:UIKmlLuaPanelBase
  2. ---@field view KLFusionBagPanelView
  3. local KLFusionBagPanel = class(UIKmlLuaPanelBase)
  4. local this = KLFusionBagPanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. self:InitData(self.args)
  10. local bag_info = string.split(SL:GetConfig("cfg_global", 6).value, '#')
  11. self.maxHor = tonumber(bag_info[1]) + 20
  12. self.maxVet = tonumber(bag_info[2])
  13. GUI:UIPanel_Open("dev/ui/Common/Item/KLUIBagTileScrollView/KLUIBagTileScrollViewItem", self.view.root, self,
  14. {
  15. hor = self.maxHor,
  16. vet = self.maxVet,
  17. canDrag = false,
  18. forbidClickCallback = self.forbidClick,
  19. itemClick = self.args and self.args.itemClick,
  20. selectList = {},
  21. callBackUI = self.args and self.args.callBackUI,
  22. isShowEffect = true
  23. }, false, function(bagTileScrollView)
  24. ---@type KLUIBagTileScrollViewItem
  25. self.bagTileScrollView = bagTileScrollView
  26. if self.itemList then
  27. self.bagTileScrollView:ClearBagItem()
  28. self.bagTileScrollView:RefreshItemByItem(self.itemList)
  29. self.itemList = nil
  30. end
  31. end)
  32. end
  33. ---初始化数据
  34. function this:InitData(data)
  35. self.x = (data and data.x) or 0
  36. self.y = (data and data.y) or 0
  37. end
  38. ---注册UI事件和服务器消息
  39. function this:RegistEvents()
  40. GUI:AddOnClickEvent(self.view.closeBtn, self, self.ClosePanel)
  41. GUI:AddOnClickEvent(self.view.person_shop_btn, self, self.personBtn)
  42. GUI:AddOnClickEvent(self.view.storage_btn, self, self.personBtn)
  43. GUI:AddOnClickEvent(self.view.recycle_btn, self, self.personBtn)
  44. GUI:AddOnClickEvent(self.view.tidy_btn, self, self.personBtn)
  45. end
  46. ---界面显示时调用一次
  47. function this:Show()
  48. end
  49. ---创建或者刷新界面数据时调用
  50. function this:Refresh()
  51. local x = self.x
  52. local y = self.y
  53. GUI:setPosition(self.view.root, x, y)
  54. end
  55. function this:RefreshItem(itemlist)
  56. if self.bagTileScrollView and itemlist then
  57. itemlist = self:SortItemList(itemlist)
  58. self.bagTileScrollView:ClearBagItem()
  59. self.bagTileScrollView:RefreshItemByItem(itemlist)
  60. self.itemList = nil
  61. else
  62. self.itemList = self:SortItemList(itemlist)
  63. end
  64. end
  65. function this:RefreshGrailSelect(itemList)
  66. self.bagTileScrollView:RefreshSelect(itemList)
  67. end
  68. function this:personBtn()
  69. SL:TipMessage(SL:GetConfig('cfg_string', 286).text, 1, NoticeType.NoticeLeftBottom) --"锻造中无法使用",
  70. end
  71. function this:Hide()
  72. end
  73. function this:ClosePanel()
  74. self.args.callBackUI:ClosePanel()
  75. end
  76. function this:Close()
  77. end
  78. ---@param itemList CommonProtos.Item[]
  79. ---@return CommonProtos.Item[]
  80. function this:SortItemList(itemList)
  81. local bag_str = SL:GetConfig("cfg_global", 6).value
  82. local bag_tbl = string.split(bag_str, '#')
  83. local bag_hor = tonumber(bag_tbl[1])
  84. local bag_vet = tonumber(bag_tbl[2])
  85. local use_cell_dict = {}
  86. local sortItemList = {}
  87. local cfg_id, now_hor, now_vet, is_put, hold_vet, hole_hor, item, now_hold_hor, now_judge_hor, now_hold_vet, now_judge_vet, now_cell_index
  88. local max_hor = bag_hor + 20
  89. for _, v in pairs(itemList) do
  90. cfg_id = v.cfgId
  91. now_hor = 1
  92. while now_hor <= max_hor do
  93. now_vet = 1
  94. while now_vet <= bag_vet do
  95. is_put = true
  96. ---@type cfg_item_column
  97. item = SL:GetConfig("cfg_item", cfg_id)
  98. hold_vet = item.holdGrid[1]
  99. hole_hor = item.holdGrid[2]
  100. now_hold_hor = 0
  101. while now_hold_hor < hole_hor do
  102. now_judge_hor = now_hor + now_hold_hor
  103. now_hold_vet = 0
  104. while now_hold_vet < hold_vet do
  105. now_judge_vet = now_vet + now_hold_vet
  106. now_cell_index = now_judge_hor * 100 + now_judge_vet
  107. if use_cell_dict[now_cell_index] or now_judge_vet > bag_vet then
  108. is_put = false
  109. break
  110. end
  111. now_hold_vet = now_hold_vet + 1
  112. end
  113. if not is_put then
  114. break
  115. end
  116. now_hold_hor = now_hold_hor + 1
  117. end
  118. if is_put then
  119. break
  120. end
  121. now_vet = now_vet + 1
  122. end
  123. if is_put then
  124. break
  125. end
  126. now_hor = now_hor + 1
  127. end
  128. local now_index = now_hor * 100 + now_vet
  129. sortItemList[now_index] = v
  130. now_hold_hor = 0
  131. while now_hold_hor < hole_hor do
  132. now_hold_vet = 0
  133. local now_hold_judge_hor = now_hor + now_hold_hor
  134. while now_hold_vet < hold_vet do
  135. local now_hold_judge_vet = now_vet + now_hold_vet
  136. now_cell_index = now_hold_judge_hor * 100 + now_hold_judge_vet
  137. use_cell_dict[now_cell_index] = true
  138. now_hold_vet = now_hold_vet + 1
  139. end
  140. now_hold_hor = now_hold_hor + 1
  141. end
  142. end
  143. return sortItemList
  144. end
  145. return this