KLShapeShiftCardBreakPanel.lua 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. ---@class KLShapeShiftCardBreakPanel:UIKmlLuaPanelBase
  2. ---@field view KLShapeShiftCardBreakPanelView
  3. local KLShapeShiftCardBreakPanel = class(UIKmlLuaPanelBase)
  4. local this = KLShapeShiftCardBreakPanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. self.breakCount = 1
  10. self.cardItemList = {}
  11. GUI:DataListInitData(self.view.datalist_card,
  12. function()
  13. return self:ItemCountFunc()
  14. end, function(realIndex)
  15. return self:ItemGetFunc(realIndex)
  16. end, nil, function(realIndex, kmlCtrl)
  17. return self:ItemUpdateFunc(realIndex, kmlCtrl)
  18. end
  19. )
  20. self.cardExchangeItemList = {}
  21. GUI:DataListInitData(self.view.datalist_card_exchange,
  22. function()
  23. return self:ExchangeItemCountFunc()
  24. end, function(realIndex)
  25. return self:ExchangeItemGetFunc(realIndex)
  26. end, nil,
  27. function(realIndex, kmlCtrl)
  28. return self:ExchangeItemUpdateFunc(realIndex, kmlCtrl)
  29. end
  30. )
  31. self.cardBreakList = {}
  32. self.selectCardBreak = {}
  33. GUI:DataListInitData(self.view.break_card_list,
  34. function()
  35. return self.breakCount
  36. end,
  37. function(realIndex)
  38. return self:DataListItemGetFunc(realIndex)
  39. end,
  40. nil,
  41. function(realIndex, kmlCtrl)
  42. return self:DataListItemUpdateFunc(realIndex, kmlCtrl)
  43. end)
  44. self.attrList = {}
  45. GUI:DataListInitData(self.view.attr_datalist,
  46. function()
  47. return #self.attrList
  48. end,
  49. nil,
  50. nil,
  51. function(realIndex)
  52. local attr = GUI:GetChildControl(self.view.attr_datalist, realIndex, 'attr')
  53. local attrInfo = self.attrList[realIndex + 1]
  54. local preValue
  55. local tbl = SL:GetConfig("cfg_att_info", tonumber(attrInfo.attrId))
  56. local attrName = tbl.name
  57. local att_remark = tbl.remarks
  58. if att_remark == 1 then
  59. preValue = attrInfo.attrValue
  60. else
  61. preValue = tonumber(attrInfo.attrValue) / 100 .. '%'
  62. end
  63. GUI:Text_setString(attr, attrName .. ":" .. preValue)
  64. local cfg = SL:GetConfig("cfg_card_att", tonumber(attrInfo.attrCfgId))
  65. GUI:Text_setTextColor(attr, tostring(cfg.color))
  66. end
  67. )
  68. self.scrollViewType = E_ShapeShiftCardType.Exchange
  69. end
  70. --region NormalListRefresh
  71. function this:ItemCountFunc()
  72. return #self.selectCardInfo
  73. end
  74. function this:ItemGetFunc()
  75. ---@type KLShapeShiftCardItem
  76. local item = GUI:UIPanel_Open("dev/outui/ShapeShiftCard/Item/KLShapeShiftCard/KLShapeShiftCardItem", self.view.datalist_card, self, { type = E_ShapeShiftCardFuncType.Break }, true)
  77. local kmlCtrl = item.view.root
  78. self.cardItemList[kmlCtrl] = item
  79. return kmlCtrl
  80. end
  81. ---@param realIndex number
  82. ---@param kmlCtrl KingML.KmlControl
  83. function this:ItemUpdateFunc(realIndex, kmlCtrl)
  84. ---@type KLShapeShiftCardItem
  85. local item = self.cardItemList[kmlCtrl]
  86. item:RefreshBreak(self.selectCardInfo[realIndex + 1])
  87. end
  88. --endregion
  89. --region ExchangeListRefresh
  90. function this:ExchangeItemCountFunc()
  91. return #self.exchangeCardInfo
  92. end
  93. function this:ExchangeItemGetFunc()
  94. ---@type KLShapeShiftCardItem
  95. local item = GUI:UIPanel_Open("dev/outui/ShapeShiftCard/Item/KLShapeShiftCard/KLShapeShiftCardItem", self.view.datalist_card_exchange, self, { type = E_ShapeShiftCardFuncType.ExBreak }, true)
  96. local kmlCtrl = item.view.root
  97. self.cardExchangeItemList[kmlCtrl] = item
  98. return kmlCtrl
  99. end
  100. ---@param realIndex number
  101. ---@param kmlCtrl KingML.KmlControl
  102. function this:ExchangeItemUpdateFunc(realIndex, kmlCtrl)
  103. ---@type KLShapeShiftCardItem
  104. local item = self.cardExchangeItemList[kmlCtrl]
  105. item:RefreshBreak(self.exchangeCardInfo[realIndex + 1])
  106. end
  107. --endregion
  108. --region BreakListRefresh
  109. function this:DataListItemGetFunc()
  110. ---@type KLShapeShiftCardItem
  111. local item = GUI:UIPanel_Open("dev/outui/ShapeShiftCard/Item/KLShapeShiftCard/KLShapeShiftCardItem", self.view.break_card_list, self, { type = E_ShapeShiftCardFuncType.UnBreak }, true)
  112. local kmlCtrl = item.view.root
  113. self.cardBreakList[kmlCtrl] = item
  114. return kmlCtrl
  115. end
  116. function this:DataListItemUpdateFunc(realIndex, kmlCtrl)
  117. ---@type KLShapeShiftCardItem
  118. local item = self.cardBreakList[kmlCtrl]
  119. item:RefreshBreak(self.selectCardBreak[realIndex + 1])
  120. end
  121. --endregion
  122. ---注册UI事件和服务器消息
  123. function this:RegistEvents()
  124. GUI:AddOnClickEvent(self.view.btn_go, self, self.SwitchCardShop)
  125. GUI:AddOnClickEvent(self.view.btn_tips, self, self.FuncTips)
  126. GUI:AddOnClickEvent(self.view.btn_break, self, self.BreakOnClick)
  127. GUI:AddOnClickEvent(self.view.btn_auto_break_ex, self, self.AutoBreakOnClick)
  128. GUI:AddOnClickEvent(self.view.btn_auto_break, self, self.AutoBreakOnClick)
  129. GUI:AddOnClickEvent(self.view.btn_break_up, self, self.RefreshBreakPanel)
  130. GUI:SetToggleOnValueChange(self.view.toggle_shift, self, self.ToggleShiftOnChange)
  131. GUI:SetToggleOnValueChange(self.view.toggle_attr, self, self.ToggleAttrOnChange)
  132. GUI:SetToggleOnValueChange(self.view.toggle_god_attr, self, self.ToggleGodAttrOnChange)
  133. SL:RegisterLUAEvent(LUA_SHAPE_CARD_BAG_CHANGE, self.RES_TRANSFER_CARD_BAG, self)
  134. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_CARD_BREAKTHROUGH_FAIL, self.RES_CARD_BREAKTHROUGH_FAIL, self)
  135. end
  136. ---界面显示时调用一次
  137. function this:Show()
  138. end
  139. ---创建或者刷新界面数据时调用
  140. function this:Refresh()
  141. self.selectCardInfo = {}
  142. self.normalCardInfo = {}
  143. self.exchangeCardInfo = {}
  144. self:RES_TRANSFER_CARD_BAG()
  145. end
  146. function this:SwitchCardShop()
  147. local ui = GUI:GetUI("dev/outui/ShapeShiftCard/Panel/KLShapeShiftCardMain/KLShapeShiftCardMainPanel")
  148. if ui then
  149. GUI:Toggle_setIsOn(ui.view.toggle_shop, true)
  150. end
  151. end
  152. function this:FuncTips()
  153. local helpCfg = SL:GetConfig("cfg_rule_text", 103)
  154. if helpCfg then
  155. SL:CommonStrTipsMessage({ title = helpCfg.menutxt, str = helpCfg.location })
  156. end
  157. end
  158. function this:RefreshBreakPanel()
  159. self.breakIsShow = not self.breakIsShow
  160. if not self.breakIsShow then
  161. self:HideBreakPanel()
  162. else
  163. self:ShowBreakPanel()
  164. end
  165. end
  166. function this:HideBreakPanel(isChange)
  167. GUI:setVisible(self.view.panel_break, false)
  168. GUI:setPositionY(self.view.btn_break_up, -22)
  169. GUI:setContentSize(self.view.loopscrollview_card, 825, 463)
  170. GUI:Image_loadTexture(self.view.img_btn_icon, "house_up", "Atlas/KLShapeShiftCard.spriteatlas")
  171. if not isChange then
  172. if #self.selectCardInfo == 0 then
  173. GUI:setVisible(self.view.panel_no_card, true)
  174. end
  175. self:RefreshScrollView()
  176. end
  177. self.selectCardBreak = {}
  178. self.attrList = {}
  179. self.breakCount = 1
  180. GUI:setVisible(self.view.text_minor_1, false)
  181. GUI:setVisible(self.view.text_minor_2, false)
  182. GUI:DataListUpdateData(self.view.attr_datalist)
  183. GUI:SetLoadingbar_startper(self.view.loadingbar_luck, 0)
  184. end
  185. function this:ShowBreakPanel()
  186. GUI:setVisible(self.view.panel_break, true)
  187. GUI:setPositionY(self.view.btn_break_up, 190)
  188. GUI:setContentSize(self.view.loopscrollview_card, 825, 254)
  189. GUI:Image_loadTexture(self.view.img_btn_icon, "house_down", "Atlas/KLShapeShiftCard.spriteatlas")
  190. if #self.selectCardInfo == 0 then
  191. GUI:setVisible(self.view.panel_no_card, false)
  192. end
  193. GUI:DataListUpdateData(self.view.break_card_list)
  194. GUI:DataListUpdateData(self.view.datalist_card)
  195. self.needRefreshHouseList = true
  196. end
  197. function this:ToggleShiftOnChange(_, _, eventData)
  198. if eventData[1] then
  199. self:RefreshExchangeScrollView()
  200. end
  201. end
  202. function this:ToggleAttrOnChange(_, _, eventData)
  203. if eventData[1] then
  204. self.scrollViewType = E_ShapeShiftCardType.Attr
  205. self:RefreshScrollView()
  206. end
  207. end
  208. function this:ToggleGodAttrOnChange(_, _, eventData)
  209. if eventData[1] then
  210. self.scrollViewType = E_ShapeShiftCardType.GodAttr
  211. self:RefreshScrollView()
  212. end
  213. end
  214. function this:AutoBreakOnClick()
  215. GUI:UIPanel_Open("dev/outui/ShapeShiftCard/Panel/KLShapeShiftCardAutoUpgrade/KLShapeShiftCardAutoUpgradePanel", nil, nil, { callback = self.AutoUpgradeClick, funcType = E_ShapeShiftCardFuncType.Break, cardType = self.scrollViewType, btnName = "一键突破" })
  216. end
  217. function this.AutoUpgradeClick(autoType, autoLevel)
  218. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_BREAKTHROUGH_CARD_ALL, { autoType, autoLevel })
  219. end
  220. function this:BreakOnClick()
  221. if #self.selectCardBreak == self.breakCount then
  222. SL:CommonTipsMessage({ stringTblID = 20008, ui = self, callback = function()
  223. local card = {}
  224. local mainCard = self.selectCardBreak[1].id
  225. for i = 2, self.breakCount do
  226. card[#card + 1] = self.selectCardBreak[i].id
  227. end
  228. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_BREAKTHROUGH_CARD, { mainCard, card })
  229. end })
  230. else
  231. SL:TipMessage(SL:GetConfig('cfg_string', 20004).text, 1, NoticeType.NoticeMid) --"卡牌数量不足"
  232. end
  233. end
  234. function this:RES_TRANSFER_CARD_BAG()
  235. self.normalCardInfo = {}
  236. self.exchangeCardInfo = {}
  237. ---@type BagShapeShiftCard[]
  238. local message = InfoManager.shapeShiftCardInfo.allCardInfo
  239. if message then
  240. for _, v in pairs(message) do
  241. ---@type cfg_card_breakthrough_column
  242. if SL:HasConfig("cfg_card_breakthrough", v.cfgid) then
  243. local card_break_tbl = SL:GetConfig("cfg_card_breakthrough", v.cfgid)
  244. if card_break_tbl and card_break_tbl.expend ~= 0 then
  245. v.breakTbl = card_break_tbl
  246. if v.type == E_ShapeShiftCardType.Exchange then
  247. local isHave = true
  248. for _, vv in pairs(self.exchangeCardInfo) do
  249. if vv.cfgid == v.cfgid then
  250. vv.count[#vv.count + 1] = v.id
  251. isHave = false
  252. end
  253. end
  254. if isHave then
  255. v.count = {}
  256. v.count[1] = v.id
  257. self.exchangeCardInfo[#self.exchangeCardInfo + 1] = v
  258. end
  259. elseif v.type == E_ShapeShiftCardType.Attr or v.type == E_ShapeShiftCardType.GodAttr then
  260. self.normalCardInfo[#self.normalCardInfo + 1] = v
  261. end
  262. end
  263. end
  264. end
  265. end
  266. table.sort(self.normalCardInfo, function(a, b)
  267. if a.subType ~= b.subType then
  268. return a.subType < b.subType
  269. else
  270. if a.quality ~= b.quality then
  271. return a.quality > b.quality
  272. else
  273. return a.cfgid > b.cfgid
  274. end
  275. end
  276. end)
  277. table.sort(self.exchangeCardInfo, function(a, b)
  278. if a.subType ~= b.subType then
  279. return a.subType < b.subType
  280. else
  281. if a.quality ~= b.quality then
  282. return a.quality > b.quality
  283. else
  284. return a.cfgid > b.cfgid
  285. end
  286. end
  287. end)
  288. self:HideBreakPanel(true)
  289. self.breakIsShow = false
  290. if self.scrollViewType == E_ShapeShiftCardType.Exchange then
  291. self:RefreshExchangeScrollView()
  292. else
  293. self:RefreshScrollView()
  294. end
  295. self:RefreshBreakRedPoint()
  296. end
  297. ---刷新赋能卡牌
  298. function this:RefreshScrollView(cfgid, noReset)
  299. GUI:setVisible(self.view.loopscrollview_card_exchange, false)
  300. GUI:setVisible(self.view.loopscrollview_card, true)
  301. GUI:setVisible(self.view.btn_break_up, true)
  302. GUI:setVisible(self.view.btn_auto_break_ex, false)
  303. self.selectCardInfo = {}
  304. if not cfgid then
  305. for _, v in pairs(self.normalCardInfo) do
  306. if not noReset then
  307. ---显示选中光圈
  308. v.select = false
  309. end
  310. if v.type == self.scrollViewType then
  311. self.selectCardInfo[#self.selectCardInfo + 1] = v
  312. end
  313. end
  314. else
  315. for _, v in pairs(self.normalCardInfo) do
  316. if v.type == self.scrollViewType and v.cfgid == cfgid then
  317. self.selectCardInfo[#self.selectCardInfo + 1] = v
  318. end
  319. end
  320. end
  321. GUI:DataListUpdateData(self.view.datalist_card)
  322. if #self.selectCardInfo == 0 and not cfgid then
  323. GUI:setVisible(self.view.panel_no_card, true)
  324. else
  325. GUI:setVisible(self.view.panel_no_card, false)
  326. end
  327. if self.scrollViewType == E_ShapeShiftCardType.Attr then
  328. GUI:setVisible(self.view.img_redPoint, self.red_1)
  329. elseif self.scrollViewType == E_ShapeShiftCardType.GodAttr then
  330. GUI:setVisible(self.view.img_redPoint, self.red_3)
  331. end
  332. end
  333. ---刷新变身卡牌
  334. function this:RefreshExchangeScrollView()
  335. self.scrollViewType = E_ShapeShiftCardType.Exchange
  336. ---隐藏突破副窗口且不刷新赋能卡牌数据
  337. self:HideBreakPanel(true)
  338. self.breakIsShow = false
  339. GUI:setVisible(self.view.loopscrollview_card_exchange, true)
  340. GUI:setVisible(self.view.loopscrollview_card, false)
  341. GUI:setVisible(self.view.btn_break_up, false)
  342. GUI:DataListUpdateData(self.view.datalist_card_exchange)
  343. if #self.exchangeCardInfo == 0 then
  344. GUI:setVisible(self.view.panel_no_card, true)
  345. GUI:setVisible(self.view.btn_auto_break_ex, false)
  346. else
  347. GUI:setVisible(self.view.panel_no_card, false)
  348. GUI:setVisible(self.view.btn_auto_break_ex, true)
  349. end
  350. end
  351. function this:SetBreakInfo(info, isAdd)
  352. if isAdd then
  353. ---突破材料满了不进行后续操作
  354. local isMax = true
  355. for i = 1, info.breakTbl.expend do
  356. if not self.selectCardBreak[i] or not self.selectCardBreak[i].id then
  357. self.selectCardBreak[i] = info
  358. isMax = false
  359. if i == 1 then
  360. self.attrList = {}
  361. GUI:setVisible(self.view.attr_layout, true)
  362. if info and table.count(info.entry) then
  363. for _, v in pairs(info.entry) do
  364. self.attrList[#self.attrList + 1] = { ["attrId"] = v.attrid, ["attrValue"] = v.attrvalue, ["attrCfgId"] = v.entryid }
  365. end
  366. end
  367. GUI:DataListUpdateData(self.view.attr_datalist)
  368. GUI:SetLoadingbar_startper(self.view.loadingbar_luck, info.breakLuck)
  369. end
  370. break
  371. end
  372. end
  373. if isMax then
  374. return true
  375. end
  376. else
  377. for i = 1, info.breakTbl.expend do
  378. if self.selectCardBreak[i] and self.selectCardBreak[i].id == info.id then
  379. self.selectCardBreak[i] = nil
  380. if i == 1 then
  381. self.attrList = {}
  382. GUI:DataListUpdateData(self.view.attr_datalist)
  383. GUI:SetLoadingbar_startper(self.view.loadingbar_luck, 0)
  384. end
  385. break
  386. end
  387. end
  388. end
  389. self.breakCount = 1
  390. for i = 1, info.breakTbl.expend do
  391. if self.selectCardBreak[i] then
  392. self.breakCount = self.selectCardBreak[i].breakTbl.expend
  393. break
  394. end
  395. end
  396. if self.breakCount == 1 then
  397. GUI:setVisible(self.view.text_minor_1, false)
  398. GUI:setVisible(self.view.text_minor_2, false)
  399. elseif self.breakCount == 2 then
  400. GUI:setVisible(self.view.text_minor_1, true)
  401. GUI:setVisible(self.view.text_minor_2, false)
  402. elseif self.breakCount == 3 then
  403. GUI:setVisible(self.view.text_minor_1, true)
  404. GUI:setVisible(self.view.text_minor_2, true)
  405. end
  406. GUI:DataListUpdateData(self.view.break_card_list)
  407. ---刷新单个卡牌选中框,不刷全部卡牌,防止刷新导致list位置重置
  408. if not self.needRefreshHouseList then
  409. ---@param v KLShapeShiftCardItem
  410. for _, v in pairs(self.cardItemList) do
  411. v:ShowSelectShow(info.id, isAdd)
  412. end
  413. end
  414. ---刷新数据正确性
  415. for _, v in pairs(self.selectCardInfo) do
  416. if v.id == info.id then
  417. v.select = isAdd
  418. break
  419. end
  420. end
  421. for i = 1, info.breakTbl.expend do
  422. if self.selectCardBreak[i] then
  423. ---选中主卡才刷新牌库,后续不刷新,防止刷新导致list位置重置
  424. if self.needRefreshHouseList then
  425. self:RefreshScrollView(self.selectCardBreak[i].cfgid)
  426. self.needRefreshHouseList = false
  427. end
  428. return
  429. end
  430. end
  431. ---无卡时需要刷新全部卡牌
  432. self.needRefreshHouseList = true
  433. self:RefreshScrollView(nil, true)
  434. end
  435. function this:RefreshBreakRedPoint()
  436. self.red_1 = false
  437. self.red_2 = false
  438. self.red_3 = false
  439. for _, v in pairs(self.normalCardInfo) do
  440. if v.type == E_ShapeShiftCardType.Attr and not self.red_1 then
  441. local cardCount = InfoManager.shapeShiftCardInfo:GetBagCardCountByCfgId(v.cfgid)
  442. if cardCount >= v.breakTbl.expend then
  443. self.red_1 = true
  444. if self.red_3 then
  445. break
  446. end
  447. end
  448. elseif v.type == E_ShapeShiftCardType.GodAttr and not self.red_3 then
  449. local cardCount = InfoManager.shapeShiftCardInfo:GetBagCardCountByCfgId(v.cfgid)
  450. if cardCount >= v.breakTbl.expend then
  451. self.red_3 = true
  452. if self.red_1 then
  453. break
  454. end
  455. end
  456. end
  457. end
  458. for _, v in pairs(self.exchangeCardInfo) do
  459. local cardCount = InfoManager.shapeShiftCardInfo:GetBagCardCountByCfgId(v.cfgid)
  460. if cardCount >= v.breakTbl.expend then
  461. self.red_2 = true
  462. break
  463. end
  464. end
  465. GUI:setVisible(self.view.img_redPoint_shift, self.red_2)
  466. GUI:setVisible(self.view.img_redPoint_attr, self.red_1)
  467. GUI:setVisible(self.view.img_redPoint_god_attr, self.red_3)
  468. end
  469. function this:RES_CARD_BREAKTHROUGH_FAIL()
  470. GUI:setVisible(self.view.img_fail, false)
  471. GUI:setVisible(self.view.img_fail, true)
  472. end
  473. function this:Close()
  474. if self.timer then
  475. SL:UnSchedule(self.timer)
  476. self.timer = nil
  477. end
  478. self.cardItemList = nil
  479. self.selectCardInfo = nil
  480. self.normalCardInfo = nil
  481. self.cardBreakList = nil
  482. self.selectCardBreak = nil
  483. end
  484. return this