KLUIForgingMasterPanel.lua 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. ---@class KLUIForgingMasterPanel:UIKmlLuaPanelBase
  2. ---@field view KLUIForgingMasterPanelView
  3. local KLUIForgingMasterPanel = class(UIKmlLuaPanelBase)
  4. local this =KLUIForgingMasterPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. ---1 锻造, 2 追加
  8. self.uiType = self.args.uiType
  9. self.cfgId = self.args.cfgId
  10. end
  11. ---创建或者刷新界面数据时调用
  12. function this:Refresh()
  13. ---@type cfg_item_column
  14. local item = SL:GetConfig("cfg_item", self.cfgId)
  15. local tbl_id = tonumber(item.strPart[1] .. "0" .. self.uiType)
  16. ---@type cfg_equip_masterGroup_column
  17. local group = SL:GetConfig("cfg_equip_masterGroup", tbl_id)
  18. ---@type cfg_equip_master_column[]
  19. local master = SL:GetConfigTable("cfg_equip_master")
  20. ---@type cfg_equip_master_column[]
  21. local masterTbl = {}
  22. local masterValue, masterStrPartId, masterCount
  23. for i, v in pairs(master) do
  24. if v.group == group.group and v.type == self.uiType then
  25. masterTbl[#masterTbl + 1] = v
  26. masterCount = v.count
  27. masterValue = v.value
  28. if v.strPartId and not masterStrPartId then
  29. masterStrPartId = {}
  30. for k, part in ipairs(v.strPartId) do
  31. masterStrPartId[k] = part
  32. end
  33. end
  34. end
  35. end
  36. table.sort(masterTbl, function(a,b)
  37. return a.id < b.id
  38. end)
  39. local forgingLevel = self:GetShowMasterLevel(masterCount, masterStrPartId)
  40. local curLvId = 0
  41. for i, v in ipairs(masterTbl) do
  42. if v.lv > forgingLevel then
  43. self:RefreshUI(curLvId, v.id, group.strpartShow)
  44. return
  45. end
  46. curLvId = v.id
  47. end
  48. if curLvId > 0 then
  49. self:RefreshUI(curLvId, nil, group.strpartShow)
  50. end
  51. end
  52. ---注册UI事件和服务器消息
  53. function this:RegistEvents()
  54. --GUI:UIPanel_Open("dev/ui/Equip/Panel/KLUIForgingMaster/KLUIForgingMasterPanel")
  55. --GUI:UIPanel_Close("dev/ui/Equip/Panel/KLUIForgingMaster/KLUIForgingMasterPanel")
  56. GUI:AddOnClickEvent(self.view.btn_close, self, self.CloseSelf)
  57. end
  58. function this:GetShowMasterLevel(type, partStr)
  59. ---@type CommonProtos.Item[]
  60. local equipData = SL:GetMetaValue(EMetaVarGetKey.EQUIP_DATA)
  61. if type == 1 then
  62. local minForgingLevel = 100
  63. for i, v in pairs(equipData[1]) do
  64. ---@type cfg_item_column
  65. local item = SL:GetConfig("cfg_item", v.cfgId)
  66. for j, k in pairs(partStr) do
  67. if item.strPart[1] == k or item.strPart[2] == k then
  68. local forgingLevel
  69. if self.uiType == 1 then
  70. forgingLevel = EquipFunc.GetEquipStrengthLevel(v)
  71. else
  72. forgingLevel = EquipFunc.GetEquipAppendLevel(v)
  73. end
  74. if forgingLevel < minForgingLevel then
  75. minForgingLevel = forgingLevel
  76. end
  77. table.remove(partStr, j)
  78. break
  79. end
  80. end
  81. end
  82. if #partStr == 0 then
  83. return minForgingLevel
  84. else
  85. return 0
  86. end
  87. else
  88. local totalLevel = 0
  89. for i, v in pairs(equipData[1]) do
  90. ---@type cfg_item_column
  91. local item = SL:GetConfig("cfg_item", v.cfgId)
  92. for j, k in pairs(partStr) do
  93. if k == item.strPart[1] or k == item.strPart[2] then
  94. local forgingLevel = 0
  95. if self.uiType == 1 then
  96. forgingLevel = EquipFunc.GetEquipStrengthLevel(v)
  97. else
  98. forgingLevel = EquipFunc.GetEquipAppendLevel(v)
  99. end
  100. totalLevel = totalLevel + forgingLevel
  101. break
  102. end
  103. end
  104. end
  105. return totalLevel
  106. end
  107. end
  108. function this:RefreshUI(curLevel, nextLevel, strpartShow)
  109. local partList
  110. if nextLevel then
  111. if curLevel == 0 then
  112. ---未激活
  113. ---@type cfg_equip_master_column
  114. local curTbl = SL:GetConfig("cfg_equip_master", nextLevel)
  115. GUI:Text_setString(self.view.now_attr, "<color=#999999>" .. curTbl.note .. "+" .. curTbl.lv .. "</color>")
  116. GUI:Text_setString(self.view.now_bonus, self:GetAttrInfo(curTbl.att2))
  117. partList = curTbl.strPartId
  118. else
  119. ---激活
  120. local curTbl = SL:GetConfig("cfg_equip_master", curLevel)
  121. GUI:Text_setString(self.view.now_attr, curTbl.note .. "<color=#1ADD1F>+" .. curTbl.lv .. "</color>")
  122. GUI:Text_setString(self.view.now_bonus, self:GetAttrInfo(curTbl.att2, 1))
  123. partList = curTbl.strPartId
  124. end
  125. if curLevel == 0 then
  126. nextLevel = nextLevel + 1
  127. end
  128. GUI:SetActive(self.view.next_level, true)
  129. ---@type cfg_equip_master_column
  130. local nextTbl = SL:GetConfig("cfg_equip_master", nextLevel)
  131. GUI:Text_setString(self.view.next_attr, "<color=#999999>" .. nextTbl.note .. "+" .. nextTbl.lv .. "</color>")
  132. GUI:Text_setString(self.view.next_bonus, self:GetAttrInfo(nextTbl.att2))
  133. else
  134. ---满级
  135. ---@type cfg_equip_master_column
  136. local curTbl = SL:GetConfig("cfg_equip_master", curLevel)
  137. GUI:Text_setString(self.view.now_attr, curTbl.note .. "<color=#1ADD1F>+" .. curTbl.lv .. "</color>")
  138. GUI:Text_setString(self.view.now_bonus, self:GetAttrInfo(curTbl.att2, 1))
  139. GUI:SetActive(self.view.next_level, false)
  140. partList = curTbl.strPartId
  141. end
  142. if self.uiType == 1 then
  143. GUI:Text_setString(self.view.text_title, "强化大师")
  144. GUI:Text_setString(self.view.text_tips, "满足强化条件可点亮属性")
  145. else
  146. GUI:Text_setString(self.view.text_title, "追加大师")
  147. GUI:Text_setString(self.view.text_tips, "满足追加条件可点亮属性")
  148. end
  149. GUI:Text_setString(self.view.text_part_name, strpartShow)
  150. end
  151. function this:GetAttrInfo(attr, act)
  152. local value, str
  153. -----@type cfg_att_info_column
  154. --local attrTbl = SL:GetConfig("cfg_att_info", attr[1])
  155. --if attrTbl.remarks == 2 then
  156. -- value = attr[2] / 100
  157. -- str = value .. "%"
  158. --else
  159. -- str = attr[2]
  160. --end
  161. --if act then
  162. -- return attrTbl.name .. "<color=#1ADD1F>+" .. str .. "</color>"
  163. --else
  164. -- return "<color=#999999>" .. attrTbl.name .. "+" .. str .. "</color>"
  165. --end
  166. if attr[1] == 1 then
  167. value = "强化属性"
  168. elseif attr[1] == 2 then
  169. value = "追加属性"
  170. end
  171. str = attr[2] / 100
  172. if act then
  173. return value .. "<color=#1ADD1F>+" .. str .. "%</color>"
  174. else
  175. return "<color=#999999>" .. value .. "+" .. str .. "%</color>"
  176. end
  177. end
  178. function this:CloseSelf()
  179. GUI:UIPanel_Close("dev/outui/Equip/Panel/KLUIForgingMaster/KLUIForgingMasterPanel")
  180. end
  181. function this:Close()
  182. end
  183. return this