KLUIEquipTransferPanel.lua 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. ---@class KLUIEquipTransferPanel:UIKmlLuaPanelBase
  2. ---@field view KLUIEquipTransferPanelView
  3. local KLUIEquipTransferPanel = class(UIKmlLuaPanelBase)
  4. local this = KLUIEquipTransferPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. end
  8. ---创建或者刷新界面数据时调用
  9. function this:Refresh()
  10. self.strengthenState = "0"
  11. self.appendState = "0"
  12. self.rebornState = "0"
  13. self.sourceId = nil
  14. self.targetId = nil
  15. GUI:UIPanel_Open("dev/outui/Bag/Panel/KLEquipBag/KLEquipBagPanel",
  16. nil, nil,
  17. {
  18. itemList = self:SortItemList(self:GetCanTransferItemList()),
  19. x = -482,
  20. bagType = EBagShowType.EquipTransfer,
  21. itemClickCallBack = self.ClickItemCallBack,
  22. callBackUI = self
  23. }, nil, function(panel)
  24. ---@type KLEquipBagPanel
  25. self.bagUI = panel
  26. end)
  27. local args = { type = "common", item = nil, default = { width = 133, height = 234 } }
  28. ---@type KLBagItemItem
  29. GUI:UIPanel_Open("dev/ui/Common/Item/KLBagItem/KLBagItemItem", self.view.panel_equip_source_item, self, args, true, function(item)
  30. self.sourceEquip = item
  31. end)
  32. ---@type KLBagItemItem
  33. GUI:UIPanel_Open("dev/ui/Common/Item/KLBagItem/KLBagItemItem", self.view.panel_equip_target_item, self, args, true, function(item)
  34. self.targetEquip = item
  35. end)
  36. end
  37. ---注册UI事件和服务器消息
  38. function this:RegistEvents()
  39. GUI:AddOnClickEvent(self.view.btn_close, self, self.CloseSelf)
  40. GUI:AddOnClickEvent(self.view.btn_transfer, self, self.Transfer)
  41. GUI:AddOnClickEvent(self.view.btn_equip_source_takeoff, self, self.SourceEquipTakeOff, { isTips = true })
  42. GUI:AddOnClickEvent(self.view.btn_equip_target_takeoff, self, self.TargetEquipTakeOff, { isTips = true })
  43. --GUI:SetToggleOnValueChange(self.view.toggle_transfer_reborn, self, self.ToggleRebornChange)
  44. GUI:SetToggleOnValueChange(self.view.toggle_transfer_append, self, self.ToggleAppendChange)
  45. GUI:SetToggleOnValueChange(self.view.toggle_transfer_strengthen, self, self.ToggleStrengthenChange)
  46. SL:RegisterLUAEvent(LUA_EVENT_TRANSFER_SUCCESS, self.RES_TRANSFER_EQUIP, self)
  47. --SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_TRANSFER_EQUIP, self.RES_TRANSFER_EQUIP, self)
  48. SL:RegisterLUAEvent(LUA_EVENT_FORGE_GROUP_PANEL_CLOSE, self.CloseSelf, self)
  49. end
  50. function this:Transfer()
  51. if self.sourceId and self.targetId then
  52. if self.strengthenState == "1" or self.appendState == "1" or self.rebornState == "1" then
  53. if self.canTransfer then
  54. local overMax = false
  55. if self.strengthenState == "1" then
  56. ---@type cfg_equip_strengthen_column
  57. local tbl = SL:GetConfig("cfg_equip_strengthen", self.targetItem.cfgId)
  58. if tbl.maxLevel < EquipFunc.GetEquipStrengthLevel(self.sourceItem) then
  59. overMax = true
  60. end
  61. end
  62. if self.appendState == "1" then
  63. ---@type cfg_equip_appends_column
  64. local tbl = SL:GetConfig("cfg_equip_appends", self.targetItem.cfgId)
  65. if tbl.maxLevel < EquipFunc.GetEquipAppendLevel(self.sourceItem) then
  66. overMax = true
  67. end
  68. end
  69. if overMax then
  70. SL:CommonTipsMessage({ stringTblID=213,ui = self, callback = function()
  71. local message = {
  72. firstItem = self.sourceItem.id,
  73. secondItem = self.targetItem.id,
  74. transferStrength = self.strengthenState == "1",
  75. transferAppend = self.appendState == "1",
  76. transferRegeneration = self.rebornState == "1",
  77. }
  78. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_TRANSFER_EQUIP, message)
  79. end })
  80. else
  81. local message = {
  82. firstItem = self.sourceItem.id,
  83. secondItem = self.targetItem.id,
  84. transferStrength = self.strengthenState == "1",
  85. transferAppend = self.appendState == "1",
  86. transferRegeneration = self.rebornState == "1",
  87. }
  88. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_TRANSFER_EQUIP, message)
  89. end
  90. else
  91. SL:TipMessage(SL:GetConfig('cfg_string',269).text, 1, NoticeType.NoticeMid )--"货币不足",
  92. end
  93. else
  94. SL:TipMessage( SL:GetConfig('cfg_string',270).text, 1, NoticeType.NoticeMid )--"请选择转移项",
  95. end
  96. else
  97. SL:TipMessage( SL:GetConfig('cfg_string',395).text, 1, NoticeType.NoticeMid )--"请选择转移道具",
  98. end
  99. --GUI:UIPanel_Open("dev/outui/Equip/Panel/KLUIEquipQuickTransfer/KLUIEquipQuickTransferPanel", nil, nil, { sourceItem = self.sourceItem, targetItem = self.targetItem })
  100. end
  101. function this:SourceEquipTakeOff(_, eventData)
  102. if eventData and eventData.isTips then
  103. SL:CommonTipsMessage({ stringTblID=214, ui = self, callback = function()
  104. self.sourceId = nil
  105. self:TargetEquipTakeOff()
  106. self:RefreshEquipItemInfo(1)
  107. end })
  108. else
  109. if self.sourceId then
  110. self.sourceId = nil
  111. self:TargetEquipTakeOff()
  112. self:RefreshEquipItemInfo(1)
  113. end
  114. end
  115. end
  116. function this:TargetEquipTakeOff(_, eventData)
  117. if eventData and eventData.isTips then
  118. SL:CommonTipsMessage({stringTblID=214,ui = self, callback = function()
  119. self.targetId = nil
  120. self:RefreshEquipItemInfo(2)
  121. end })
  122. else
  123. if self.targetId then
  124. self.targetId = nil
  125. self:RefreshEquipItemInfo(2)
  126. end
  127. end
  128. end
  129. ---@param control UIKmlLuaControl
  130. function this:ToggleRebornChange(control)
  131. self.rebornState = GUI:Toggle_getIsOn(control)
  132. self:SourceEquipTakeOff()
  133. self.bagUI:RefreshBagItemShow(self:SortItemList(self:GetCanTransferItemList()))
  134. GUI:setVisible(self.view.text_reborn_tips, self.rebornState == "1")
  135. end
  136. ---@param control UIKmlLuaControl
  137. function this:ToggleAppendChange(control)
  138. self.appendState = GUI:Toggle_getIsOn(control)
  139. self:SourceEquipTakeOff()
  140. self.bagUI:RefreshBagItemShow(self:SortItemList(self:GetCanTransferItemList()))
  141. end
  142. ---@param control UIKmlLuaControl
  143. function this:ToggleStrengthenChange(control)
  144. self.strengthenState = GUI:Toggle_getIsOn(control)
  145. self:SourceEquipTakeOff()
  146. self.bagUI:RefreshBagItemShow(self:SortItemList(self:GetCanTransferItemList()))
  147. end
  148. ---点击背包item回调
  149. ---@param itemControl KLBagItemItemView
  150. ---@param itemData CommonProtos.Item
  151. function this:ClickItemCallBack(itemControl, itemData)
  152. if self.sourceId then
  153. if not self.targetId then
  154. self.targetId = itemData.id
  155. self.targetItem = itemData
  156. self:RefreshEquipItemInfo(2)
  157. end
  158. else
  159. if self.appendState ~= "1" and self.strengthenState ~= "1" and self.rebornState ~= "1" then
  160. SL:TipMessage( SL:GetConfig('cfg_string',270).text, 1, NoticeType.NoticeMid ) --"请选择转移项",
  161. else
  162. self.sourceId = itemData.id
  163. self.sourceItem = itemData
  164. self:RefreshEquipItemInfo(1)
  165. self:GetCanInheritItemList(self.sourceItem.cfgId)
  166. end
  167. end
  168. end
  169. function this:RES_TRANSFER_EQUIP()
  170. --GUI:setVisible(self.view.success_anim, true)
  171. --if self.resultCoro ~= nil then
  172. -- Coroutine.Stop(self.resultCoro)
  173. --end
  174. --self.resultCoro = Coroutine.Start(
  175. -- function()
  176. -- Coroutine.Wait(1.5)
  177. -- GUI:setVisible(self.view.success_anim, false)
  178. -- end
  179. --)
  180. self:SourceEquipTakeOff()
  181. end
  182. function this:RefreshEquipItemInfo(itemType)
  183. if itemType == 1 then
  184. ---转移装备
  185. if self.sourceId then
  186. ---刷新转移栏
  187. self.sourceEquip:SetItem(self.sourceItem)
  188. GUI:SetActive(self.view.panel_equip_source_item, true)
  189. GUI:SetActive(self.view.img_equip_source_select, false)
  190. GUI:SetActive(self.view.img_equip_target_select, true)
  191. GUI:SetActive(self.view.btn_equip_source_takeoff, true)
  192. local costInfo = EquipFunc.GetTransferCost(self.sourceItem, self.strengthenState, self.appendState, self.rebornState)
  193. if costInfo.id ~= 0 then
  194. ---@type cfg_item_column
  195. local item = SL:GetConfig("cfg_item", costInfo.id)
  196. local bag_num = SL:GetBagItemCount(costInfo.id)
  197. GUI:Text_setString(self.view.text_cost_item_name, item.name)
  198. GUI:Item_setItemId(self.view.item_cost, item.id)
  199. GUI:setVisible(self.view.cost_panel, true)
  200. if bag_num >= costInfo.num then
  201. self.canTransfer = true
  202. bag_num = SL:GetSimpleNumber(bag_num, 2)
  203. GUI:Text_setString(self.view.text_item_bag_count, "<color=#1ADD1F>" .. bag_num .. "</color> / " .. costInfo.num)
  204. else
  205. self.canTransfer = false
  206. bag_num = SL:GetSimpleNumber(bag_num, 2)
  207. GUI:Text_setString(self.view.text_item_bag_count, "<color=#FF2323>" .. bag_num .. "</color> / " .. costInfo.num)
  208. end
  209. end
  210. self.bagUI:RefreshBagItemShow(self:SortItemList(self:GetCanInheritItemList(self.sourceItem.cfgId)))
  211. else
  212. ---清空转移栏
  213. GUI:SetActive(self.view.panel_equip_source_item, false)
  214. GUI:SetActive(self.view.img_equip_source_select, true)
  215. GUI:SetActive(self.view.img_equip_target_select, false)
  216. GUI:SetActive(self.view.btn_equip_source_takeoff, false)
  217. GUI:setVisible(self.view.cost_panel, false)
  218. self.bagUI:RefreshBagItemShow(self:SortItemList(self:GetCanTransferItemList()))
  219. end
  220. else
  221. ---继承装备
  222. if self.targetId then
  223. ---刷新继承栏
  224. self.targetEquip:SetItem(self.targetItem)
  225. GUI:Button_loadTextureNormal(self.view.btn_transfer, "button_interface_window37", "Atlas/TS_Common.spriteatlas")
  226. GUI:SetActive(self.view.panel_equip_target_item, true)
  227. GUI:SetActive(self.view.img_equip_target_select_text, false)
  228. GUI:SetActive(self.view.img_equip_target_select, false)
  229. GUI:SetActive(self.view.btn_equip_target_takeoff, true)
  230. else
  231. ---清空继承栏
  232. GUI:Button_loadTextureNormal(self.view.btn_transfer, "button_interface_window37_gery", "Atlas/TS_Common.spriteatlas")
  233. GUI:SetActive(self.view.panel_equip_target_item, false)
  234. GUI:SetActive(self.view.img_equip_target_select_text, true)
  235. GUI:SetActive(self.view.img_equip_target_select, true)
  236. GUI:SetActive(self.view.btn_equip_target_takeoff, false)
  237. end
  238. end
  239. end
  240. ---获取可转移装备
  241. function this:GetCanTransferItemList()
  242. local canItemList = {}
  243. local itemList = self:GetAllEquipInTransfer()
  244. for i, v in ipairs(itemList) do
  245. local canSet = true
  246. local strength = EquipFunc.GetEquipStrengthLevel(v)
  247. local append = EquipFunc.GetEquipAppendLevel(v)
  248. local rebornItem = EquipFunc.GetEquipRegenerate(v)
  249. local reborn = false
  250. if rebornItem and next(rebornItem) then
  251. reborn = true
  252. end
  253. ---@type cfg_equip_transfer_column
  254. local sourceItem = SL:GetConfig("cfg_equip_transfer", v.cfgId)
  255. if self.strengthenState == "1" then
  256. if sourceItem.transfer[1] == 1 then
  257. if strength == 0 then
  258. canSet = false
  259. end
  260. else
  261. canSet = false
  262. end
  263. end
  264. if self.appendState == "1" then
  265. if sourceItem.transfer[2] == 1 then
  266. if append == 0 then
  267. canSet = false
  268. end
  269. else
  270. canSet = false
  271. end
  272. end
  273. if self.rebornState == "1" then
  274. if sourceItem.transfer[3] == 1 then
  275. if not reborn then
  276. canSet = false
  277. end
  278. else
  279. canSet = false
  280. end
  281. else
  282. if self.strengthenState == "1" and reborn then
  283. canSet = false
  284. end
  285. end
  286. if append == 0 and strength == 0 and not reborn then
  287. canSet = false
  288. end
  289. if canSet then
  290. canItemList[#canItemList + 1] = v
  291. end
  292. end
  293. return canItemList
  294. end
  295. ---获取可继承装备
  296. function this:GetCanInheritItemList(cfg_id)
  297. local canItemList = {}
  298. ---@type CommonProtos.Item[]
  299. local itemList = self:GetAllEquipInTransfer()
  300. ---@type cfg_equip_transfer_column
  301. local sourceItem = SL:GetConfig("cfg_equip_transfer", cfg_id)
  302. local sourceGroup = sourceItem.transferGroup
  303. local sourceReborn = sourceItem.regenerationGroup
  304. for _, v in pairs(itemList) do
  305. local canTransfer = true
  306. if v.id ~= self.sourceId then
  307. ---@type cfg_equip_transfer_column
  308. local targetItem = SL:GetConfig("cfg_equip_transfer", v.cfgId)
  309. if self.strengthenState == "1" then
  310. if targetItem.transferGroup and targetItem.transferGroup == sourceGroup then
  311. if EquipFunc.GetEquipStrengthLevel(v) ~= 0 then
  312. canTransfer = false
  313. end
  314. else
  315. canTransfer = false
  316. end
  317. end
  318. if canTransfer and self.appendState == "1" then
  319. if targetItem.transferGroup and targetItem.transferGroup == sourceGroup then
  320. if EquipFunc.GetEquipAppendLevel(v) ~= 0 then
  321. canTransfer = false
  322. end
  323. else
  324. canTransfer = false
  325. end
  326. end
  327. if canTransfer and self.rebornState == "1" then
  328. if targetItem.regenerationGroup and targetItem.regenerationGroup == sourceReborn then
  329. local rebornItem = EquipFunc.GetEquipRegenerate(v)
  330. local reborn = false
  331. if rebornItem and next(rebornItem) then
  332. reborn = true
  333. end
  334. if reborn then
  335. canTransfer = false
  336. end
  337. if canTransfer and self.strengthenState == "0" then
  338. ---@type cfg_equip_regeneration_column
  339. local regeneration = SL:GetConfig("cfg_equip_regeneration", v.cfgId)
  340. if not regeneration or regeneration.condition > EquipFunc.GetEquipStrengthLevel(v) then
  341. canTransfer = false
  342. end
  343. end
  344. else
  345. canTransfer = false
  346. end
  347. end
  348. if canTransfer then
  349. canItemList[#canItemList + 1] = v
  350. end
  351. end
  352. end
  353. return canItemList
  354. end
  355. ---@return CommonProtos.Item[]
  356. function this:GetAllEquipInTransfer()
  357. ---@type CommonProtos.Item[]
  358. local bagData = SL:GetMetaValue(EMetaVarGetKey.BAG_DATA)
  359. ---@type CommonProtos.Item[]
  360. local equipData = SL:GetMetaValue(EMetaVarGetKey.EQUIP_DATA)
  361. local equip_list = {}
  362. if equipData[1] then
  363. for _, v in pairs(equipData[1]) do
  364. local hasCfg = SL:HasConfig("cfg_equip_transfer", v.cfgId, "id")
  365. if hasCfg then
  366. local item = SL:GetConfig("cfg_equip_transfer", v.cfgId)
  367. if item then
  368. equip_list[#equip_list + 1] = v
  369. end
  370. end
  371. end
  372. end
  373. if bagData[1] then
  374. for _, v in pairs(bagData[1]) do
  375. local hasCfg = SL:HasConfig("cfg_equip_transfer", v.cfgId, "id")
  376. if hasCfg then
  377. local item = SL:GetConfig("cfg_equip_transfer", v.cfgId)
  378. if item then
  379. equip_list[#equip_list + 1] = v
  380. end
  381. end
  382. end
  383. end
  384. return equip_list
  385. end
  386. ---@param itemList CommonProtos.Item[]
  387. ---@return CommonProtos.Item[]
  388. function this:SortItemList(itemList)
  389. local bag_str = SL:GetConfig("cfg_global", 6).value
  390. local bag_tbl = string.split(bag_str, '#')
  391. local bag_hor = tonumber(bag_tbl[1])
  392. local bag_vet = tonumber(bag_tbl[2])
  393. local use_cell_dict = {}
  394. local sortItemList = {}
  395. 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
  396. local max_hor = bag_hor + 20
  397. for _, v in pairs(itemList) do
  398. cfg_id = v.cfgId
  399. now_hor = 1
  400. while now_hor <= max_hor do
  401. now_vet = 1
  402. while now_vet <= bag_vet do
  403. is_put = true
  404. ---@type cfg_item_column
  405. item = SL:GetConfig("cfg_item", cfg_id)
  406. hold_vet = item.holdGrid[1]
  407. hole_hor = item.holdGrid[2]
  408. now_hold_hor = 0
  409. while now_hold_hor < hole_hor do
  410. now_judge_hor = now_hor + now_hold_hor
  411. now_hold_vet = 0
  412. while now_hold_vet < hold_vet do
  413. now_judge_vet = now_vet + now_hold_vet
  414. now_cell_index = now_judge_hor * 100 + now_judge_vet
  415. if use_cell_dict[now_cell_index] or now_judge_vet > bag_vet then
  416. is_put = false
  417. break
  418. end
  419. now_hold_vet = now_hold_vet + 1
  420. end
  421. if not is_put then
  422. break
  423. end
  424. now_hold_hor = now_hold_hor + 1
  425. end
  426. if is_put then
  427. break
  428. end
  429. now_vet = now_vet + 1
  430. end
  431. if is_put then
  432. break
  433. end
  434. now_hor = now_hor + 1
  435. end
  436. local now_index = now_hor * 100 + now_vet
  437. sortItemList[now_index] = v
  438. now_hold_hor = 0
  439. while now_hold_hor < hole_hor do
  440. now_hold_vet = 0
  441. local now_hold_judge_hor = now_hor + now_hold_hor
  442. while now_hold_vet < hold_vet do
  443. local now_hold_judge_vet = now_vet + now_hold_vet
  444. now_cell_index = now_hold_judge_hor * 100 + now_hold_judge_vet
  445. use_cell_dict[now_cell_index] = true
  446. now_hold_vet = now_hold_vet + 1
  447. end
  448. now_hold_hor = now_hold_hor + 1
  449. end
  450. end
  451. return sortItemList
  452. end
  453. function this:CloseSelf()
  454. GUI:UIPanel_Close("dev/outui/Bag/Panel/KLEquipBag/KLEquipBagPanel")
  455. GUI:UIPanel_Close("dev/outui/Equip/Panel/KLUIEquipTransfer/KLUIEquipTransferPanel")
  456. GUI:UIPanel_Close("dev/ui/UIForgeGroup/Panel/KLUIForgeGroup/KLUIForgeGroupPanel")
  457. end
  458. function this:Close()
  459. end
  460. return this