KLSuitPanel.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. ---@class KLSuitPanel:UIKmlLuaPanelBase
  2. ---@field view KLSuitPanelView
  3. local KLSuitPanel = class(UIKmlLuaPanelBase)
  4. local this = KLSuitPanel
  5. ---@type table<number,cfg_fashion_column[]>
  6. local grade2Tbls = {}
  7. ---@type table<number,KLSuitEquipItem>
  8. local id2Item = {}
  9. ---@type number[]
  10. local selectCfgIds = {}
  11. ---@type number[]
  12. local showPreviewList = {}
  13. ---@type table<EEquipSlotType,number> <EEquipSlotType,cfgId>
  14. local appearCfgIds = {}
  15. ---@type table<EEquipSlotType,number> <EEquipSlotType,cfgId>
  16. local serverCfgIds = {}
  17. ---@type number[]
  18. local stateCfgIds = {}
  19. ---是否是去保存
  20. ---@type boolean
  21. local isToSave
  22. ---创建时调用一次
  23. function this:Init()
  24. GUI:DataListInitData(self.view.loopscrollviewData,
  25. function()
  26. return self:ItemCountFunc()
  27. end,
  28. function(realIndex)
  29. return self:ItemGetFunc(realIndex)
  30. end,
  31. function(realIndex, kmlCtrl)
  32. return self:ItemInitFunc(realIndex, kmlCtrl)
  33. end,
  34. function(realIndex, kmlCtrl)
  35. return self:ItemUpdateFunc(realIndex, kmlCtrl)
  36. end,
  37. function(realIndex)
  38. return self:ItemSizeGetFunc(realIndex)
  39. end
  40. )
  41. self.Part_ITEM_H = 64
  42. self.Page_Width = GUI:GetWidth(self.view.loopscrollview)
  43. self.PAGE_EXT_H = 40
  44. ---@type table<KingML.KmlControl,KLSuitItem>
  45. self.partItems = {}
  46. end
  47. function this:ItemCountFunc()
  48. return #self.partData
  49. end
  50. function this:ItemGetFunc()
  51. ---@type KLSuitItem
  52. local item = GUI:UIPanel_Open("dev/outui/AppearGroup/Item/KLSuit/KLSuitItem", self.view.loopscrollviewData, self, nil, true)
  53. local kmlCtrl = item.view.root
  54. self.partItems[kmlCtrl] = item
  55. return kmlCtrl
  56. end
  57. function this:ItemInitFunc()
  58. end
  59. ---@param realIndex number
  60. ---@param kmlCtrl KingML.KmlControl
  61. function this:ItemUpdateFunc(realIndex, kmlCtrl)
  62. local item = self.partItems[kmlCtrl]
  63. local luaIndex = realIndex + 1
  64. local grade = self.partData[luaIndex]
  65. local titleStr = SL:NumberToChinese(grade) .. "阶卓越套装"
  66. item:UpdateUI(appearCfgIds, stateCfgIds, grade2Tbls[grade], titleStr, self.itemY, luaIndex)
  67. end
  68. ---@param realIndex number
  69. function this:ItemSizeGetFunc(realIndex)
  70. local luaIndex = realIndex + 1
  71. local slot = self.partData[luaIndex]
  72. local equipCount = #grade2Tbls[slot]
  73. local line = math.ceil(equipCount / 5)
  74. self.itemY = line * self.Part_ITEM_H + (line - 1) * 5 + self.PAGE_EXT_H
  75. return Vector2(self.Page_Width, self.itemY)
  76. end
  77. ---创建或者刷新界面数据时调用
  78. function this:Refresh()
  79. SL:onLUAEvent(APPEAR_PREVIEW_SELECT_CHANGE)
  80. self:AnalysisEquipData()
  81. SL:SendLuaNetMsg(LuaMessageIdToSever.GET_EQUIP_APPEAR)
  82. end
  83. function this:AnalysisEquipData()
  84. self.partData = {}
  85. grade2Tbls = {}
  86. ---@type cfg_fashion_column[]
  87. local tbl = SL:GetConfigTable('cfg_fashion')
  88. ---@type cfg_career_column
  89. local meCareer = SL:GetMetaValue(EMetaVarGetKey.ME_CAREER_TAB_COLUMN)
  90. local meLevel = SL:GetMetaValue(EMetaVarGetKey.LEVEL)
  91. for _, fashTbl in pairs(tbl) do
  92. if table.contains(fashTbl.type, E_FashionType.Change) and (#fashTbl.job == 0 or table.contains(fashTbl.job, meCareer.id)) and fashTbl.level <= meLevel then
  93. if not grade2Tbls[fashTbl.grade] then
  94. grade2Tbls[fashTbl.grade] = {}
  95. end
  96. table.insert(grade2Tbls[fashTbl.grade], fashTbl)
  97. if not table.contains(self.partData, fashTbl.grade) then
  98. table.insert(self.partData, fashTbl.grade)
  99. end
  100. end
  101. end
  102. table.sort(self.partData)
  103. end
  104. ---注册UI事件和服务器消息
  105. function this:RegistEvents()
  106. GUI:AddOnClickEvent(self.view.BtnClose, self, self.BtnCloseOnClick)
  107. GUI:AddOnClickEvent(self.view.BtnCancel, self, self.BtnCancelOnClick)
  108. GUI:AddOnClickEvent(self.view.BtnSure, self, self.BtnSureOnClick)
  109. GUI:AddOnClickEvent(self.view.BtnHelp, self, self.BtnHelpOnClick)
  110. SL:RegisterLuaNetMsg(LuaMessageIdToClient.GET_EQUIP_APPEAR, self.GET_EQUIP_APPEAR, self)
  111. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_EQUIP_FASHION, self.RES_EQUIP_FASHION, self)
  112. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_ACT_EQUIP_FASHION, self.RES_ACT_EQUIP_FASHION, self)
  113. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_SETTING_EQUIP_APPEAR, self.RES_SETTING_EQUIP_APPEAR, self)
  114. SL:RegisterLUAEvent(LUA_EVENT_LEVELCHANGE, self.OnMeLevelChange,self)
  115. end
  116. function this:OnMeLevelChange()
  117. self:AnalysisEquipData()
  118. GUI:DataListUpdateData(self.view.loopscrollviewData)
  119. end
  120. function this:BtnHelpOnClick()
  121. local helpCfg = SL:GetConfig("cfg_rule_text", 203)
  122. if helpCfg then
  123. SL:CommonStrTipsMessage({ title = helpCfg.menutxt, str = helpCfg.location })
  124. end
  125. end
  126. --保存设置成功
  127. ---@param message {slot:EEquipSlotType,cfgId:number}[]
  128. function this:RES_SETTING_EQUIP_APPEAR(_, message)
  129. table.clear(appearCfgIds)
  130. table.clear(serverCfgIds)
  131. table.clear(showPreviewList)
  132. for slot, cfgId in pairs(message) do
  133. slot = tonumber(slot)
  134. appearCfgIds[slot] = cfgId
  135. serverCfgIds[slot] = cfgId
  136. table.insert(showPreviewList, cfgId)
  137. end
  138. end
  139. --激活成功
  140. ---@param message number[]
  141. function this:RES_ACT_EQUIP_FASHION(_, message)
  142. if not message then return end
  143. table.clear(stateCfgIds)
  144. for _, cfgId in pairs(message) do
  145. table.insert(stateCfgIds, cfgId)
  146. local isHave = SL:GetMetaValue(EMetaVarGetKey.EQUIP_CHECK_EXIST_CFG, cfgId)
  147. if not isHave then
  148. table.removeByValue(showPreviewList, cfgId)
  149. end
  150. table.removeByValue(selectCfgIds, cfgId)
  151. table.removeByKeyValue(appearCfgIds, cfgId)
  152. end
  153. SL:onLUAEvent(APPEAR_PREVIEW_SELECT_CHANGE, showPreviewList)
  154. GUI:DataListUpdateData(self.view.loopscrollviewData)
  155. end
  156. --返回幻化激活状态
  157. ---@param message number[]
  158. function this:RES_EQUIP_FASHION(_, message)
  159. table.clear(stateCfgIds)
  160. if message then
  161. for _, v in pairs(message) do
  162. table.insert(stateCfgIds, v)
  163. end
  164. end
  165. GUI:DataListUpdateData(self.view.loopscrollviewData)
  166. end
  167. --返回外观
  168. ---@param message {slot:EEquipSlotType,cfgId:number}[]
  169. function this:GET_EQUIP_APPEAR(_, message)
  170. if not message then return end
  171. table.clear(appearCfgIds)
  172. table.clear(serverCfgIds)
  173. table.clear(showPreviewList)
  174. for _, kp in pairs(message) do
  175. local slot = tonumber(kp.slot)
  176. appearCfgIds[slot] = kp.cfgId
  177. serverCfgIds[slot] = kp.cfgId
  178. table.insert(showPreviewList, kp.cfgId)
  179. end
  180. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_EQUIP_FASHION)
  181. end
  182. function this:BtnSureOnClick()
  183. if isToSave then
  184. SL:CommonTipsMessage({
  185. stringTblID = 209,
  186. title = "提示",
  187. callback = function()
  188. ---@type {slot:number,cfgId:number}[]
  189. local dt = {}
  190. for slot, cfgId in pairs(appearCfgIds) do
  191. table.insert(dt, { slot = slot, cfgId = cfgId })
  192. end
  193. SL:SendLuaNetMsg(LuaMessageIdToSever.SETTING_EQUIP_APPEAR, { equipindex = dt })
  194. self:BtnCloseOnClick()
  195. end
  196. })
  197. else
  198. if #selectCfgIds == 0 then
  199. SL:TipMessage( SL:GetConfig('cfg_string', 254).text, 1, NoticeType.NoticeMid )-- "请选择激活道具",
  200. return
  201. end
  202. GUI:UIPanel_Open("dev/outui/AppearGroup/Panel/KLAppearCost/KLAppearCostPanel", nil, nil, selectCfgIds)
  203. end
  204. end
  205. function this:BtnCancelOnClick()
  206. return self:BtnCloseOnClick()
  207. end
  208. function this:BtnCloseOnClick()
  209. GUI:UIPanel_Close("dev/outui/AppearGroup/Panel/KLSuit/KLSuitPanel")
  210. GUI:UIPanel_Close("dev/outui/AppearGroup/Panel/KLAppearGroup/KLAppearGroupPanel")
  211. GUI:UIPanel_Close("dev/outui/AppearGroup/Panel/KLAppearPreview/KLAppearPreviewPanel")
  212. end
  213. function this:Close()
  214. table.clear(selectCfgIds)
  215. end
  216. ---@param equipItem KLSuitEquipItem
  217. function this:OnEquipItemSelect(equipItem, suitIndex, suitEquipIndex, isUnlocked)
  218. local grade = self.partData[suitIndex]
  219. local itemId = grade2Tbls[grade][suitEquipIndex].id
  220. ---@type cfg_item_column
  221. local itemTbl = SL:GetConfig("cfg_item", itemId)
  222. local part = itemTbl.strPart[1]
  223. local isDel = table.contains(selectCfgIds, itemId)
  224. local isHave = SL:GetMetaValue(EMetaVarGetKey.EQUIP_CHECK_EXIST_CFG, itemId)
  225. if isUnlocked then
  226. --点击的是已激活的,将选中的未激活的清理掉,将列表中的同部位的装备去掉,该点击放到即将保存列表列表,
  227. GUI:Text_setString(self.view.BtnSure, "保存")
  228. if isDel then
  229. table.removeByValue(selectCfgIds, itemId)
  230. if id2Item[itemId] then
  231. id2Item[itemId]:SetState(false)
  232. id2Item[itemId] = nil
  233. end
  234. if serverCfgIds[part] and serverCfgIds[part] ~= itemId then
  235. appearCfgIds[part] = serverCfgIds[part]
  236. else
  237. appearCfgIds[part] = nil
  238. end
  239. if not isHave then
  240. table.removeByValue(showPreviewList, itemId)
  241. if serverCfgIds[part] and not table.contains(showPreviewList, serverCfgIds[part]) then
  242. table.insert(showPreviewList, serverCfgIds[part])
  243. end
  244. end
  245. else
  246. for i = #selectCfgIds, 1, -1 do
  247. local cfgId = selectCfgIds[i]
  248. ---@type cfg_item_column
  249. local tmpTbl = SL:GetConfig("cfg_item", cfgId)
  250. local tmpPart = tmpTbl.strPart[1]
  251. if not table.contains(stateCfgIds, cfgId) then
  252. if id2Item[cfgId] then
  253. id2Item[cfgId]:SetState(false)
  254. id2Item[cfgId] = nil
  255. end
  256. table.remove(selectCfgIds, i)
  257. if tmpPart == part then
  258. table.removeByValue(showPreviewList, cfgId)
  259. else
  260. local isEquip = SL:GetMetaValue(EMetaVarGetKey.EQUIP_CHECK_EXIST_CFG, cfgId)
  261. if not isEquip then
  262. table.removeByValue(showPreviewList, cfgId)
  263. end
  264. end
  265. elseif tmpPart == part then
  266. if id2Item[cfgId] then
  267. id2Item[cfgId]:SetState(false)
  268. id2Item[cfgId] = nil
  269. end
  270. table.remove(selectCfgIds, i)
  271. table.removeByValue(showPreviewList, cfgId)
  272. end
  273. end
  274. table.insert(selectCfgIds, itemId)
  275. id2Item[itemId] = equipItem
  276. equipItem:SetState(true)
  277. --将外观列表 appearCfgIds 中的同部位的装备替换
  278. appearCfgIds[part] = itemId
  279. if not table.contains(showPreviewList, itemId) then
  280. table.insert(showPreviewList, itemId)
  281. end
  282. end
  283. isToSave = true
  284. else
  285. --点击的也是未激活的, 将所有选中的已激活清理掉,该点击放到即将激活列表,并且将列表中的同部位的装备去掉
  286. GUI:Text_setString(self.view.BtnSure, "激活")
  287. if isDel then
  288. table.removeByValue(selectCfgIds, itemId)
  289. if id2Item[itemId] then
  290. id2Item[itemId]:SetState(false)
  291. id2Item[itemId] = nil
  292. end
  293. if not isHave then
  294. table.removeByValue(showPreviewList, itemId)
  295. if serverCfgIds[part] and not table.contains(showPreviewList, serverCfgIds[part]) then
  296. table.insert(showPreviewList, serverCfgIds[part])
  297. end
  298. end
  299. else
  300. for i = #selectCfgIds, 1, -1 do
  301. local cfgId = selectCfgIds[i]
  302. ---@type cfg_item_column
  303. local tmpTbl = SL:GetConfig("cfg_item", cfgId)
  304. local tmpPart = tmpTbl.strPart[1]
  305. if table.contains(stateCfgIds, cfgId) then
  306. if id2Item[cfgId] then
  307. id2Item[cfgId]:SetState(false)
  308. id2Item[cfgId] = nil
  309. end
  310. table.remove(selectCfgIds, i)
  311. appearCfgIds[tmpPart] = nil
  312. if tmpPart == part then
  313. table.removeByValue(showPreviewList, cfgId)
  314. else
  315. local isEquip = SL:GetMetaValue(EMetaVarGetKey.EQUIP_CHECK_EXIST_CFG, cfgId)
  316. if not isEquip then
  317. table.removeByValue(showPreviewList, cfgId)
  318. end
  319. end
  320. elseif tmpPart == part then
  321. if id2Item[cfgId] then
  322. id2Item[cfgId]:SetState(false)
  323. id2Item[cfgId] = nil
  324. end
  325. table.remove(selectCfgIds, i)
  326. appearCfgIds[tmpPart] = nil
  327. table.removeByValue(showPreviewList, cfgId)
  328. end
  329. end
  330. table.insert(selectCfgIds, itemId)
  331. id2Item[itemId] = equipItem
  332. equipItem:SetState(true)
  333. if not table.contains(showPreviewList, itemId) then
  334. table.insert(showPreviewList, itemId)
  335. end
  336. end
  337. isToSave = false
  338. end
  339. SL:onLUAEvent(APPEAR_PREVIEW_SELECT_CHANGE, showPreviewList)
  340. end
  341. return this