KLEquipJewelryPanel.lua 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. ---@class KLEquipJewelryPanel:UIKmlLuaPanelBase
  2. ---@field view KLEquipJewelryPanelView
  3. local KLEquipJewelryPanel = class(UIKmlLuaPanelBase)
  4. local this = KLEquipJewelryPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. self.equipPanel = GUI:UIPanel_Open("dev/ui/Equip/Panel/KLEquipUI/KLEquipUIPanel", nil, nil,
  8. { x = -465, hideTips = true, callBack = self.CloseEquipUi,forgeGroupType=EForgeGroupType.Jewelry})
  9. self.OrnamentsGroupList = {}
  10. local ornamentsTbl = SL:GetConfigTable('cfg_equip_ornaments')
  11. for _, v in pairs(ornamentsTbl) do
  12. if not self.OrnamentsGroupList[v.ornamentsGroup] then
  13. self.OrnamentsGroupList[v.ornamentsGroup] = {}
  14. end
  15. table.insert(self.OrnamentsGroupList[v.ornamentsGroup], v)
  16. end
  17. self.AttTextList = {}
  18. GUI:DataListInitData(self.view.Attr_list, function()
  19. return table.count(self.AttTextList)
  20. end, function()
  21. end, function()
  22. end, function(realIndex)
  23. local strengthInfo = self.AttTextList[realIndex + 1]
  24. local name = strengthInfo['attrName']
  25. local preValue = strengthInfo['preValue']
  26. local nextValue = strengthInfo['nextValue']
  27. local arrowShow = strengthInfo['arrowShow']
  28. local attControl = GUI:GetChildControl(self.view.Attr_list, realIndex, 'attrName')
  29. local preControl = GUI:GetChildControl(self.view.Attr_list, realIndex, 'preValue')
  30. local nextControl = GUI:GetChildControl(self.view.Attr_list, realIndex, 'nextValue')
  31. local arrowControl = GUI:GetChildControl(self.view.Attr_list, realIndex, 'attrArrow')
  32. GUI:Text_setString(attControl, name)
  33. GUI:Text_setString(preControl, tostring(preValue))
  34. GUI:Text_setString(nextControl, tostring(nextValue))
  35. GUI:setVisible(arrowControl, arrowShow)
  36. end)
  37. self.ExceAttTextList = {}
  38. GUI:DataListInitData(self.view.Exce_list, function()
  39. return table.count(self.ExceAttTextList)
  40. end, function()
  41. end, function()
  42. end, function(realIndex)
  43. local strengthInfo = self.ExceAttTextList[realIndex + 1]
  44. local attrName = strengthInfo['attrName']
  45. local lv = strengthInfo['lv']
  46. local attrValue = strengthInfo['attrValue']
  47. local isActive = strengthInfo['isActive']
  48. local isUnlock = strengthInfo['isUnlock']
  49. local attShow = strengthInfo['attShow']
  50. local nameControl = GUI:GetChildControl(self.view.Exce_list, realIndex, 'ExceAttrName')
  51. local BtnControl = GUI:GetChildControl(self.view.Exce_list, realIndex, 'ExceActiveBtn')
  52. local LockControl = GUI:GetChildControl(self.view.Exce_list, realIndex, 'ExceLock')
  53. local activeTextControl = GUI:GetChildControl(self.view.Exce_list, realIndex, 'ActiveText')
  54. local exceActiveBtnRedPoint = GUI:GetChildControl(self.view.Exce_list, realIndex, 'ExceActiveBtnRedPoint')
  55. GUI:SetActive(exceActiveBtnRedPoint,InfoManager.equipJewelryInfo:IsJewelryCanActive(self.equipInfo))
  56. if isActive then
  57. GUI:SetActive(LockControl, false)
  58. GUI:SetActive(BtnControl, false)
  59. GUI:SetActive(activeTextControl, true)
  60. if attShow == 0 then
  61. GUI:Text_setString(nameControl, string.format('<color="#4BA7E8">%s</color>', attrName))
  62. else
  63. GUI:Text_setString(nameControl, string.format('<color="#4BA7E8">%s</color>', attrName .. " +" .. attrValue))
  64. end
  65. GUI:Text_setString(activeTextControl, string.format('<color="#2a8430">%s</color>', ""))
  66. else
  67. if isUnlock then
  68. GUI:SetActive(LockControl, false)
  69. GUI:SetActive(BtnControl, true)
  70. else
  71. GUI:SetActive(LockControl, true)
  72. GUI:SetActive(BtnControl, false)
  73. end
  74. GUI:SetActive(activeTextControl, false)
  75. if attShow == 0 then
  76. GUI:Text_setString(nameControl, string.format('<color="#9b9b9b">%s</color>', attrName))
  77. else
  78. GUI:Text_setString(nameControl, string.format('<color="#9b9b9b">%s</color>', attrName .. " +" .. attrValue))
  79. end
  80. end
  81. GUI:AddOnClickEvent(BtnControl, self, self.ActiveBtn, { ExceAttTextList = self.ExceAttTextList, preLevel = self.preLevel, equipInfo = self.equipInfo })
  82. end)
  83. self.costList = {}
  84. GUI:DataListInitData(self.view.cost_List, function()
  85. return table.count(self.costList)
  86. end, function()
  87. end, function()
  88. end, function(realIndex)
  89. local costInfo = self.costList[realIndex + 1]
  90. local cfgId = costInfo['cfgId']
  91. local needCount = costInfo['needCount']
  92. local itemControl = GUI:GetChildControl(self.view.cost_List, realIndex, 'cost_item')
  93. local nameControl = GUI:GetChildControl(self.view.cost_List, realIndex, 'cost_name')
  94. local numControl = GUI:GetChildControl(self.view.cost_List, realIndex, 'cost_num')
  95. local costAddBtn = GUI:GetChildControl(self.view.cost_List, realIndex, 'costAddBtn')
  96. if SL:GetConfig('cfg_item', cfgId) == nil then
  97. return
  98. end
  99. GUI:Item_setItemId(itemControl, cfgId)
  100. local name = SL:GetConfig('cfg_item', cfgId).name
  101. GUI:Text_setString(nameControl, name)
  102. local haveCount = SL:GetBagItemCount(cfgId)
  103. if haveCount < needCount then
  104. GUI:Text_setString(numControl, string.format('<color="#9b1818">%d</color>/%d', haveCount, needCount))
  105. else
  106. GUI:Text_setString(numControl, string.format('<color="#5CE366FF">%d</color>/%d', haveCount, needCount))
  107. end
  108. GUI:AddOnClickEvent(costAddBtn, self, self.costAddBtn, { cfgId = cfgId })
  109. end)
  110. end
  111. function this:costAddBtn(control, eventData)
  112. local cfgId = eventData.cfgId
  113. SL:CommonItemGetPath(nil, cfgId)
  114. end
  115. function this:ActiveBtn(control, eventData)
  116. GUI:UIPanel_Open("dev/outui/Equip/Panel/KLEquipJewelryActive/KLEquipJewelryActivePanel", nil, nil,
  117. { ExceAttTextList = eventData.ExceAttTextList, preLevel = eventData.preLevel, equipInfo = eventData.equipInfo })
  118. end
  119. function this.CloseEquipUi()
  120. GUI:UIPanel_Close("dev/ui/UIForgeGroup/Panel/KLUIForgeGroup/KLUIForgeGroupPanel")
  121. GUI:UIPanel_Close("dev/ui/Equip/Panel/KLEquipUI/KLEquipUIPanel")
  122. GUI:UIPanel_Close("dev/outui/Equip/Panel/KLEquipJewelry/KLEquipJewelryPanel")
  123. end
  124. ---创建或者刷新界面数据时调用
  125. function this:Refresh()
  126. GUI:setVisible(self.view.bg2, false)
  127. GUI:setVisible(self.view.tips, true)
  128. local equipAll = SL:GetMetaValue(EMetaVarGetKey.EQUIP_DATA)
  129. if equipAll and equipAll[1] and next(equipAll[1]) then
  130. for i, v in pairs(equipAll[1]) do
  131. for _, j in pairs(E_JewelryEquipType) do
  132. if i == j then
  133. self:LUA_EVENT_EQUIP_GRID_CLICK(_, i)
  134. return
  135. end
  136. end
  137. end
  138. end
  139. end
  140. ---注册UI事件和服务器消息
  141. function this:RegistEvents()
  142. SL:RegisterLUAEvent(LUA_EVENT_EQUIP_GRID_CLICK, self.LUA_EVENT_EQUIP_GRID_CLICK, self)
  143. GUI:AddOnClickEvent(self.view.CloseBtn, self, self.CloseEquipUi)
  144. GUI:AddOnClickEvent(self.view.LevelButton, self, self.LevelButtonOnClick)
  145. GUI:AddOnClickEvent(self.view.item_model, self, self.item_modelOnClick)
  146. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_UPDATE_EQUIP_ORNAMENTS, self.RES_UPDATE_EQUIP_ORNAMENTS, self)
  147. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_ACT_EQUIP_ORNAMENTS, self.RES_ACT_EQUIP_ORNAMENTS, self)
  148. --SL:RegisterLUAEvent(LUA_EVENT_BAG_CHANGE_AFTER, self.LUA_EVENT_BAG_CHANGE_AFTER, self)
  149. --SL:RegisterLUAEvent(LUA_EVENT_MONEYCHANGE, self.LUA_EVENT_MONEYCHANGE, self)
  150. SL:RegisterLUAEvent(LUA_EVENT_FORGE_GROUP_PANEL_CLOSE, self.CloseEquipUi, self)
  151. end
  152. function this:item_modelOnClick()
  153. SL:OpenTips("equip",self.equipInfo.cfgId,self.equipInfo.id,nil, self.equipInfo, {hideBtn=true})
  154. end
  155. function this:LUA_EVENT_BAG_CHANGE_AFTER(_,message)
  156. if not message then
  157. return
  158. end
  159. if not self.equipInfo then
  160. return
  161. end
  162. ----加载升级消耗
  163. self:SetLevelUpCost(self.equipInfo, self.preLevel)
  164. self.equipPanel:UpdateAllItem()
  165. GUI:DataListUpdateData(self.view.Exce_list)
  166. SL:RefreshPanelALLRedPoint("KLUIForgeGroupPanel")
  167. end
  168. function this:LUA_EVENT_MONEYCHANGE(_,message)
  169. if not self.equipInfo then
  170. return
  171. end
  172. ----加载升级消耗
  173. self:SetLevelUpCost(self.equipInfo, self.preLevel)
  174. self.equipPanel:UpdateAllItem()
  175. SL:RefreshPanelALLRedPoint("KLUIForgeGroupPanel")
  176. end
  177. ---@param message RES_UPDATE_EQUIP_ORNAMENTS
  178. function this:RES_ACT_EQUIP_ORNAMENTS(_, message)
  179. if message then
  180. local firstUnlock = false
  181. for _, v in pairs(self.ExceAttTextList) do
  182. for _, j in pairs(message.ssactlv) do
  183. if tonumber(j) == v.lv then
  184. v.isActive = true
  185. end
  186. end
  187. if v.isActive == false and not firstUnlock then
  188. ---第一个未激活的解锁
  189. firstUnlock = true
  190. v.isUnlock = true
  191. end
  192. end
  193. GUI:DataListUpdateData(self.view.Exce_list)
  194. SL:onLUAEvent(LUA_EVENT_JEWELRY_CHANGE,self.equipInfo)
  195. SL:RefreshPanelALLRedPoint("KLUIForgeGroupPanel")
  196. self.equipPanel:UpdateAllItem()
  197. end
  198. end
  199. ---@param message RES_UPDATE_EQUIP_ORNAMENTS
  200. function this:RES_UPDATE_EQUIP_ORNAMENTS(_, message)
  201. GUI:setVisible(self.view.success_ok, false)
  202. if message then
  203. GUI:setVisible(self.view.success_ok, true)
  204. if self.equipInfo.id == message.itemId then
  205. self.OutEquipData = message
  206. end
  207. self:ClickEquip(self.equipInfo)
  208. SL:onLUAEvent(LUA_EVENT_JEWELRY_CHANGE,self.equipInfo)
  209. SL:RefreshPanelALLRedPoint("KLUIForgeGroupPanel")
  210. self.equipPanel:UpdateAllItem()
  211. end
  212. end
  213. function this:LevelButtonOnClick()
  214. if not self.isHaveLevelCount then
  215. SL:TipMessage( SL:GetConfig('cfg_string', 260).text, 1, NoticeType.NoticeMid )--"材料不足!",
  216. SL:CommonItemGetPath(nil, self.levelCfgId)
  217. else
  218. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_UPDATE_EQUIP_ORNAMENTS, { itemId = self.equipInfo.id })
  219. end
  220. end
  221. function this:LUA_EVENT_EQUIP_GRID_CLICK(_, index)
  222. ---@type CommonProtos.Item
  223. local equip = SL:GetMetaValue("EQUIP_TARGET_DATA", 1, index)
  224. if index == E_AppearEquipType.Weapon and equip == nil then
  225. equip = SL:GetMetaValue("EQUIP_TARGET_DATA", 1, E_AppearEquipType.TwoHandWeapon)
  226. end
  227. if equip then
  228. ---@type RES_UPDATE_EQUIP_ORNAMENTS
  229. self.OutEquipData = SL:JsonDecode(equip.luaExtData,false)---json.decode(equip.luaExtData)
  230. if SL:HasConfig('cfg_equip_ornamentsMain', equip['cfgId']) then
  231. local ornament_tbl = SL:GetConfig('cfg_equip_ornamentsMain', equip['cfgId'])
  232. if ornament_tbl then
  233. self.equipPanel:SetSelectIndex(index)
  234. self.equipInfo = equip
  235. self:ClickEquip(equip)
  236. return
  237. end
  238. else
  239. SL:TipMessage( SL:GetConfig('cfg_string', 261).text, 1, NoticeType.NoticeMid )--"请选择首饰装备!",
  240. end
  241. end
  242. end
  243. ---@param equipInfo CommonProtos.Item
  244. function this:ClickEquip(equipInfo)
  245. if self.OutEquipData == nil or (self.OutEquipData and not self.OutEquipData.ssuplv) then
  246. self.preLevel = 0
  247. else
  248. self.preLevel = tonumber(self.OutEquipData.ssuplv)
  249. end
  250. local PreOrnament_Tbl = self:GetJewelryTblInfoByLevel(equipInfo.cfgId, self.preLevel)
  251. local NextOrnament_Tbl = self:GetJewelryTblInfoByLevel(equipInfo.cfgId, self.preLevel + 1)
  252. ---@type cfg_item_column
  253. local itemTbl = SL:GetConfig("cfg_item", equipInfo.cfgId)
  254. if PreOrnament_Tbl then
  255. local nextLevel = ""
  256. if NextOrnament_Tbl then
  257. nextLevel = self.preLevel + 1
  258. end
  259. GUI:setVisible(self.view.bg2, true)
  260. GUI:setVisible(self.view.tips, false)
  261. if nextLevel == "" then
  262. GUI:Text_setString(self.view.preLevel, "+" .. self.preLevel)
  263. GUI:Text_setString(self.view.nextLevel, "")
  264. GUI:SetActive(self.view.arrow, false)
  265. GUI:SetActive(self.view.Material, false)
  266. GUI:SetActive(self.view.LevelButton, false)
  267. GUI:SetActive(self.view.maxLevelTips, true)
  268. GUI:SetActive(self.view.maxLevelTips, true)
  269. else
  270. GUI:Text_setString(self.view.preLevel, "+" .. self.preLevel)
  271. GUI:Text_setString(self.view.nextLevel, "+" .. nextLevel)
  272. GUI:SetActive(self.view.arrow, true)
  273. GUI:SetActive(self.view.Material, true)
  274. GUI:SetActive(self.view.LevelButton, true)
  275. GUI:SetActive(self.view.maxLevelTips, false)
  276. ----加载升级消耗
  277. self:SetLevelUpCost(equipInfo, self.preLevel)
  278. end
  279. GUI:Text_setString(self.view.equipName, itemTbl.name .. "(" .. self.preLevel .. "级)")
  280. ---@type cfg_color_column
  281. local colorCfg = SL:GetConfig("cfg_color",itemTbl.color)
  282. GUI:Text_setTextColor(self.view.equipName, colorCfg.color)
  283. ----加载上面模型
  284. self:SetEquipModel(equipInfo.cfgId)
  285. ----加载基础属性
  286. self:SetAttrInfo(PreOrnament_Tbl, NextOrnament_Tbl)
  287. ----加载卓越属性
  288. self:SetExcellenceAttrInfo(equipInfo.cfgId)
  289. end
  290. end
  291. function this:SetEquipModel(cfgId)
  292. GUI:setVisible(self.view.item_model, true)
  293. GUI:Item_setItemId(self.view.item_model, cfgId)
  294. GUI:setScale(self.view.item_model,2)
  295. GUI:setPosition(self.view.item_model,0,-50)
  296. end
  297. function this:SetLevelUpCost(equipInfo, level)
  298. self.costList = {}
  299. self.isHaveLevelCount = true
  300. local ornament_tbl = self:GetJewelryTblInfoByLevel(equipInfo.cfgId, level)
  301. if next(ornament_tbl.lvDeplete) then
  302. for _, attrValue in pairs(ornament_tbl.lvDeplete) do
  303. local tbl = {}
  304. tbl = {
  305. cfgId = tonumber(attrValue[1]),
  306. needCount = tonumber(attrValue[2])
  307. }
  308. local haveCount = SL:GetBagItemCount(tbl.cfgId)
  309. local needCount = tbl.needCount
  310. if haveCount < needCount then
  311. self.isHaveLevelCount = false
  312. self.levelCfgId = tbl.cfgId
  313. end
  314. table.insert(self.costList, tbl)
  315. end
  316. end
  317. GUI:SetActive(self.view.LevelButtonRedPoint,
  318. InfoManager.equipJewelryInfo:IsJewelryCanUpLevel(self.equipInfo))
  319. GUI:DataListUpdateData(self.view.cost_List)
  320. end
  321. function this:SetExcellenceAttrInfo(cfgId)
  322. self.ExceAttTextList = {}
  323. local firstUnlock = false
  324. local ornament_tbl = SL:GetConfig('cfg_equip_ornamentsMain', cfgId)
  325. if ornament_tbl.ornamentsGroup and self.OrnamentsGroupList[ornament_tbl.ornamentsGroup] then
  326. for i, v in pairs(self.OrnamentsGroupList[ornament_tbl.ornamentsGroup]) do
  327. if next(v.excellenceAtt) then
  328. for _, attrValue in pairs(v.excellenceAtt) do
  329. local attrName = SL:GetConfig("cfg_att_info", tonumber(attrValue[1])).name
  330. local att_remark = SL:GetConfig("cfg_att_info", tonumber(attrValue[1])).remarks
  331. local att_show = SL:GetConfig("cfg_att_info", tonumber(attrValue[1])).attShow
  332. local att_Value = attrValue[2]
  333. local isActive = false --是否激活
  334. local isUnlock = false ---是否解锁
  335. if self.OutEquipData and self.OutEquipData.ssactlv then
  336. for _, data in pairs(self.OutEquipData.ssactlv) do
  337. if tonumber(data) == v.lv then
  338. isActive = true
  339. end
  340. end
  341. end
  342. if isActive == false and not firstUnlock then
  343. ---第一个未激活的解锁
  344. firstUnlock = true
  345. isUnlock = true
  346. end
  347. local tbl = {}
  348. if att_remark == 1 then
  349. tbl = {
  350. attrName = attrName,
  351. attrValue = tostring(att_Value),
  352. lv = v.lv,
  353. unlockDeplete = v.unlockDeplete,
  354. isActive = isActive,
  355. isUnlock = isUnlock,
  356. attShow = att_show
  357. }
  358. else
  359. tbl = {
  360. attrName = attrName,
  361. attrValue = tonumber(att_Value) / 100 .. '%',
  362. lv = v.lv,
  363. unlockDeplete = v.unlockDeplete,
  364. isActive = isActive,
  365. isUnlock = isUnlock,
  366. attShow = att_show
  367. }
  368. end
  369. table.insert(self.ExceAttTextList, tbl)
  370. end
  371. end
  372. end
  373. end
  374. GUI:DataListUpdateData(self.view.Exce_list)
  375. end
  376. function this:SetAttrInfo(PreOrnament_Tbl, NextOrnament_Tbl)
  377. self.AttTextList = {}
  378. local AtkSpecialTbl=InfoManager.equipJewelryInfo:GetAttrJewelSpecialTbl(ESpecialAttrID.minAtk,ESpecialAttrID.maxAtk,PreOrnament_Tbl, NextOrnament_Tbl,"攻 击 力")
  379. if AtkSpecialTbl then
  380. table.insert(self.AttTextList, AtkSpecialTbl)
  381. end
  382. for _, attrValue in pairs(PreOrnament_Tbl.basicAtt) do
  383. local attrId = attrValue[1]
  384. if not InfoManager.equipJewelryInfo:IsSpecialAttrId(attrId) then
  385. local name = SL:GetConfig("cfg_att_info", tonumber(attrId)).name
  386. local att_remark = SL:GetConfig("cfg_att_info", tonumber(attrId)).remarks
  387. local att_Value = attrValue[2]
  388. local NextAttrValue = ""
  389. local arrowShow = true
  390. if NextOrnament_Tbl then
  391. for _, nextAttrvalue in pairs(NextOrnament_Tbl.basicAtt) do
  392. if tonumber(nextAttrvalue[1]) == tonumber(attrValue[1]) then
  393. NextAttrValue = nextAttrvalue[2]
  394. end
  395. end
  396. end
  397. if NextAttrValue == "" then
  398. arrowShow = false
  399. end
  400. local tbl = {}
  401. if att_remark == 1 then
  402. tbl = {
  403. attrName = name,
  404. preValue = att_Value,
  405. nextValue = NextAttrValue,
  406. arrowShow = arrowShow
  407. }
  408. else
  409. tbl = {
  410. attrName = name,
  411. preValue = tonumber(att_Value) / 100 .. '%',
  412. nextValue = NextAttrValue,
  413. arrowShow = arrowShow
  414. }
  415. end
  416. table.insert(self.AttTextList, tbl)
  417. end
  418. end
  419. GUI:DataListUpdateData(self.view.Attr_list)
  420. end
  421. ---@return cfg_equip_ornaments_column
  422. function this:GetJewelryTblInfoByLevel(cfgId, Level)
  423. ---@type cfg_equip_ornamentsMain_column
  424. local ornament_tbl = SL:GetConfig('cfg_equip_ornamentsMain', cfgId)
  425. if ornament_tbl.ornamentsGroup and self.OrnamentsGroupList[ornament_tbl.ornamentsGroup] then
  426. for _, v in pairs(self.OrnamentsGroupList[ornament_tbl.ornamentsGroup]) do
  427. if v.lv == tonumber(Level) then
  428. return v
  429. end
  430. end
  431. end
  432. return nil
  433. end
  434. function this:Close()
  435. if self.coHide ~= nil then
  436. Coroutine.Stop(self.coHide)
  437. end
  438. GUI:UIPanel_Close("dev/outui/Equip/Panel/KLEquipJewelryActive/KLEquipJewelryActivePanel")
  439. end
  440. return this