KLArchangelDecomposePanel.lua 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. ---@class KLArchangelDecomposePanel:UIKmlLuaPanelBase
  2. ---@field view KLArchangelDecomposePanelView
  3. ---@field grailList CommonProtos.Item[]
  4. ---@field selectGrailList number[]
  5. ---@field grailItemList KLGrailDecomposeItem[]
  6. local KLArchangelDecomposePanel = class(UIKmlLuaPanelBase)
  7. local this = KLArchangelDecomposePanel
  8. function this:AsyncLoadUI()
  9. end
  10. ---创建时调用一次
  11. function this:Init()
  12. SL.HideMainPanel()
  13. self.grailList = {}
  14. self.grailItemList = {}
  15. GUI:DataListInitData(self.view.DecomposeGetDataList, function()
  16. return #self.getList
  17. end, function(realIndex)
  18. end, function(realIndex, kmlcontrol)
  19. end, function(realIndex, kmlcontrol)
  20. return self:GetDataListItemUpdateFunc(realIndex, kmlcontrol)
  21. end)
  22. GUI:DataListInitData(self.view.DecomposeCustomDataList, function()
  23. return #self.costList
  24. end, function(realIndex)
  25. end, function(realIndex, kmlcontrol)
  26. end, function(realIndex, kmlcontrol)
  27. return self:CustomDataListItemUpdateFunc(realIndex, kmlcontrol)
  28. end)
  29. GUI:DataListInitData(self.view.grail_list, function()
  30. return #self.grailList
  31. end, function(realIndex)
  32. return self:GrailDecomposeItemGetFunc(realIndex)
  33. end, function(realIndex, kmlcontrol)
  34. end, function(realIndex, kmlcontrol)
  35. return self:GrailDecomposeItemUpdateFunc(realIndex, kmlcontrol)
  36. end)
  37. end
  38. ---注册UI事件和服务器消息
  39. function this:RegistEvents()
  40. GUI:AddOnClickEvent(self.view.allselect, self, self.AllSelect)
  41. GUI:AddOnClickEvent(self.view.CloseButton, self, self.ClosePanel)
  42. GUI:AddOnClickEvent(self.view.DecomposeButton, self, self.Decompose)
  43. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_GRAIL_DECOMPOSE_RESULT, self.RES_GRAIL_DECOMPOSE_RESULT, self)
  44. end
  45. ---界面显示时调用一次
  46. function this:Show()
  47. self.all = false
  48. GUI:setVisible(self.view.gouxuan, false)
  49. end
  50. ---创建或者刷新界面数据时调用
  51. function this:Refresh()
  52. self.grailList = {}
  53. self.selectGrailList = {}
  54. if not self.bagUI then
  55. GUI:UIPanel_Open("dev/outui/Archangel/Panel/KLFusionBag/KLFusionBagPanel", nil, nil, { x = -482, y = 0, itemClick = self.BagItemClick, callBackUI = self }, false, function(bagUI)
  56. ---@type KLFusionBagPanel
  57. self.bagUI = bagUI
  58. self.bagUI:RefreshItem(self:GetBagList())
  59. end)
  60. else
  61. self.bagUI:RefreshItem(self:GetBagList())
  62. end
  63. GUI:setVisible(self.view.hide_panel, false)
  64. GUI:setVisible(self.view.NoInfo, true)
  65. end
  66. function this:AllSelect()
  67. self.all = not self.all
  68. GUI:setVisible(self.view.gouxuan, self.all)
  69. self.selectGrailList = {}
  70. self.grailList = {}
  71. self.selectGrailShow = {}
  72. local data = self:GetBagList()
  73. for i, v in pairs(data) do
  74. if self.all then
  75. table.insert(self.selectGrailList, v.id)
  76. local pos = table.getKey(self.selectGrailList, v.id)
  77. self.grailList[pos] = v
  78. end
  79. self.selectGrailShow[v.id] = self.all
  80. end
  81. self.bagUI:RefreshGrailSelect(self.selectGrailShow)
  82. self:RefreshCostandGet()
  83. end
  84. function this:BagItemClick(itemControl, itemData, itemSelf)
  85. if table.contains(self.selectGrailList, itemData.id) then
  86. itemSelf:SetSelectEffect(false, true)
  87. local pos = table.getKey(self.selectGrailList, itemData.id)
  88. table.remove(self.grailList, pos)
  89. table.removeByValue(self.selectGrailList, itemData.id)
  90. else
  91. table.insert(self.selectGrailList, itemData.id)
  92. local pos = table.getKey(self.selectGrailList, itemData.id)
  93. self.grailList[pos] = itemData
  94. itemSelf:SetSelectEffect(true, true)
  95. end
  96. self:RefreshCostandGet()
  97. end
  98. function this:RefreshCostandGet()
  99. if table.count(self.selectGrailList) == 0 then
  100. GUI:setVisible(self.view.hide_panel, false)
  101. GUI:setVisible(self.view.NoInfo, true)
  102. return
  103. end
  104. GUI:setVisible(self.view.hide_panel, true)
  105. GUI:setVisible(self.view.NoInfo, false)
  106. --刷新道具显示
  107. GUI:DataListUpdateData(self.view.grail_list)
  108. --刷新所得
  109. local getListData = {}
  110. local costListData = {}
  111. self.getList = {}
  112. self.costList = {}
  113. for i, v in pairs(self.grailList) do
  114. local angelstrengthenLv = InfoManager.archangeEquipInfo:GetGrailStrengthLv(v.id)
  115. local strengthenTbl = SL:GetConfig("cfg_equip_angelStrengthen", v.cfgId, "id")
  116. local costTbl = SL:GetConfigTwoKeys("cfg_equip_angelStrengthenCost", strengthenTbl.SplitGroup, angelstrengthenLv, "AngelstrengthenGroup", "AngelstrengthenLv")
  117. for _, j in pairs(costTbl.AngelstrengthenGet) do
  118. if getListData[j[1]] then
  119. getListData[j[1]] = getListData[j[1]] + j[2]
  120. else
  121. getListData[j[1]] = j[2]
  122. end
  123. end
  124. for _, j in pairs(costTbl.RecoVeryCost) do
  125. if costListData[j[1]] then
  126. costListData[j[1]] = costListData[j[1]] + j[2]
  127. else
  128. costListData[j[1]] = j[2]
  129. end
  130. end
  131. end
  132. for i, v in pairs(getListData) do
  133. table.insert(self.getList, { itemId = i, count = v })
  134. end
  135. for i, v in pairs(costListData) do
  136. table.insert(self.costList, { itemId = i, count = v })
  137. end
  138. GUI:DataListUpdateData(self.view.DecomposeGetDataList)
  139. GUI:DataListUpdateData(self.view.DecomposeCustomDataList)
  140. end
  141. function this:GrailDecomposeItemGetFunc(realIndex)
  142. local item = GUI:UIPanel_Open("dev/outui/Archangel/Item/KLGrailDecompose/KLGrailDecomposeItem", self.view.grail_list, self, nil, true)
  143. self.grailItemList[item.view.root] = item
  144. return item.view.root
  145. end
  146. function this:GrailDecomposeItemUpdateFunc(realIndex, kmlcontrol)
  147. self.grailItemList[kmlcontrol]:RefeshData(self.grailList[realIndex + 1].cfgId, self.grailList[realIndex + 1].id)
  148. end
  149. function this:GetDataListItemUpdateFunc(realIndex, kmlcontrol)
  150. local GetItem = GUI:GetChildControl(self.view.DecomposeGetDataList, realIndex, "GetItem")
  151. GUI:Item_setItemId(GetItem, self.getList[realIndex + 1].itemId)
  152. GUI:Item_setItemCount(GetItem, tostring(self.getList[realIndex + 1].count))
  153. end
  154. function this:CustomDataListItemUpdateFunc(realIndex, kmlcontrol)
  155. local cost_item = GUI:GetChildControl(self.view.DecomposeCustomDataList, realIndex, "cost_item")
  156. local cost_name = GUI:GetChildControl(self.view.DecomposeCustomDataList, realIndex, "cost_name")
  157. local cost_num = GUI:GetChildControl(self.view.DecomposeCustomDataList, realIndex, "cost_num")
  158. local costAddBtn = GUI:GetChildControl(self.view.DecomposeCustomDataList, realIndex, "costAddBtn")
  159. local data = self.costList[realIndex + 1]
  160. GUI:Item_setItemId(cost_item, data.itemId)
  161. ---@type cfg_item_column
  162. local itemTbl = SL:GetConfig("cfg_item", data.itemId, "id")
  163. GUI:Text_setString(cost_name, itemTbl.name)
  164. local costNumStr = ""
  165. local bagCount = SL:GetBagItemCount(data.itemId)
  166. if bagCount >= data.count then
  167. costNumStr = "<color='#1add1f'>" .. tostring(bagCount) .. "</color>/" .. tostring(data.count)
  168. --self.isCost = true
  169. else
  170. costNumStr = "<color='#ff2323'>" .. tostring(bagCount) .. "</color>/" .. tostring(data.count)
  171. --self.isCost = false
  172. end
  173. GUI:Text_setString(cost_num, costNumStr)
  174. GUI:AddOnClickEvent(costAddBtn, self, function()
  175. SL:CommonItemGetPath(nil, data.itemId)
  176. end)
  177. end
  178. function this:GetBagList()
  179. local data = {}
  180. local bagItemTabl = SL:GetMetaValue("BAG_DATA")[1]
  181. if bagItemTabl then
  182. for _, v in pairs(bagItemTabl) do
  183. local tbl = nil
  184. if SL:HasConfig("cfg_equip_angelGrail", v.cfgId, "id") then
  185. table.insert(data, v)
  186. end
  187. end
  188. end
  189. return data
  190. end
  191. function this:Decompose()
  192. local indexlist = {}
  193. for i, v in pairs(self.selectGrailList) do
  194. table.insert(indexlist, SL:GetBagIndex(v))
  195. end
  196. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_ANGEL_GRAIL_DECOMPOSE, { indexList = indexlist, grailIds = self.selectGrailList })
  197. end
  198. function this:RES_GRAIL_DECOMPOSE_RESULT(_, message)
  199. if message then
  200. for i, v in pairs(self.selectGrailList) do
  201. InfoManager.archangeEquipInfo:GrailInfoChange(v)
  202. end
  203. InfoManager.archangeEquipInfo:CheckEquipRed()
  204. local group = GUI:GetUI("dev/outui/Archangel/Panel/KLArchangelGroup/KLArchangelGroupPanel")
  205. if group then
  206. group:RefreshRed()
  207. end
  208. self:Refresh()
  209. end
  210. end
  211. function this:ClosePanel()
  212. GUI:UIPanel_Close("dev/outui/Archangel/Panel/KLArchangelDecompose/KLArchangelDecomposePanel")
  213. GUI:UIPanel_Close("dev/outui/Archangel/Panel/KLArchangelGroup/KLArchangelGroupPanel")
  214. end
  215. function this:Hide()
  216. end
  217. function this:Close()
  218. GUI:UIPanel_Close("dev/outui/Archangel/Panel/KLFusionBag/KLFusionBagPanel")
  219. end
  220. return this