KLUIInfoPanel.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. ---@class KLUIInfoPanel:UIKmlLuaPanelBase
  2. ---@field view KLUIInfoPanelView
  3. local KLUIInfoPanel = class(UIKmlLuaPanelBase)
  4. local this = KLUIInfoPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. GUI:DataListInitData(self.view.attr_datalist, function()
  8. return self:ItemCountFunc()
  9. end, function(realIndex)
  10. return self:ItemGetFunc(realIndex)
  11. end, function(realIndex, kmlcontrol)
  12. return self:ItemInitFunc(realIndex, kmlcontrol)
  13. end, function(realIndex, kmlcontrol)
  14. return self:ItemUpdateFunc(realIndex, kmlcontrol)
  15. end)
  16. ---@type cfg_global_column
  17. local tbl_str = SL:GetConfig("cfg_global", 84)
  18. if tbl_str then
  19. local tbl = string.split(tbl_str.value, '#')
  20. self.intervalTime = tonumber(tbl[1]) / 1000
  21. self.showTime = tonumber(tbl[2]) / 1000
  22. else
  23. self.intervalTime = 0.1
  24. self.showTime = 2
  25. end
  26. ---@type cfg_global_column
  27. local cfg = SL:GetConfig("cfg_global", 1702)
  28. self.limitIndex = cfg and tonumber(cfg.value) or 10
  29. ---@type KLUIInfoChangeItem[]
  30. self.attrItemList = {}
  31. self.totalQueue = {}
  32. self.tempMinAttrValue = {}
  33. self.attrQueue = {}
  34. self.tempAttrList = {}
  35. self.totalItemNum = 0
  36. self.itemIndex = 0
  37. self.listIsReady = false
  38. end
  39. function this:ItemCountFunc()
  40. return self.limitIndex
  41. end
  42. function this:ItemGetFunc(realIndex)
  43. local item = GUI:UIPanel_Open("dev/ui/Role/Item/KLUIInfoChange/KLUIInfoChangeItem", self.view.attr_datalist, self, { baseUI = self }, true)
  44. self.attrItemList[realIndex + 1] = item
  45. return item.view.root
  46. end
  47. function this:ItemInitFunc(realIndex, kmlcontrol)
  48. end
  49. function this:ItemUpdateFunc(realIndex, rectTrans)
  50. end
  51. ---创建或者刷新界面数据时调用
  52. function this:Refresh()
  53. GUI:DataListUpdateData(self.view.attr_datalist, nil, function()
  54. self.listIsReady = true
  55. end)
  56. end
  57. ---注册UI事件和服务器消息
  58. function this:RegistEvents()
  59. SL:RegisterLUAEvent(LUA_EVENT_FIGHT_ATT_CHANGE, self.RoleDat_Me_FightAttrChange, self)
  60. end
  61. ---@param message MapProtos.FightAttrInfoRes
  62. function this:RoleDat_Me_FightAttrChange(_, message)
  63. ---最小攻击力
  64. local dcNum = 0
  65. ---最小魔法攻击力
  66. local mcNum = 0
  67. ---最小诅咒攻击力
  68. local zzNum = 0
  69. local tempAttrList = {}
  70. for i, v in pairs(message) do
  71. ---@type cfg_att_info_column
  72. local attrTbl = SL:GetConfig("cfg_att_info", v.type)
  73. local isMainShow = attrTbl.isMainshow
  74. local isShow = false
  75. if isMainShow[1] == 1 then
  76. isShow = true
  77. elseif isMainShow[1] == 2 then
  78. local baseCareer = SL:GetMetaValue(EMetaVarGetKey.JOB)
  79. if baseCareer == 2 then
  80. isShow = table.count(isMainShow, 2) >= 2
  81. else
  82. isShow = table.contains(isMainShow, baseCareer)
  83. end
  84. end
  85. if isShow then
  86. if v.type == EMUCharacterAttrType.minDC then
  87. dcNum = v.num
  88. elseif v.type == EMUCharacterAttrType.minMC then
  89. mcNum = v.num
  90. elseif v.type == EMUCharacterAttrType.minZuZhou then
  91. zzNum = v.num
  92. else
  93. table.insert(tempAttrList, v)
  94. end
  95. end
  96. end
  97. if #tempAttrList > 0 then
  98. if #self.totalQueue > 0 then
  99. local list = self.totalQueue[1]
  100. for i, v in ipairs(tempAttrList) do
  101. table.insert(list, v)
  102. end
  103. self.totalQueue[1] = list
  104. else
  105. self.totalQueue[#self.totalQueue + 1] = tempAttrList
  106. self.tempMinAttrValue[#self.totalQueue] = { minDC = dcNum, minMC = mcNum, minZZ = zzNum }
  107. end
  108. self:RefreshAttrQueue()
  109. end
  110. end
  111. function this:RefreshTotalItemNum()
  112. self.totalItemNum = self.totalItemNum - 1
  113. if self.totalItemNum <= 0 then
  114. self.totalItemNum = 0
  115. self.itemIndex = 0
  116. self:RefreshAttrQueue()
  117. end
  118. end
  119. function this:RefreshAttrQueue()
  120. if not self.listIsReady then
  121. return
  122. end
  123. if not self.scheduleId and self.totalItemNum == 0 then
  124. self.attrQueue = table.remove(self.totalQueue, 1)
  125. self.tempAttrList = table.remove(self.tempMinAttrValue, 1)
  126. if self.attrQueue then
  127. self.scheduleId = SL:Schedule(self.scheduleId, 0, self.intervalTime, -1, function()
  128. local data = table.remove(self.attrQueue, 1)
  129. if data then
  130. self.itemIndex = self.itemIndex + 1
  131. local ui = self.attrItemList[self.itemIndex]
  132. ui:RefreshUI(data, self.tempAttrList.minDC, self.tempAttrList.minMC, self.tempAttrList.minZZ, self.showTime)
  133. ui:ShowUI()
  134. if self.itemIndex >= self.limitIndex then
  135. self.itemIndex = 0
  136. end
  137. self.totalItemNum = self.totalItemNum + 1
  138. else
  139. SL:UnSchedule(self.scheduleId)
  140. self.scheduleId = nil
  141. end
  142. end)
  143. end
  144. end
  145. end
  146. function this:Close()
  147. if self.scheduleId then
  148. SL:UnSchedule(self.scheduleId)
  149. self.scheduleId = nil
  150. end
  151. self.totalQueue = {}
  152. self.tempMinAttrValue = {}
  153. self.attrQueue = {}
  154. self.tempAttrList = {}
  155. self.totalItemNum = 0
  156. self.itemIndex = 0
  157. end
  158. return this