KLTitlePanel.lua 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. ---@class KLTitlePanel:UIKmlLuaPanelBase
  2. ---@field view KLTitlePanelView
  3. ---@field titleData TitleData[]
  4. ---@field curTitleItem KLTitleItem
  5. ---@field curTitleId number
  6. ---@field serverTitleId number
  7. local KLTitlePanel = class(UIKmlLuaPanelBase)
  8. local this = KLTitlePanel
  9. ---创建时调用一次
  10. function this:Init()
  11. self.titleData = {}
  12. ---@type {str:string,sort:number}[]
  13. self.attrData = {}
  14. ---@type table<KingML.KmlControl,KLTitleItem>
  15. self.titleItems = {}
  16. ---@param realIndex number
  17. ---@param kmlCtrl KingML.KmlControl
  18. GUI:DataListInitData(self.view.loopscrollviewData,
  19. function()
  20. return #self.titleData
  21. end,
  22. function()
  23. ---@type KLTitleItem
  24. local item = GUI:UIPanel_Open("dev/outui/AppearGroup/Item/KLTitle/KLTitleItem", self.view.loopscrollviewData, self, nil, true)
  25. local kmlCtrl = item.view.root
  26. self.titleItems[kmlCtrl] = item
  27. return kmlCtrl
  28. end,
  29. nil,
  30. function(realIndex, kmlCtrl)
  31. local item = self.titleItems[kmlCtrl]
  32. local luaIndex = realIndex + 1
  33. local dt = self.titleData[luaIndex]
  34. local isSelect = dt.confId == self.curTitleId
  35. item:UpdateUI(dt, isSelect)
  36. end
  37. )
  38. ---@param realIndex number
  39. GUI:DataListInitData(self.view.datalist11,
  40. function()
  41. return #self.attrData
  42. end,
  43. nil,
  44. nil,
  45. function(realIndex,kmlCtrl)
  46. local txtInfo = GUI:GetChildControl(self.view.datalist11, realIndex, 'TxtInfo',kmlCtrl)
  47. local luaIndex = realIndex + 1
  48. local dt = self.attrData[luaIndex]
  49. GUI:Text_setString(txtInfo, dt.str)
  50. end)
  51. end
  52. ---创建或者刷新界面数据时调用
  53. function this:Refresh()
  54. SL:SendLuaNetMsg(LuaMessageIdToSever.GET_TITLE)
  55. end
  56. function this:AnalysisTitleAttrData()
  57. table.clear(self.attrData)
  58. ---@type table<number,number>
  59. local attrId2Val = {}
  60. for _, v in pairs(self.titleData) do
  61. ---@type cfg_fashion_column
  62. local fashionTbl = SL:GetConfig("cfg_fashion", v.confId)
  63. if fashionTbl then
  64. for _, attr in pairs(fashionTbl.att) do
  65. local attrId = attr[1]
  66. local attrVal = attr[2]
  67. if attrId and attrVal then
  68. if not attrId2Val[attrId] then
  69. attrId2Val[attrId] = attrVal
  70. else
  71. attrId2Val[attrId] = attrId2Val[attrId] + attrVal
  72. end
  73. end
  74. end
  75. end
  76. end
  77. --策划要求 最大(小)攻击力提高 最大(小)魔法攻击力 最大(小)攻击力 最大(小)诅咒攻击力 合并写死
  78. local hasAtkUp
  79. local hasAtk
  80. local hasMagic
  81. local hasCurse
  82. if attrId2Val[200011] and attrId2Val[200021] then
  83. local str
  84. if attrId2Val[200011] == attrId2Val[200021] then
  85. str = "<color=#dce1e5>攻击力提高:</color>" .. attrId2Val[200011]
  86. else
  87. str = "<color=#dce1e5>攻击力提高:</color>" .. attrId2Val[200011] .. "~" .. attrId2Val[200021]
  88. end
  89. ---@type cfg_att_info_column
  90. local attrTbl = SL:GetConfig("cfg_att_info", 200011)
  91. table.insert(self.attrData, { str = str, sort = attrTbl.sort })
  92. hasAtkUp = true
  93. end
  94. if attrId2Val[201011] and attrId2Val[201021] then
  95. local str
  96. if attrId2Val[201011] == attrId2Val[201021] then
  97. str = "<color=#dce1e5>攻击力:</color>" .. attrId2Val[201021]
  98. else
  99. str = "<color=#dce1e5>攻击力:</color>" .. attrId2Val[201021] .. "~" .. attrId2Val[201011]
  100. end
  101. ---@type cfg_att_info_column
  102. local attrTbl = SL:GetConfig("cfg_att_info", 201011)
  103. table.insert(self.attrData, { str = str, sort = attrTbl.sort })
  104. hasAtk = true
  105. end
  106. if attrId2Val[202011] and attrId2Val[202021] then
  107. local str
  108. if attrId2Val[202011] == attrId2Val[202021] then
  109. str = "<color=#dce1e5>魔法攻击力:</color>" .. attrId2Val[202021]
  110. else
  111. str = "<color=#dce1e5>魔法攻击力:</color>" .. attrId2Val[202021] .. "~" .. attrId2Val[202011]
  112. end
  113. ---@type cfg_att_info_column
  114. local attrTbl = SL:GetConfig("cfg_att_info", 202011)
  115. table.insert(self.attrData, { str = str, sort = attrTbl.sort })
  116. hasMagic = true
  117. end
  118. if attrId2Val[205011] and attrId2Val[205021] then
  119. local str
  120. if attrId2Val[205011] == attrId2Val[205021] then
  121. str = "<color=#dce1e5>诅咒攻击力:</color>" .. attrId2Val[205011]
  122. else
  123. str = "<color=#dce1e5>诅咒攻击力:</color>" .. attrId2Val[205011] .. "~" .. attrId2Val[205021]
  124. end
  125. ---@type cfg_att_info_column
  126. local attrTbl = SL:GetConfig("cfg_att_info", 205011)
  127. table.insert(self.attrData, { str = str, sort = attrTbl.sort })
  128. hasCurse = true
  129. end
  130. for attrId, attrVal in pairs(attrId2Val) do
  131. local isAdd
  132. if attrId == 200011 or attrId == 200021 then
  133. isAdd = not hasAtkUp
  134. elseif attrId == 201011 or attrId == 201021 then
  135. isAdd = not hasAtk
  136. elseif attrId == 202011 or attrId == 202021 then
  137. isAdd = not hasMagic
  138. elseif attrId == 205011 or attrId == 205021 then
  139. isAdd = not hasCurse
  140. else
  141. isAdd = true
  142. end
  143. if isAdd then
  144. ---@type cfg_att_info_column
  145. local attrTbl = SL:GetConfig("cfg_att_info", attrId)
  146. local str
  147. if attrTbl.remarks == 1 then
  148. str = "<color=#dce1e5>" .. attrTbl.name .. ":</color>" .. attrVal
  149. else
  150. str = "<color=#dce1e5>" .. attrTbl.name .. ":</color>" .. (attrVal / 100) .. "%"
  151. end
  152. table.insert(self.attrData, { str = str, sort = attrTbl.sort })
  153. end
  154. end
  155. table.sort(self.attrData, function(a, b)
  156. return a.sort < b.sort
  157. end)
  158. end
  159. ---注册UI事件和服务器消息
  160. function this:RegistEvents()
  161. GUI:AddOnClickEvent(self.view.BtnClose, self, self.BtnCloseOnClick)
  162. GUI:AddOnClickEvent(self.view.BtnCancel, self, self.BtnCancelOnClick)
  163. GUI:AddOnClickEvent(self.view.BtnSure, self, self.BtnSureOnClick)
  164. SL:RegisterLuaNetMsg(LuaMessageIdToClient.GET_TITLE, self.GET_TITLE, self)
  165. SL:RegisterLuaNetMsg(LuaMessageIdToClient.SETTING_TITLE_APPEAR, self.SETTING_TITLE_APPEAR, self)
  166. end
  167. function this:SETTING_TITLE_APPEAR(_, message)
  168. self.serverTitleId = tonumber(message)
  169. end
  170. --[[
  171. {
  172. title{
  173. {
  174. obtainTime: -- 称号的获取时间
  175. expiresTime: -- 称号的到期时间(到期时间的时间戳) -1为永久
  176. confId:
  177. type: -- 1永久 2限时 3活动限时
  178. },
  179. ...
  180. } -- 称号列表
  181. hidden: --是否隐藏称号
  182. curEquipTitle: --当前穿戴的称号
  183. }
  184. ]]
  185. ---@alias TitleData {obtainTime:number,confId:number,type:number,expiresTime:number}
  186. ---@param message {title:TitleData[],curEquipTitle:number,hidden:boolean}
  187. function this:GET_TITLE(_, message)
  188. self.serverTitleId = tonumber(message.curEquipTitle)
  189. self.curTitleId = tonumber(message.curEquipTitle)
  190. table.clear(self.titleData)
  191. local meTbl
  192. for _, v in pairs(message.title) do
  193. if self.serverTitleId == v.confId then
  194. meTbl = v
  195. else
  196. table.insert(self.titleData, v)
  197. end
  198. end
  199. table.sort(self.titleData, function(a, b)
  200. return a.confId < b.confId
  201. end)
  202. if meTbl then
  203. table.insert(self.titleData, 1, meTbl)
  204. end
  205. GUI:DataListUpdateData(self.view.loopscrollviewData)
  206. self:AnalysisTitleAttrData()
  207. GUI:DataListUpdateData(self.view.datalist11)
  208. end
  209. function this:BtnSureOnClick()
  210. SL:CommonTipsMessage({
  211. stringTblID = 209,
  212. title = "提示",
  213. callback = function()
  214. SL:SendLuaNetMsg(LuaMessageIdToSever.SET_TITLE, { title = self.curTitleId })
  215. self:BtnCloseOnClick()
  216. end
  217. })
  218. end
  219. function this:BtnCancelOnClick()
  220. if self.curTitleId == self.serverTitleId then
  221. self:BtnCloseOnClick()
  222. return
  223. end
  224. self:BtnSureOnClick()
  225. end
  226. function this:BtnCloseOnClick()
  227. GUI:UIPanel_Close("dev/outui/AppearGroup/Panel/KLTitle/KLTitlePanel")
  228. GUI:UIPanel_Close("dev/outui/AppearGroup/Panel/KLAppearGroup/KLAppearGroupPanel")
  229. GUI:UIPanel_Close("dev/outui/AppearGroup/Panel/KLAppearPreview/KLAppearPreviewPanel")
  230. end
  231. function this:Close()
  232. self.curTitleItem = nil
  233. self.curTitleId = nil
  234. self.serverTitleId = nil
  235. SL:onLUAEvent(TITLE_PREVIEW_SELECT_CHANGE)
  236. end
  237. ---@param titleItem KLTitleItem
  238. function this:TitleItemOnClick(titleItem, titleId)
  239. if self.curTitleItem then
  240. self.curTitleItem:SetIsSelect(false)
  241. end
  242. if self.curTitleItem and self.curTitleId == titleId then
  243. self.curTitleId = nil
  244. self.curTitleItem = nil
  245. else
  246. self.curTitleItem = titleItem
  247. self.curTitleId = titleId
  248. titleItem:SetIsSelect(true)
  249. end
  250. SL:onLUAEvent(TITLE_PREVIEW_SELECT_CHANGE, self.curTitleId)
  251. end
  252. return this