KLEquipJewelryActivePanel.lua 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. ---@class KLEquipJewelryActivePanel:UIKmlLuaPanelBase
  2. ---@field view KLEquipJewelryActivePanelView
  3. local KLEquipJewelryActivePanel = class(UIKmlLuaPanelBase)
  4. local this = KLEquipJewelryActivePanel
  5. ---创建时调用一次
  6. function this:Init()
  7. self.ExceAttTextList = {}
  8. GUI:DataListInitData(self.view.cost_list, function()
  9. return table.count(self.ExceAttTextList)
  10. end, function()
  11. end, function()
  12. end, function(realIndex)
  13. local strengthInfo = self.ExceAttTextList[realIndex + 1]
  14. local attrName = strengthInfo['attrName']
  15. local attrValue = strengthInfo['attrValue']
  16. local lv = strengthInfo['lv']
  17. local isActive = strengthInfo['isActive']
  18. local attShow =strengthInfo['attShow']
  19. local nameControl = GUI:GetChildControl(self.view.cost_list, realIndex, 'ExceAttrName')
  20. local textControl = GUI:GetChildControl(self.view.cost_list, realIndex, 'ExceActiveText')
  21. if isActive then
  22. if attShow == 0 then
  23. GUI:Text_setString(nameControl, string.format('<color="#4BA7E8">%s</color>', attrName))
  24. else
  25. GUI:Text_setString(nameControl, string.format('<color="#4BA7E8">%s</color>', attrName .. " +" .. attrValue))
  26. end
  27. --GUI:Text_setString(nameControl, string.format('<color="#4BA7E8">%s</color>', attrName .. " +" .. attrValue))
  28. GUI:Text_setString(textControl, string.format('<color="#2a8430">%s</color>', ""))
  29. else
  30. if attShow == 0 then
  31. GUI:Text_setString(nameControl, string.format('<color="#9b9b9b">%s</color>', attrName))
  32. else
  33. GUI:Text_setString(nameControl, string.format('<color="#9b9b9b">%s</color>', attrName .. " +" .. attrValue))
  34. end
  35. if self.preLevel < lv then
  36. GUI:Text_setString(textControl, string.format('<color="#FF2323">%s</color>', lv .. "级可激活"))
  37. else
  38. GUI:Text_setString(textControl, string.format('<color="#1ADD1F">%s</color>', "可激活"))
  39. end
  40. end
  41. end)
  42. end
  43. ---创建或者刷新界面数据时调用
  44. function this:Refresh()
  45. GUI:setPositionZ(self.view.root, -500)
  46. if self.args then
  47. self.ExceAttTextList = self.args.ExceAttTextList
  48. self.preLevel = self.args.preLevel
  49. self.equipInfo = self.args.equipInfo
  50. if self:IsAllActive() then
  51. GUI:SetActive(self.view.ActiveBtn, false)
  52. GUI:SetActive(self.view.activeIcon, true)
  53. self.needLv=tonumber(self.preLevel)
  54. else
  55. self.needLv, self.unlockDeplete = self:GetFirstUnlockDeplete()
  56. GUI:SetActive(self.view.ActiveBtn, true)
  57. GUI:SetActive(self.view.activeIcon, false)
  58. end
  59. GUI:DataListUpdateData(self.view.cost_list)
  60. self.ItemCfgId = tonumber(self.unlockDeplete[1][1])
  61. self:SetEquipModel(self.ItemCfgId)
  62. local haveCount = SL:GetBagItemCount(self.ItemCfgId)
  63. local needCount = tonumber(self.unlockDeplete[1][2])
  64. if haveCount < needCount then
  65. GUI:Text_setString(self.view.count, string.format('<color="#9b1818">%d</color>/%d', haveCount, needCount))
  66. else
  67. GUI:Text_setString(self.view.count, string.format('<color="#1ADD1F">%d</color>/%d', haveCount, needCount))
  68. end
  69. if self.preLevel < self.needLv then
  70. GUI:Text_setString(self.view.Level, string.format('<color="#9b1818">%d</color>/%d', self.preLevel, self.needLv))
  71. else
  72. GUI:Text_setString(self.view.Level, string.format('<color="#1ADD1F">%d</color>/%d', self.preLevel, self.needLv))
  73. end
  74. end
  75. end
  76. function this:GetFirstUnlockDeplete()
  77. for _, v in pairs(self.ExceAttTextList) do
  78. if v.isActive == false then
  79. return v.lv, v.unlockDeplete
  80. end
  81. end
  82. return nil,nil
  83. end
  84. function this:SetEquipModel(cfgId)
  85. GUI:setVisible(self.view.itemModel, true)
  86. GUI:Item_setItemId(self.view.itemModel, cfgId)
  87. end
  88. ---注册UI事件和服务器消息
  89. function this:RegistEvents()
  90. GUI:AddOnClickEvent(self.view.CloseBtn, self, self.CloseBtn)
  91. GUI:AddOnClickEvent(self.view.Add, self, self.AddBtn)
  92. GUI:AddOnClickEvent(self.view.ActiveBtn, self, self.ActiveBtn)
  93. GUI:AddOnClickEvent(self.view.maskBtn, self, self.CloseBtn)
  94. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_ACT_EQUIP_ORNAMENTS, self.RES_ACT_EQUIP_ORNAMENTS, self)
  95. SL:RegisterLUAEvent(LUA_EVENT_BAG_CHANGE_AFTER, self.LUA_EVENT_BAG_CHANGE_AFTER, self)
  96. end
  97. function this:LUA_EVENT_BAG_CHANGE_AFTER()
  98. local haveCount = SL:GetBagItemCount(self.ItemCfgId)
  99. local needCount = tonumber(self.unlockDeplete[1][2])
  100. if haveCount < needCount then
  101. GUI:Text_setString(self.view.count, string.format('<color="#9b1818">%d</color>/%d', haveCount, needCount))
  102. else
  103. GUI:Text_setString(self.view.count, string.format('<color="#5CE366FF">%d</color>/%d', haveCount, needCount))
  104. end
  105. end
  106. ---@param message RES_UPDATE_EQUIP_ORNAMENTS
  107. function this:RES_ACT_EQUIP_ORNAMENTS(_, message)
  108. if message then
  109. for _, v in pairs(message.ssactlv) do
  110. for _, j in pairs(self.ExceAttTextList) do
  111. if tonumber(v) == j.lv then
  112. j.isActive = true
  113. end
  114. end
  115. end
  116. self:Refresh()
  117. end
  118. end
  119. function this:IsAllActive()
  120. ---是否全部激活
  121. for _, j in pairs(self.ExceAttTextList) do
  122. if j.isActive == false then
  123. return false
  124. end
  125. end
  126. return true
  127. end
  128. function this:CloseBtn()
  129. GUI:UIPanel_Close("dev/outui/Equip/Panel/KLEquipJewelryActive/KLEquipJewelryActivePanel")
  130. end
  131. function this:AddBtn()
  132. SL:CommonItemGetPath(nil, self.ItemCfgId)
  133. end
  134. function this:ActiveBtn()
  135. if self.needLv then
  136. if tonumber(self.preLevel) < tonumber(self.needLv)then
  137. SL:TipMessage( SL:GetConfig('cfg_string',249).text, 1, NoticeType.NoticeMid )--"等级不足!",
  138. else
  139. local haveCount = SL:GetBagItemCount(self.ItemCfgId)
  140. local needCount = tonumber(self.unlockDeplete[1][2])
  141. if haveCount < needCount then
  142. SL:TipMessage(SL:GetConfig('cfg_string',260).text, 1, NoticeType.NoticeMid )--"材料不足!",
  143. SL:CommonItemGetPath(nil, self.ItemCfgId)
  144. else
  145. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_ACT_EQUIP_ORNAMENTS, { itemId = self.equipInfo.id, lv = tonumber(self.needLv) })
  146. end
  147. end
  148. end
  149. end
  150. function this:Close()
  151. end
  152. return this