KLTransferRingPanel.lua 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. ---@class KLTransferRingPanel:UIKmlLuaPanelBase
  2. ---@field view KLTransferRingPanelView
  3. ---@field curRingItem KLTransferRingItem
  4. ---@field curRingId number
  5. ---@field serverRingId number
  6. local KLTransferRingPanel = class(UIKmlLuaPanelBase)
  7. local this = KLTransferRingPanel
  8. ---创建时调用一次
  9. function this:Init()
  10. GUI:DataListInitData(self.view.loopscrollviewData,
  11. function()
  12. return self:ItemCountFunc()
  13. end,
  14. function(realIndex)
  15. return self:ItemGetFunc(realIndex)
  16. end,
  17. function(realIndex, kmlCtrl)
  18. return self:ItemInitFunc(realIndex, kmlCtrl)
  19. end,
  20. function(realIndex, kmlCtrl)
  21. return self:ItemUpdateFunc(realIndex, kmlCtrl)
  22. end
  23. )
  24. GUI:DataListInitData(self.view.datalist11,
  25. function()
  26. return self:AttrCountFunc()
  27. end,
  28. function(realIndex)
  29. return self:AttrItemGetFunc(realIndex)
  30. end,
  31. function(realIndex, kmlCtrl)
  32. return self:AttrItemInitFunc(realIndex, kmlCtrl)
  33. end,
  34. function(realIndex, kmlCtrl)
  35. return self:AttrItemUpdateFunc(realIndex, kmlCtrl)
  36. end)
  37. ---@type RingData[]
  38. self.ringData = {}
  39. ---@type {str:string,sort:number}[]
  40. self.attrData = {}
  41. ---@type table<KingML.KmlControl,KLTransferRingItem>
  42. self.ringItems = {}
  43. end
  44. --region 变身戒指
  45. function this:ItemCountFunc()
  46. return #self.ringData
  47. end
  48. function this:ItemGetFunc()
  49. ---@type KLTransferRingItem
  50. local item = GUI:UIPanel_Open("dev/outui/AppearGroup/Item/KLTransferRing/KLTransferRingItem", self.view.loopscrollviewData, self, nil, true)
  51. local kmlCtrl = item.view.root
  52. self.ringItems[kmlCtrl] = item
  53. return kmlCtrl
  54. end
  55. function this:ItemInitFunc()
  56. end
  57. ---@param realIndex number
  58. ---@param kmlCtrl KingML.KmlControl
  59. function this:ItemUpdateFunc(realIndex, kmlCtrl)
  60. local item = self.ringItems[kmlCtrl]
  61. local luaIndex = realIndex + 1
  62. local dt = self.ringData[luaIndex]
  63. local isSelect = dt.itemId == self.curRingId
  64. item:UpdateUI(dt, isSelect)
  65. end
  66. --endregion
  67. --region Attr
  68. function this:AttrCountFunc()
  69. return #self.attrData
  70. end
  71. function this:AttrItemGetFunc()
  72. end
  73. function this:AttrItemInitFunc()
  74. end
  75. ---@param realIndex number
  76. function this:AttrItemUpdateFunc(realIndex)
  77. local txtInfo = GUI:GetChildControl(self.view.datalist11, realIndex, 'TxtInfo')
  78. local luaIndex = realIndex + 1
  79. local dt = self.attrData[luaIndex]
  80. GUI:Text_setString(txtInfo, dt.str)
  81. end
  82. --endregion
  83. ---创建或者刷新界面数据时调用
  84. function this:Refresh()
  85. SL:onLUAEvent(TRANSFER_RING_PREVIEW_SELECT_CHANGE)
  86. SL:SendLuaNetMsg(LuaMessageIdToSever.GET_SHAPE_RING)
  87. end
  88. function this:AnalysisRingAttrData()
  89. table.clear(self.attrData)
  90. ---@type table<number,number>
  91. local attrId2Val = {}
  92. for _, v in pairs(self.ringData) do
  93. ---@type cfg_fashion_column
  94. local fashionTbl = SL:GetConfig("cfg_fashion", v.itemId)
  95. if fashionTbl then
  96. for _, attr in pairs(fashionTbl.att) do
  97. local attrId = attr[1]
  98. local attrVal = attr[2]
  99. if attrId and attrVal then
  100. if not attrId2Val[attrId] then
  101. attrId2Val[attrId] = attrVal
  102. else
  103. attrId2Val[attrId] = attrId2Val[attrId] + attrVal
  104. end
  105. end
  106. end
  107. end
  108. end
  109. --策划要求 最大(小)攻击力提高 最大(小)魔法攻击力 最大(小)攻击力 最大(小)诅咒攻击力 合并写死
  110. local hasAtkUp
  111. local hasAtk
  112. local hasMagic
  113. local hasCurse
  114. if attrId2Val[200011] and attrId2Val[200021] then
  115. local str
  116. if attrId2Val[200011] == attrId2Val[200021] then
  117. str = "<color=#dce1e5>攻击力提高:</color>" .. attrId2Val[200011]
  118. else
  119. str = "<color=#dce1e5>攻击力提高:</color>" .. attrId2Val[200011] .. "~" .. attrId2Val[200021]
  120. end
  121. ---@type cfg_att_info_column
  122. local attrTbl = SL:GetConfig("cfg_att_info", 200011)
  123. table.insert(self.attrData, { str = str, sort = attrTbl.sort })
  124. hasAtkUp = true
  125. end
  126. if attrId2Val[201011] and attrId2Val[201021] then
  127. local str
  128. if attrId2Val[201011] == attrId2Val[201021] then
  129. str = "<color=#dce1e5>攻击力:</color>" .. attrId2Val[201021]
  130. else
  131. str = "<color=#dce1e5>攻击力:</color>" .. attrId2Val[201021] .. "~" .. attrId2Val[201011]
  132. end
  133. ---@type cfg_att_info_column
  134. local attrTbl = SL:GetConfig("cfg_att_info", 201011)
  135. table.insert(self.attrData, { str = str, sort = attrTbl.sort })
  136. hasAtk = true
  137. end
  138. if attrId2Val[202011] and attrId2Val[202021] then
  139. local str
  140. if attrId2Val[202011] == attrId2Val[202021] then
  141. str = "<color=#dce1e5>魔法攻击力:</color>" .. attrId2Val[202021]
  142. else
  143. str = "<color=#dce1e5>魔法攻击力:</color>" .. attrId2Val[202021] .. "~" .. attrId2Val[202011]
  144. end
  145. ---@type cfg_att_info_column
  146. local attrTbl = SL:GetConfig("cfg_att_info", 202011)
  147. table.insert(self.attrData, { str = str, sort = attrTbl.sort })
  148. hasMagic = true
  149. end
  150. if attrId2Val[205011] and attrId2Val[205021] then
  151. local str
  152. if attrId2Val[205011] == attrId2Val[205021] then
  153. str = "<color=#dce1e5>诅咒攻击力:</color>" .. attrId2Val[205011]
  154. else
  155. str = "<color=#dce1e5>诅咒攻击力:</color>" .. attrId2Val[205011] .. "~" .. attrId2Val[205021]
  156. end
  157. ---@type cfg_att_info_column
  158. local attrTbl = SL:GetConfig("cfg_att_info", 205011)
  159. table.insert(self.attrData, { str = str, sort = attrTbl.sort })
  160. hasCurse = true
  161. end
  162. for attrId, attrVal in pairs(attrId2Val) do
  163. local isAdd
  164. if attrId == 200011 or attrId == 200021 then
  165. isAdd = not hasAtkUp
  166. elseif attrId == 201011 or attrId == 201021 then
  167. isAdd = not hasAtk
  168. elseif attrId == 202011 or attrId == 202021 then
  169. isAdd = not hasMagic
  170. elseif attrId == 205011 or attrId == 205021 then
  171. isAdd = not hasCurse
  172. else
  173. isAdd = true
  174. end
  175. if isAdd then
  176. ---@type cfg_att_info_column
  177. local attrTbl = SL:GetConfig("cfg_att_info", attrId)
  178. local str
  179. if attrTbl.remarks == 1 then
  180. str = "<color=#dce1e5>" .. attrTbl.name .. ":</color>" .. attrVal
  181. else
  182. str = "<color=#dce1e5>" .. attrTbl.name .. ":</color>" .. (attrVal / 100) .. "%"
  183. end
  184. table.insert(self.attrData, { str = str, sort = attrTbl.sort })
  185. end
  186. end
  187. table.sort(self.attrData, function(a, b)
  188. return a.sort < b.sort
  189. end)
  190. end
  191. ---注册UI事件和服务器消息
  192. function this:RegistEvents()
  193. GUI:AddOnClickEvent(self.view.BtnClose, self, self.BtnCloseOnClick)
  194. GUI:AddOnClickEvent(self.view.BtnCancel, self, self.BtnCancelOnClick)
  195. GUI:AddOnClickEvent(self.view.BtnSure, self, self.BtnSureOnClick)
  196. SL:RegisterLuaNetMsg(LuaMessageIdToClient.GET_SHAPE_RING, self.GET_SHAPE_RING, self)
  197. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_PUTOON_RING, self.RES_PUTOON_RING, self)
  198. end
  199. function this:RES_PUTOON_RING(_, message)
  200. self.serverRingId = message
  201. end
  202. --[[
  203. {
  204. curWearRing: --当前穿戴的变身戒指,怪物id
  205. "title":{
  206. 1:{ -- key是下标
  207. "monsterId": --要变身的怪物id
  208. "ringAttr" : {} --戒指属性
  209. "getTime": --获取时间的秒数
  210. "time": --有效期,有效期截止的秒数,-1为永久
  211. "itemId":
  212. }
  213. }
  214. }
  215. ]]
  216. ---@alias RingData {time:number,limitTime:boolean,ringAttr:table,getTime:number,itemId:number}
  217. ---@param message {curWearRing:number,title:RingData[]}
  218. function this:GET_SHAPE_RING(_, message)
  219. self.serverRingId = message.curWearRing
  220. self.curRingId = message.curWearRing
  221. table.clear(self.ringData)
  222. local meTbl
  223. for _, v in pairs(message.title) do
  224. if self.serverRingId == v.confId then
  225. meTbl = v
  226. else
  227. table.insert(self.ringData, v)
  228. end
  229. end
  230. table.sort(self.ringData, function(a, b)
  231. return a.itemId < b.itemId
  232. end)
  233. if meTbl then
  234. table.insert(self.ringData, 1, meTbl)
  235. end
  236. GUI:DataListUpdateData(self.view.loopscrollviewData)
  237. self:AnalysisRingAttrData()
  238. GUI:DataListUpdateData(self.view.datalist11)
  239. end
  240. function this:BtnSureOnClick()
  241. SL:CommonTipsMessage({
  242. stringTblID = 209,
  243. title = "提示",
  244. callback = function()
  245. SL:SendLuaNetMsg(LuaMessageIdToSever.SET_SHAPE_RING, { monsterId = self.curRingId })
  246. self:BtnCloseOnClick()
  247. end
  248. })
  249. end
  250. function this:BtnCancelOnClick()
  251. if self.curRingId == self.serverRingId then
  252. self:BtnCloseOnClick()
  253. return
  254. end
  255. self:BtnSureOnClick()
  256. end
  257. function this:BtnCloseOnClick()
  258. GUI:UIPanel_Close("dev/outui/AppearGroup/Panel/KLTransferRing/KLTransferRingPanel")
  259. GUI:UIPanel_Close("dev/outui/AppearGroup/Panel/KLAppearGroup/KLAppearGroupPanel")
  260. GUI:UIPanel_Close("dev/outui/AppearGroup/Panel/KLAppearPreview/KLAppearPreviewPanel")
  261. end
  262. function this:Close()
  263. self.curRingItem = nil
  264. self.curRingId = nil
  265. self.serverRingId = nil
  266. end
  267. ---@param ringItem KLTransferRingItem
  268. function this:RingItemOnClick(ringItem, ringId)
  269. if self.curRingItem then
  270. self.curRingItem:SetIsSelect(false)
  271. end
  272. if self.curRingItem and self.curRingId == ringId then
  273. self.curRingId = nil
  274. self.curRingItem = nil
  275. else
  276. self.curRingItem = ringItem
  277. self.curRingId = ringId
  278. ringItem:SetIsSelect(true)
  279. end
  280. SL:onLUAEvent(TRANSFER_RING_PREVIEW_SELECT_CHANGE, self.curRingId)
  281. end
  282. return this