KLArchangelMasterPanel.lua 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. ---@class KLArchangelMasterPanel:UIKmlLuaPanelBase
  2. ---@field view KLArchangelMasterPanelView
  3. ---@field tbl cfg_equip_angelSuit_column[]
  4. local KLArchangelMasterPanel = class(UIKmlLuaPanelBase)
  5. local this = KLArchangelMasterPanel
  6. function this:AsyncLoadUI()
  7. end
  8. local ActionState = {
  9. CanAction = enum(1),
  10. NoAction = enum(2),
  11. Action = enum(3),
  12. }
  13. ---创建时调用一次
  14. function this:Init()
  15. GUI:DataListInitData(self.view.suit_datalist, function()
  16. return #self.tbl
  17. end, function(realIndex)
  18. end, function(realIndex, kmlcontrol)
  19. end, function(realIndex, kmlcontrol)
  20. return self:SuitUpdateItem(realIndex, kmlcontrol)
  21. end)
  22. end
  23. function this:SuitUpdateItem(realIndex, kmlcontrol)
  24. --local att_text = self.view.suit_datalist:GetChildControl(realIndex, "att_text")
  25. local att_text = GUI:GetChildControl(self.view.suit_datalist, realIndex, "att_text")
  26. GUI:Text_setString(att_text, "大天使天赋点+" .. tostring(self.tbl[realIndex + 1].Count))
  27. --local info_text = self.view.suit_datalist:GetChildControl(realIndex, "info_text")
  28. local info_text = GUI:GetChildControl(self.view.suit_datalist, realIndex, "info_text")
  29. --local wearcount_text = self.view.suit_datalist:GetChildControl(realIndex, "wearcount_text")
  30. local wearcount_text = GUI:GetChildControl(self.view.suit_datalist, realIndex, "wearcount_text")
  31. local text
  32. local actionCount = self.tbl[realIndex + 1].actionCount and self.tbl[realIndex + 1].actionCount or self.tbl[realIndex + 1].wearingCount
  33. GUI:Text_setString(info_text, self.tbl[realIndex + 1].text)
  34. if actionCount == self.tbl[realIndex + 1].wearingCount then
  35. GUI:Text_setString(wearcount_text, "<color='#1add1f'>(" .. tostring(actionCount) .. "/" .. tostring(self.tbl[realIndex + 1].wearingCount) .. ")</color>")
  36. else
  37. GUI:Text_setString(wearcount_text, "<color='#ff2323'>(" .. tostring(actionCount) .. "/" .. tostring(self.tbl[realIndex + 1].wearingCount) .. ")</color>")
  38. end
  39. --local ok_btn = self.view.suit_datalist:GetChildControl(realIndex, "ok_btn")
  40. local ok_btn = GUI:GetChildControl(self.view.suit_datalist, realIndex, "ok_btn")
  41. --local no_btn = self.view.suit_datalist:GetChildControl(realIndex, "no_btn")
  42. local no_btn = GUI:GetChildControl(self.view.suit_datalist, realIndex, "no_btn")
  43. --local done = self.view.suit_datalist:GetChildControl(realIndex, "done")
  44. local done = GUI:GetChildControl(self.view.suit_datalist, realIndex, "done")
  45. if self.tbl[realIndex + 1].actionInfo == ActionState.Action then
  46. -- 已激活
  47. GUI:setVisible(ok_btn, false)
  48. GUI:setVisible(no_btn, false)
  49. GUI:setVisible(done, true)
  50. elseif self.tbl[realIndex + 1].actionInfo == ActionState.CanAction then
  51. -- 可激活未激活
  52. GUI:setVisible(ok_btn, true)
  53. GUI:setVisible(no_btn, false)
  54. GUI:setVisible(done, false)
  55. GUI:AddOnClickEvent(ok_btn, self, function()
  56. -- 激活协议
  57. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_ACTIVE_ANGEL_TALENT, self.tbl[realIndex + 1].id)
  58. end)
  59. else
  60. -- 不可激活
  61. GUI:setVisible(ok_btn, false)
  62. GUI:setVisible(no_btn, true)
  63. GUI:setVisible(done, false)
  64. end
  65. end
  66. ---注册UI事件和服务器消息
  67. function this:RegistEvents()
  68. GUI:AddOnClickEvent(self.view.mask, self, self.CLosePanel)
  69. GUI:AddOnClickEvent(self.view.close, self, self.CLosePanel)
  70. SL:RegisterLUAEvent(LUA_ANGEL_TALENT_ACTIVE, self.LUA_ANGEL_TALENT_ACTIVE, self)
  71. end
  72. ---界面显示时调用一次
  73. function this:Show()
  74. end
  75. ---创建或者刷新界面数据时调用
  76. function this:Refresh()
  77. SL:RefreshPanelALLRedPoint("KLArchangelTalentPanel")
  78. self:LoadTable()
  79. GUI:DataListUpdateData(self.view.suit_datalist)
  80. end
  81. function this:CLosePanel()
  82. GUI:UIPanel_Close("dev/outui/Archangel/Panel/KLArchangelMaster/KLArchangelMasterPanel")
  83. end
  84. function this:LUA_ANGEL_TALENT_ACTIVE(_, message)
  85. self:Refresh()
  86. end
  87. function this:CanMasterAction(cfgId)
  88. local equip = SL:GetWearBarsData(9)
  89. ---@type cfg_equip_angelSuit_column
  90. local tbl = SL:GetConfig("cfg_equip_angelSuit", cfgId, "id")
  91. local wearCount = 0
  92. ---@type table @<组,装备等级[]>
  93. local equipGroup = {}
  94. for i, v in pairs(equip) do
  95. local suit = SL:GetConfig("cfg_equip_angelGroup", v.cfgId, "id").angelEquipSuit
  96. if not equipGroup[suit] then
  97. equipGroup[suit] = {}
  98. end
  99. table.insert(equipGroup[suit], InfoManager.archangeEquipInfo:GetEquipLevelInfo(v.id).level)
  100. end
  101. --- 给同组的排序
  102. for _, v in pairs(equipGroup) do
  103. table.sort(v)
  104. end
  105. local angelLv = table.copy(tbl.angelLv)
  106. --- 循环判断条件
  107. for i, v in pairs(angelLv) do
  108. if equipGroup[v[1]] then
  109. --- 给同组的排序(小到大)
  110. --- 找到改组中符合条件的最小的移除
  111. --- 同时符合条件的件数+1
  112. local count = 0
  113. local num = 1
  114. while num <= #equipGroup[v[1]] do
  115. if equipGroup[v[1]][num] >= v[3] then
  116. table.remove(equipGroup[v[1]], num)
  117. wearCount = wearCount + 1
  118. count = count + 1
  119. if count == v[2] then
  120. break
  121. end
  122. else
  123. num = num + 1
  124. end
  125. end
  126. end
  127. end
  128. return wearCount
  129. end
  130. function this:Close()
  131. InfoManager.archangeEquipInfo:CanMasterAction()
  132. end
  133. function this:LoadTable()
  134. self.tbl = {}
  135. local career = SL:GetMetaValue(EMetaVarGetKey.ME_CAREER_TAB_COLUMN)
  136. ---@type cfg_equip_angelSuit_column[]
  137. local data = SL:FindConfigs("cfg_equip_angelSuit", "type", 2)
  138. local action = {}
  139. local canAction = {}
  140. local noAction = {}
  141. for _, v in pairs(data) do
  142. local actionCount = self:CanMasterAction(v.id)
  143. if v.career == career.baseCareer then
  144. if InfoManager.archangeEquipInfo:IsMasterAction(v.id) then
  145. -- 已激活
  146. v.actionInfo = ActionState.Action
  147. table.insert(action, v)
  148. elseif actionCount == v.wearingCount then
  149. -- 可激活未激活
  150. v.actionInfo = ActionState.CanAction
  151. v.actionCount = actionCount
  152. table.insert(canAction, v)
  153. else
  154. -- 不可激活
  155. v.actionInfo = ActionState.NoAction
  156. v.actionCount = actionCount
  157. table.insert(noAction, v)
  158. end
  159. end
  160. end
  161. table.sort(action, function(a, b)
  162. return a.id < b.id
  163. end)
  164. table.sort(canAction, function(a, b)
  165. return a.id < b.id
  166. end)
  167. table.sort(noAction, function(a, b)
  168. return a.id < b.id
  169. end)
  170. table.insertArray(self.tbl, canAction)
  171. table.insertArray(self.tbl, noAction)
  172. table.insertArray(self.tbl, action)
  173. end
  174. return this