KLShapeShiftCardInlayPanel.lua 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. ---@class KLShapeShiftCardInlayPanel:UIKmlLuaPanelBase
  2. ---@field view KLShapeShiftCardInlayPanelView
  3. local KLShapeShiftCardInlayPanel = class(UIKmlLuaPanelBase)
  4. local this =KLShapeShiftCardInlayPanel
  5. ---@class EquipPartCardInfo
  6. ---@field luck number
  7. ---@field unlock boolean
  8. ---@field card number
  9. ---卡牌装备部位
  10. local EquipParts = {1,2,3,4,5,6,7,8,9,10,11,12,13}
  11. ---卡牌装备部位坐标
  12. local PartsPos = {
  13. [1] = {-340, 51},
  14. [2] = {-340, -52},
  15. [3] = {-340, 51},
  16. [4] = {-443, 149},
  17. [6] = {-443, 51},
  18. [7] = {-443, -52},
  19. [8] = {-443, -150},
  20. [5] = {329, 50},
  21. [9] = {330, -51},
  22. [10] = {429, 151},
  23. [11] = {429, 50},
  24. [12] = {429, -52},
  25. [13] = {429, -151},
  26. }
  27. function this:AsyncLoadUI()
  28. end
  29. ---创建时调用一次
  30. function this:Init()
  31. GUI:OSAScrollView_Initialized(self.view.osa_card_list, self.CardItemGetFun, self.CardItemUpdateFun, self)
  32. GUI:OSAScrollView_Initialized(self.view.osa_card_house_list, self.CardItemGetFun_2,self.CardItemUpdateFun_2, self)
  33. GUI:OSAScrollView_Initialized(self.view.osa_attr_list_left, nil,self.CardAttrLeftUpdateFun, self)
  34. GUI:OSAScrollView_Initialized(self.view.osa_attr_list_right, nil,self.CardAttrRightUpdateFun, self)
  35. end
  36. function this:CardItemGetFun()
  37. return GUI:UIPanel_Open("dev/outui/ShapeShiftCard/Item/KLShapeShiftCard/KLShapeShiftCardItem", nil, self, { type = E_ShapeShiftCardFuncType.UnInlay }, true)
  38. end
  39. ---@param item KLShapeShiftCardItem
  40. ---@param index number
  41. function this:CardItemUpdateFun(item,index)
  42. local partInfo = self.allPartsInfo[self.part]
  43. local cardInfo = partInfo[index + 1]
  44. item:RefreshUnInlayItem(cardInfo, index + 1, self.part, partInfo)
  45. end
  46. function this:CardItemGetFun_2()
  47. return GUI:UIPanel_Open("dev/outui/ShapeShiftCard/Item/KLShapeShiftCard/KLShapeShiftCardItem", nil, self, { type = E_ShapeShiftCardFuncType.Inlay }, true)
  48. end
  49. ---@param item KLShapeShiftCardItem
  50. ---@param index number
  51. function this:CardItemUpdateFun_2(item,index)
  52. item:RefreshBagItem(self.selectPartCardInfo[index + 1])
  53. end
  54. function this:CardAttrLeftUpdateFun(item, index)
  55. local text_attr_name = GUI:GetChildById(item, "text_attr_name")
  56. local text_attr_value = GUI:GetChildById(item, "text_attr_value")
  57. local info = self.allAttrTbl[index + 1]
  58. ---@type cfg_att_info_column
  59. local tbl = SL:GetConfig("cfg_att_info", info.attr)
  60. local name = tbl.name
  61. if info.value2 then
  62. name = "攻击力"
  63. end
  64. if info.active then
  65. GUI:Text_setString(text_attr_name, name .. ":")
  66. GUI:Text_setTextColor(text_attr_name, "#DCE1E5")
  67. GUI:Text_setTextColor(text_attr_value, "#DCE1E5")
  68. else
  69. GUI:Text_setString(text_attr_name, name .. ":(未激活)")
  70. GUI:Text_setTextColor(text_attr_name, "#999999")
  71. GUI:Text_setTextColor(text_attr_value, "#999999")
  72. end
  73. if info.value2 then
  74. if info.value2 > info.value then
  75. GUI:Text_setString(text_attr_value, info.value .. "~" .. info.value2)
  76. else
  77. GUI:Text_setString(text_attr_value, info.value2 .. "~" .. info.value)
  78. end
  79. else
  80. if tbl.remarks == 1 then
  81. GUI:Text_setString(text_attr_value, tostring(info.value))
  82. else
  83. local value = info.value / 100
  84. GUI:Text_setString(text_attr_value, value .. "%")
  85. end
  86. end
  87. end
  88. function this:CardAttrRightUpdateFun(item, index)
  89. local text_skill_name = GUI:GetChildById(item, "text_skill_name")
  90. local info = self.allSkillTbl[index + 1]
  91. local text = "Lv." .. info.level .. " " .. info.name
  92. if info.active then
  93. GUI:Text_setString(text_skill_name, text)
  94. if info.quality == 1 then
  95. GUI:Text_setTextColor(text_skill_name, "#4CC5FE")
  96. elseif info.quality == 2 then
  97. GUI:Text_setTextColor(text_skill_name, "#E6E600")
  98. elseif info.quality == 3 then
  99. GUI:Text_setTextColor(text_skill_name, "#FF2323")
  100. end
  101. else
  102. GUI:Text_setString(text_skill_name, text .. "(未激活)")
  103. GUI:Text_setTextColor(text_skill_name, "#999999")
  104. end
  105. end
  106. ---注册UI事件和服务器消息
  107. function this:RegistEvents()
  108. for _, v in pairs(EquipParts) do
  109. local partBtn = self.view["equip_part_" .. v]
  110. GUI:AddOnClickEvent(partBtn, self, self.OnClickEquipPart, v)
  111. end
  112. GUI:AddOnClickEvent(self.view.btn_card_close, self, self.CloseCardHouse)
  113. GUI:AddOnClickEvent(self.view.btn_go, self, self.SwitchCardShop)
  114. GUI:AddOnClickEvent(self.view.btn_tips, self, self.FuncTips)
  115. GUI:AddOnClickEvent(self.view.btn_tips_2, self, self.FuncTips_2)
  116. --SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_TRANSFER_CARD_PART_INFO, self.RES_TRANSFER_CARD_PART_INFO, self)
  117. SL:RegisterLUAEvent(LUA_SHAPE_CARD_BAG_CHANGE, self.RES_TRANSFER_CARD_BAG, self)
  118. SL:RegisterLUAEvent(LUA_SHAPE_CARD_PART_INFO_CHANGE, self.RES_TRANSFER_CARD_PART_INFO, self)
  119. --SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_TRANSFER_CARD_BAG, self.RES_TRANSFER_CARD_BAG, self)
  120. end
  121. ---刷新卡牌镶嵌栏
  122. function this:OnClickEquipPart(_,part)
  123. self.part = part
  124. GUI:setPosition(self.view.img_equip_part_select, PartsPos[part][1], PartsPos[part][2])
  125. if self.equip and self.equip[1] and self.equip[1][part] then
  126. GUI:setVisible(self.view.panel_lapse, false)
  127. else
  128. GUI:setVisible(self.view.panel_lapse, true)
  129. end
  130. ---刷新默认镶嵌槽位
  131. self.selectIndex = 0
  132. for i, v in pairs(self.allPartsInfo[self.part]) do
  133. if v.unlock and (not v.card or v.card == 0) then
  134. self.selectIndex = i
  135. break
  136. end
  137. end
  138. self:CloseCardHouse()
  139. self:RefreshCardHouseList()
  140. end
  141. ---界面显示时调用一次
  142. function this:Show()
  143. end
  144. ---创建或者刷新界面数据时调用
  145. function this:Refresh()
  146. ---@type BagShapeShiftCard[]
  147. self.allCardInfo = InfoManager.shapeShiftCardInfo.allCardInfo
  148. ---@type ShapeShiftMessage[]
  149. self.allPartsInfo = InfoManager.shapeShiftCardInfo.allPartsInfo
  150. self:RefreshRoleEquip()
  151. ---当职业为弓箭手或使用双手武器时,使用双手武器槽位
  152. if SL:GetMetaValue(EMetaVarGetKey.JOB) == 3 or (self.equip and self.equip[1] and self.equip[1][3]) then
  153. GUI:setVisible(self.view.equip_part_1, false)
  154. GUI:setVisible(self.view.equip_part_3, true)
  155. self:OnClickEquipPart(nil, 3)
  156. else
  157. GUI:setVisible(self.view.equip_part_1, true)
  158. GUI:setVisible(self.view.equip_part_3, false)
  159. self:OnClickEquipPart(nil, 1)
  160. end
  161. self:RefreshAllPartRedPointInfo()
  162. self:RefreshAllPartAttrInfo()
  163. end
  164. ---刷新装备栏装备
  165. function this:RefreshRoleEquip()
  166. self.equip = SL:GetTotalWearEquips()
  167. if self.equip[1] then
  168. for _, v in pairs(EquipParts) do
  169. local tbl = SL:GetConfig("cfg_card_inlay", v)
  170. GUI:Image_loadTexture(self.view["item_equip_type_" ..v], "icon_type_" .. tbl.type, "Atlas/KLShapeShiftCard.spriteatlas")
  171. if self.equip[1][v] then
  172. GUI:setVisible(self.view["item_equip_" .. v], true)
  173. GUI:Item_setItemId(self.view["item_equip_" .. v], self.equip[1][v].cfgId)
  174. else
  175. GUI:setVisible(self.view["item_equip_" .. v], false)
  176. end
  177. end
  178. end
  179. end
  180. function this:OpenCardHouse(index)
  181. self:RefreshSelectIndex(index)
  182. GUI:setVisible(self.view.panel_cards, true)
  183. GUI:setVisible(self.view.layout_all_attr, false)
  184. end
  185. ---当前选中卡牌下标
  186. function this:RefreshSelectIndex(index)
  187. self.selectIndex = index
  188. end
  189. function this:CloseCardHouse()
  190. GUI:setVisible(self.view.panel_cards, false)
  191. GUI:setVisible(self.view.layout_all_attr, true)
  192. end
  193. ---当前部位卡牌参数变化刷新
  194. function this:RES_TRANSFER_CARD_PART_INFO(_, eventData)
  195. self:OnClickEquipPart(_, eventData)
  196. self:RefreshAllPartAttrInfo()
  197. self:RefreshAllPartRedPointInfo()
  198. end
  199. function this:SwitchCardShop()
  200. local ui = GUI:GetUI("dev/outui/ShapeShiftCard/Panel/KLShapeShiftCardMain/KLShapeShiftCardMainPanel")
  201. if ui then
  202. GUI:Toggle_setIsOn(ui.view.toggle_shop, true)
  203. end
  204. end
  205. function this:FuncTips()
  206. local helpCfg = SL:GetConfig("cfg_rule_text", 101)
  207. if helpCfg then
  208. SL:CommonStrTipsMessage({ title = helpCfg.menutxt, str = helpCfg.location })
  209. end
  210. end
  211. function this:FuncTips_2()
  212. local helpCfg = SL:GetConfig("cfg_rule_text", 104)
  213. if helpCfg then
  214. SL:CommonStrTipsMessage({ title = helpCfg.menutxt, str = helpCfg.location })
  215. end
  216. end
  217. ---刷新卡牌属性
  218. function this:RefreshAllPartAttrInfo()
  219. self.allAttrTbl = {}
  220. local lockSkillTbl = {}
  221. local unlockSkillTbl = {}
  222. for i, v in pairs(self.allPartsInfo) do
  223. ---@param k ShapeShiftCardMessage
  224. for _, k in ipairs(v) do
  225. if k.card and table.count(k.card) > 0 then
  226. local active
  227. if self.equip and self.equip[1] and self.equip[1][i] then
  228. active = true
  229. else
  230. active = false
  231. end
  232. local tbl_attr = {}
  233. ---左侧属性list
  234. ---@type cfg_card_shapeshift_column
  235. local tbl = SL:GetConfig("cfg_card_shapeshift", k.card.cfgid)
  236. for _, vv in pairs(tbl.attribute) do
  237. tbl_attr[#tbl_attr + 1] = { vv[1], vv[2] }
  238. end
  239. for _, vv in pairs(k.card.entry) do
  240. tbl_attr[#tbl_attr + 1] = { vv.attrid, vv.attrvalue }
  241. end
  242. for _, n2 in pairs(tbl_attr) do
  243. local set = false
  244. for _, n in pairs(self.allAttrTbl) do
  245. if n2[1] == n.attr and active == n.active then
  246. n.value = n.value + n2[2]
  247. set = true
  248. end
  249. end
  250. if not set then
  251. ---@type cfg_att_info_column
  252. local attTbl = SL:GetConfig("cfg_att_info", n2[1])
  253. local info = {}
  254. info.attr = n2[1]
  255. info.value = n2[2]
  256. info.active = active
  257. info.sort = attTbl.sort
  258. self.allAttrTbl[#self.allAttrTbl + 1] = info
  259. end
  260. end
  261. ---右侧技能list
  262. if #tbl.skill > 0 then
  263. if active then
  264. if unlockSkillTbl[tbl.group] then
  265. if unlockSkillTbl[tbl.group].level < tbl.level then
  266. unlockSkillTbl[tbl.group].level = tbl.level
  267. unlockSkillTbl[tbl.group].id = tbl.id
  268. unlockSkillTbl[tbl.group].quality = tbl.quality
  269. end
  270. else
  271. local info = {}
  272. info.id = tbl.id
  273. info.name = tbl.name
  274. info.level = tbl.level
  275. info.quality = tbl.quality
  276. unlockSkillTbl[tbl.group] = info
  277. end
  278. else
  279. if lockSkillTbl[tbl.group] then
  280. if lockSkillTbl[tbl.group].level < tbl.level then
  281. lockSkillTbl[tbl.group].level = tbl.level
  282. lockSkillTbl[tbl.group].id = tbl.id
  283. lockSkillTbl[tbl.group].quality = tbl.quality
  284. end
  285. else
  286. local info = {}
  287. info.id = tbl.id
  288. info.name = tbl.name
  289. info.level = tbl.level
  290. info.quality = tbl.quality
  291. lockSkillTbl[tbl.group] = info
  292. end
  293. end
  294. end
  295. end
  296. end
  297. end
  298. table.sort(self.allAttrTbl, function(a, b)
  299. if a.active == b.active then
  300. return a.sort < b.sort
  301. else
  302. return a.active
  303. end
  304. end)
  305. ---攻击力属性合并
  306. local indexActive, specialAttrActive, index, specialAttr
  307. for i, v in pairs(self.allAttrTbl) do
  308. if v.attr == 201021 then
  309. if v.active then
  310. if not specialAttrActive then
  311. specialAttrActive = v.value
  312. indexActive = i
  313. else
  314. v.value2 = specialAttrActive
  315. end
  316. else
  317. if not specialAttr then
  318. specialAttr = v.value
  319. index = i
  320. else
  321. v.value2 = specialAttr
  322. end
  323. end
  324. elseif v.attr == 201011 then
  325. if v.active then
  326. if not specialAttrActive then
  327. specialAttrActive = v.value
  328. indexActive = i
  329. else
  330. v.value2 = specialAttrActive
  331. end
  332. else
  333. if not specialAttr then
  334. specialAttr = v.value
  335. index = i
  336. else
  337. v.value2 = specialAttr
  338. end
  339. end
  340. end
  341. end
  342. if indexActive then
  343. table.remove(self.allAttrTbl, indexActive)
  344. end
  345. if index then
  346. if indexActive then
  347. table.remove(self.allAttrTbl, index - 1)
  348. else
  349. table.remove(self.allAttrTbl, index)
  350. end
  351. end
  352. if #self.allAttrTbl > 0 then
  353. GUI:setVisible(self.view.img_left_tips, false)
  354. else
  355. GUI:setVisible(self.view.img_left_tips, true)
  356. end
  357. GUI:OSAScrollView_RefreshList(self.view.osa_attr_list_left, #self.allAttrTbl)
  358. for i, v in pairs(unlockSkillTbl) do
  359. local info = lockSkillTbl[i]
  360. if info and info.level <= v.level then
  361. lockSkillTbl[i] = nil
  362. end
  363. end
  364. self.allSkillTbl = {}
  365. for _, v in pairs(unlockSkillTbl) do
  366. v.active = true
  367. self.allSkillTbl[#self.allSkillTbl + 1] = v
  368. end
  369. for _, v in pairs(lockSkillTbl) do
  370. v.active = false
  371. self.allSkillTbl[#self.allSkillTbl + 1] = v
  372. end
  373. table.sort(self.allSkillTbl, function(a, b)
  374. if a.active == b.active then
  375. return a.quality > b.quality
  376. else
  377. return a.active
  378. end
  379. end)
  380. if #self.allSkillTbl > 0 then
  381. GUI:setVisible(self.view.img_right_tips, false)
  382. else
  383. GUI:setVisible(self.view.img_right_tips, true)
  384. end
  385. GUI:OSAScrollView_RefreshList(self.view.osa_attr_list_right, #self.allSkillTbl)
  386. end
  387. ---把后端传过来的表key转换成number格式
  388. function this:RefreshCardPartKeyToNumber(message)
  389. if message and next(message) then
  390. local tbl = {}
  391. for i, v in pairs(message) do
  392. local tbl_1 = {}
  393. for j, k in pairs(v) do
  394. tbl_1[tonumber(j)] = k
  395. end
  396. tbl[tonumber(i)] = tbl_1
  397. end
  398. return tbl
  399. end
  400. end
  401. function this:RES_TRANSFER_CARD_BAG()
  402. ---@type BagShapeShiftCard[]
  403. self.allCardInfo = InfoManager.shapeShiftCardInfo.allCardInfo
  404. self:RefreshCardHouseList(true)
  405. self:RefreshAllPartRedPointInfo()
  406. end
  407. ---刷新镶嵌槽位与镶嵌牌库
  408. function this:RefreshCardHouseList()
  409. ---@type cfg_card_inlay_column
  410. local inlayCfg = SL:GetConfig("cfg_card_inlay", self.part)
  411. GUI:OSAScrollView_RefreshList(self.view.osa_card_list, inlayCfg.holeAmount)
  412. ---当背包变化或卡牌种类不同才刷新
  413. self.currPartType = inlayCfg.type
  414. self.selectPartCardInfo = {}
  415. if inlayCfg.type == 1 then
  416. local partInfo = self.allPartsInfo[self.part]
  417. local limitList = {}
  418. for _, v in pairs(partInfo) do
  419. if v.card and table.count(v.card) > 0 then
  420. local tbl = SL:GetConfig("cfg_card_shapeshift", v.card.cfgid)
  421. limitList[tbl.group] = true
  422. end
  423. end
  424. for _, v in ipairs(self.allCardInfo) do
  425. if inlayCfg.type == v.type and not limitList[v.group] then
  426. self.selectPartCardInfo[#self.selectPartCardInfo + 1] = v
  427. end
  428. end
  429. else
  430. for _, v in ipairs(self.allCardInfo) do
  431. if inlayCfg.type == v.type then
  432. self.selectPartCardInfo[#self.selectPartCardInfo + 1] = v
  433. end
  434. end
  435. end
  436. GUI:OSAScrollView_RefreshList(self.view.osa_card_house_list, #self.selectPartCardInfo)
  437. if #self.selectPartCardInfo > 0 then
  438. GUI:setVisible(self.view.panel_no_card, false)
  439. else
  440. GUI:setVisible(self.view.panel_no_card, true)
  441. end
  442. end
  443. ---刷新镶嵌红点
  444. function this:RefreshAllPartRedPointInfo()
  445. if self.allPartsInfo then
  446. for i, v in pairs(self.allPartsInfo) do
  447. local state = self:GetEachPartRedPointState(i, v)
  448. GUI:setVisible(self.view["item_equip_redPoint_" .. i], state)
  449. end
  450. end
  451. end
  452. ---各部位红点
  453. function this:GetEachPartRedPointState(part, partInfo)
  454. ---@type cfg_card_inlay_column
  455. local inlay = SL:GetConfig("cfg_card_inlay", tonumber(part))
  456. for j, k in pairs(partInfo) do
  457. if k.unlock then
  458. ---有卡牌可镶嵌
  459. if not k.card or table.count(k.card) == 0 then
  460. if InfoManager.shapeShiftCardInfo:GetPartHaveCardCheck(part) then
  461. return true
  462. end
  463. end
  464. else
  465. if inlay.holeAmount == #inlay.unlockFree then
  466. local rank = InfoManager.shapeShiftCardInfo:GetEquipRankByPart(part)
  467. for _, v in pairs(inlay.unlockParameter) do
  468. if j == v[1] then
  469. if rank >= v[2] then
  470. return true
  471. end
  472. end
  473. end
  474. else
  475. ---道具够解锁
  476. if inlay.unlockNormal then
  477. for _, vv in ipairs(inlay.unlockNormal) do
  478. if vv[1] == tonumber(j) then
  479. if SL:GetBagItemCount(vv[2]) >= vv[3] then
  480. return true
  481. end
  482. end
  483. end
  484. end
  485. end
  486. end
  487. end
  488. return false
  489. end
  490. function this:Close()
  491. self.selectPartCardInfo = nil
  492. self.allSkillTbl = nil
  493. self.allAttrTbl = nil
  494. self.allPartsInfo = nil
  495. self.equip = nil
  496. end
  497. return this