UIOpenServerAthleticsInfo.lua 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. ---@class UIOpenServerAthleticsInfo @注释
  2. ---@field openSerCompetitionTbl cfg_openSerCompetition_column[]
  3. UIOpenServerAthleticsInfo = class()
  4. local this = UIOpenServerAthleticsInfo
  5. function this:ctor()
  6. end
  7. function this:Init()
  8. self.openSerCompetitionTbl = SL:GetConfigTable("cfg_openSerCompetition")
  9. table.sort(self.openSerCompetitionTbl,function(a, b)
  10. return a.order < b.order
  11. end)
  12. self.openSerCompetitionTypeTbl={}
  13. for _,v in pairs(self.openSerCompetitionTbl) do
  14. self.openSerCompetitionTypeTbl[v.type] = v
  15. end
  16. self.openSerCompetitionRankTbl = SL:GetConfigTable("cfg_openSerCompetition_rank")
  17. self.openSerCompetitionChallengeTbl = SL:GetConfigTable("cfg_openSerCompetition_challenge")
  18. self.openSerCompetitionGiftTbl = SL:GetConfigTable("cfg_openSerCompetition_gift")
  19. ---@type cfg_openSerCompetition_rank_column
  20. self.openSerCompetitionRankTblGroup = {}
  21. for _, v in pairs(self.openSerCompetitionRankTbl) do
  22. if not self.openSerCompetitionRankTblGroup[v.rankGroup] then
  23. self.openSerCompetitionRankTblGroup[v.rankGroup] = {}
  24. end
  25. if not self.openSerCompetitionRankTblGroup[v.rankGroup][v.rank] then
  26. self.openSerCompetitionRankTblGroup[v.rankGroup][v.rank] = {}
  27. end
  28. self.openSerCompetitionRankTblGroup[v.rankGroup][v.rank] = v
  29. end
  30. ----------------------------------------------------------------------
  31. ---@type cfg_openSerCompetition_challenge_column
  32. self.openSerCompetitionChallengeTblGroup = {}
  33. for _, v in pairs(self.openSerCompetitionChallengeTbl) do
  34. if not self.openSerCompetitionChallengeTblGroup[v.challengeGroup] then
  35. self.openSerCompetitionChallengeTblGroup[v.challengeGroup] = {}
  36. end
  37. table.insert(self.openSerCompetitionChallengeTblGroup[v.challengeGroup],v)
  38. end
  39. --------------------------------------------------------------------
  40. self.openSerCompetitionGiftTblGroup = {}
  41. self:Reset()
  42. self:InitData()
  43. self:RegistMessages()
  44. end
  45. function this:Reset()
  46. self.RankDataList = {} ---排行
  47. self.PersonDataList = {} --个人积分
  48. end
  49. function this:InitData()
  50. end
  51. function this:RegistMessages()
  52. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_COMPETITION_RANK_INFO, self.RES_COMPETITION_RANK_INFO, self)-- 响应开服竞技排行信息
  53. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_SINGLE_CHALLENGE_INFO, self.RES_SINGLE_CHALLENGE_INFO, self)-- 响应开服竞技个人挑战领取信息
  54. --SL:RegisterLUAEvent(LUA_OPEN_SERVER_GIFT_COUNT_CHANGE, self.LUA_OPEN_SERVER_GIFT_COUNT_CHANGE, self)
  55. SL:RegisterLUAEvent(LUA_EVENT_ENTRY_MAP_LOADING_PANEL_CLOSE, self.InitGiftTblData, self)
  56. SL:RegisterLUAEvent(LUA_EVENT_CAREER_CHANGED, self.InitGiftTblData, self)
  57. end
  58. function this:InitGiftTblData()
  59. local careerId = SL:GetMetaValue(EMetaVarGetKey.JOB)
  60. self.openSerCompetitionGiftTblGroup = {}
  61. if not careerId then return false end
  62. local index = 1
  63. if self.openSerCompetitionTbl then
  64. for _, Tbl in pairs(self.openSerCompetitionTbl) do
  65. for _,gift in pairs(Tbl.gift) do
  66. if gift[1] == careerId or gift[1] == 0 then
  67. for i, id in pairs(gift) do
  68. if i ~= 1 then
  69. local data = SL:GetConfig("cfg_openSerCompetition_gift", id)
  70. if not self.openSerCompetitionGiftTblGroup[Tbl.type] then
  71. self.openSerCompetitionGiftTblGroup[Tbl.type] = {}
  72. end
  73. self.openSerCompetitionGiftTblGroup[Tbl.type][index] = data
  74. index = index + 1
  75. end
  76. end
  77. end
  78. end
  79. end
  80. end
  81. end
  82. function this:RES_COMPETITION_RANK_INFO(_, message)
  83. if message then
  84. self.RankDataList[message.type] = message
  85. SL:onLUAEvent(LUA_EVENT_COMPETITION_RANK_CHANGE, message.type)
  86. end
  87. end
  88. function this:RES_SINGLE_CHALLENGE_INFO(_, message)
  89. if message then
  90. self.PersonDataList[message.type] = message
  91. SL:onLUAEvent(LUA_EVENT_SINGLE_CHALLENGE_CHANGE, message.type)
  92. SL:RefreshPanelALLRedStateKmlByCondition("KLUISystemTopPanel")
  93. end
  94. end
  95. function this:GetOpenSerCompetitionTblDataByType(type)
  96. for _, v in pairs(self.openSerCompetitionTbl)do
  97. if v.type == type then
  98. return v
  99. end
  100. end
  101. return nil
  102. end
  103. function this:FindRankTblByType(type)
  104. local rankGroup = 1
  105. for _, v in pairs(self.openSerCompetitionTbl) do
  106. if v.type == type then
  107. rankGroup = v.rankGroup
  108. end
  109. end
  110. return rankGroup
  111. end
  112. function this:FindChallengeTblByType(type)
  113. local challengeGroup = 1
  114. for _, v in pairs(self.openSerCompetitionTbl) do
  115. if v.type == type then
  116. challengeGroup = v.challengeGroup
  117. end
  118. end
  119. return challengeGroup
  120. end
  121. function this:ShowBtnCondition()
  122. local ShowTypeList= {}
  123. for i,v in pairs(self.openSerCompetitionTbl) do
  124. local showCondition = v.showCondition
  125. local activityCondition = v.activityCondition
  126. local nextShowCondition = "false"
  127. if self.openSerCompetitionTbl[i + 1] then
  128. nextShowCondition = self.openSerCompetitionTbl[i + 1].showCondition
  129. end
  130. if showCondition == "" or ConditionManager.Check4D(showCondition) then
  131. if activityCondition == "" or ConditionManager.Check4D(activityCondition) then
  132. table.insert(ShowTypeList,v)
  133. end
  134. end
  135. end
  136. return ShowTypeList
  137. end
  138. function this:IsShowPersonAwardRed()
  139. local IsShow =false
  140. if table.isNullOrEmpty(self.PersonDataList) then return IsShow end
  141. local ShowTypeList = self:ShowBtnCondition()
  142. for _,Btn in pairs(ShowTypeList) do
  143. for _,v in pairs(self.PersonDataList) do
  144. if tonumber(v.type) == tonumber(Btn.type) then
  145. for _,ChallengeTbl in pairs(self.openSerCompetitionChallengeTblGroup[tonumber(v.type)]) do
  146. if v.num >= ChallengeTbl.typeDemandValue then
  147. IsShow= true
  148. for key, item in pairs(v.challengeAwardInfo) do
  149. if ChallengeTbl.id == tonumber(key) then
  150. IsShow= false
  151. end
  152. end
  153. if IsShow == true then
  154. return IsShow
  155. end
  156. end
  157. end
  158. end
  159. end
  160. end
  161. return IsShow
  162. end
  163. function this:IsShowGiftRed()
  164. local IsShow =false
  165. local ShowTypeList = self:ShowBtnCondition()
  166. for _,Btn in pairs(ShowTypeList) do
  167. if not table.isNullOrEmpty(self.openSerCompetitionGiftTblGroup) then
  168. for _, Tbl in pairs(self.openSerCompetitionGiftTblGroup[Btn.type]) do
  169. local buycount, totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(Tbl.count)
  170. if buycount > 0 then
  171. if Tbl.buyConsume[2] == 0 then
  172. IsShow= true
  173. return IsShow
  174. end
  175. end
  176. end
  177. end
  178. end
  179. return IsShow
  180. end
  181. function this:IsShowPersonAwardRedBtn(index)
  182. local IsShow =false
  183. if table.isNullOrEmpty(self.PersonDataList) then return IsShow end
  184. local ShowTypeList = self:ShowBtnCondition()
  185. for _,Btn in pairs(ShowTypeList) do
  186. for _,v in pairs(self.PersonDataList) do
  187. if tonumber(v.type) == Btn.type then
  188. if tonumber(v.type) == index then
  189. for _,ChallengeTbl in pairs(self.openSerCompetitionChallengeTblGroup[index]) do
  190. if v.num >= ChallengeTbl.typeDemandValue then
  191. IsShow= true
  192. for key, item in pairs(v.challengeAwardInfo) do
  193. if ChallengeTbl.id == tonumber(key) then
  194. IsShow= false
  195. end
  196. end
  197. if IsShow == true then
  198. return IsShow
  199. end
  200. end
  201. end
  202. end
  203. end
  204. end
  205. end
  206. return IsShow
  207. end
  208. function this:IsShowGiftRedBtn(index)
  209. local IsShow =false
  210. local ShowTypeList = self:ShowBtnCondition()
  211. for _,Btn in pairs(ShowTypeList) do
  212. if Btn.type == index then
  213. if not table.isNullOrEmpty(self.openSerCompetitionGiftTblGroup) then
  214. for _, Tbl in pairs(self.openSerCompetitionGiftTblGroup[Btn.type]) do
  215. local buycount, totalcount = InfoManager.countInfo:GetLimitAndTotalCountByKey(Tbl.count)
  216. if buycount > 0 then
  217. if Tbl.buyConsume[2] == 0 then
  218. IsShow= true
  219. return IsShow
  220. end
  221. end
  222. end
  223. end
  224. end
  225. end
  226. return IsShow
  227. end
  228. function this:IsShowRed()
  229. if self:IsShowPersonAwardRed() or self:IsShowGiftRed() then
  230. return true
  231. end
  232. return false
  233. end