KLMainActivityPanel.lua 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. ---@class KLMainActivityPanel:UIKmlLuaPanelBase
  2. ---@field view KLMainActivityPanelView
  3. local KLMainActivityPanel = class(UIKmlLuaPanelBase)
  4. local this =KLMainActivityPanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. self.togDataList = {}
  10. --获取sub_mainActivity表内所有数据
  11. self.togDataList = SL:GetConfigTable("sub_mainActivity")
  12. GUI:DataListInitData(self.view.TogInfoList, function()
  13. return self:GetAllTogCount()
  14. end,function()
  15. end,function()
  16. end, function(realIndex)
  17. self:TogUpdateFun(realIndex)
  18. end)
  19. end
  20. function this:GetAllTogCount()
  21. return table.count(self.togDataList)
  22. end
  23. function this:togItemOnTog(control,isOn)
  24. if GUI:Toggle_getIsOn(control) == "1" or isOn then
  25. local subArgs={}
  26. if self.args then
  27. for key, value in pairs(self.args) do
  28. subArgs[key]=value
  29. end
  30. end
  31. subArgs.mainActivityData = control.mainActivityData
  32. GUI:UIPanel_Open(control.mainActivityData.subUIRoute,self.view.subParent,self,subArgs)
  33. self:OnClickActivityMask()
  34. else
  35. GUI:UIPanel_Close(control.mainActivityData.subUIRoute)
  36. end
  37. end
  38. function this:TogUpdateFun(realIndex)
  39. local data = self.togDataList[realIndex + 1]
  40. local index = realIndex+1
  41. local togItem = GUI:GetChildControl(self.view.TogInfoList, realIndex, 'togItem')
  42. local txt_togName = GUI:GetChildControl(self.view.TogInfoList, realIndex, 'txt_togName')
  43. local img_corner = GUI:GetChildControl(self.view.TogInfoList, realIndex, 'img_corner')
  44. GUI:SetActive(img_corner,false)
  45. if data.cornerType ~= 0 then --配0不展示角标
  46. GUI:SetActive(img_corner,true)
  47. if data.cornerType == 1 then
  48. GUI:Image_loadTexture(img_corner, "img_xianshi","Atlas/QJ5_MainActivityPanel.spriteatlas")
  49. end
  50. end
  51. togItem.index = index
  52. togItem.togId = data.id
  53. togItem.mainActivityData = data
  54. togItem.redControl = GUI:GetChildControl(self.view.TogInfoList, realIndex, 'img_redPoint')
  55. self.TogControlList[index] = togItem
  56. GUI:setName(togItem,data.togName)
  57. GUI:Text_setString(txt_togName,data.showTogName)
  58. end
  59. ---注册UI事件和服务器消息
  60. function this:RegistEvents()
  61. GUI:AddOnClickEvent(self.view.btn_close,self,self.OnClickClose)
  62. end
  63. function this:OnClickClose()
  64. GUI:UIPanel_Close("dev/outui/MainActivity/Panel/KLMainActivity/KLMainActivityPanel")
  65. SL.ShowMainPanel()
  66. end
  67. ---界面显示时调用一次
  68. function this:Show()
  69. end
  70. ---创建或者刷新界面数据时调用
  71. function this:Refresh()
  72. self.TogControlList = {} --所有页签组件表
  73. table.sort(self.togDataList,function(a,b)
  74. return a.sortId < b.sortId
  75. end)
  76. SL.HideMainPanel()
  77. GUI:DataListUpdateData(self.view.TogInfoList,_,function()
  78. self:InitToggles()
  79. self:RefreshTogState()
  80. self:RefreshIndex()
  81. self:RefreshTogRedPointShow()
  82. InfoManager.mainActivityInfo:RefreshMainActivityRedPoint("tog_OpenServerAthletics",InfoManager.openServerAthleticsInfo:IsShowRed())
  83. end)
  84. end
  85. function this:RefreshTogState()
  86. for k, v in ipairs(self.TogControlList) do
  87. local isShow = this:IsOpenJudge(v.mainActivityData.showCondition,v.mainActivityData.id)
  88. GUI:SetActive(self.TogControlList[k],isShow)
  89. end
  90. end
  91. function this:IsOpenJudge(condition,id)
  92. local isShow = condition == "" or ConditionManager.Check4D(condition)
  93. ---if else 可特殊处理页签显示隐藏
  94. return isShow
  95. end
  96. function this:RefreshIndex()
  97. local allClose = true
  98. local showIndex = 0
  99. --默认选首个激活页签
  100. for i, value in ipairs(self.TogControlList) do
  101. if GUI:getVisible(value) then
  102. showIndex = i
  103. allClose = false
  104. break
  105. end
  106. end
  107. --优选传参页签
  108. --从外部跳转时,传sub_mainActivity表内id
  109. if self.args and self.args.mainActivityId then
  110. local tempID = tonumber(self.args.mainActivityId)
  111. local realWanttedIndex = -1
  112. for _, value in ipairs(self.TogControlList) do
  113. if value.togId == tempID then
  114. realWanttedIndex = value.index
  115. break
  116. end
  117. end
  118. if realWanttedIndex>0 and GUI:getVisible(self.TogControlList[realWanttedIndex]) then
  119. showIndex = realWanttedIndex
  120. else
  121. SL:TipMessage("界面未激活,无法跳转",1,NoticeType.NoticeMid)
  122. end
  123. end
  124. --关闭所有子界面
  125. for _, v in pairs(self.TogControlList) do
  126. GUI:UIPanel_Close(v.mainActivityData.subUIRoute)
  127. end
  128. if showIndex > 0 and not allClose then
  129. GUI:Toggle_setIsOn(self.TogControlList[showIndex],true)
  130. self:togItemOnTog(self.TogControlList[showIndex],true)
  131. else
  132. SL:TipMessage("当前没有开启的活动",1,NoticeType.NoticeMid)
  133. end
  134. end
  135. function this:InitToggles()
  136. for _ , v in pairs(self.TogControlList) do
  137. GUI:SetToggleOnValueChange(v, self, self.togItemOnTog)
  138. end
  139. end
  140. function this:RefreshTogRedPointShow()
  141. for _, v in pairs(self.TogControlList) do
  142. if InfoManager.mainActivityInfo.mainActivityRedsTbl then
  143. if GUI:getVisible(v) then
  144. GUI:SetActive(v.redControl,InfoManager.mainActivityInfo.mainActivityRedsTbl[v.mainActivityData.togName])
  145. end
  146. end
  147. end
  148. end
  149. function this:OnClickActivityMask()
  150. GUI:setVisible(self.view.img_activityMask, true)
  151. if self.timer then
  152. SL:UnSchedule(self.timer)
  153. end
  154. self.timer = SL:ScheduleOnce(0.5, function()
  155. GUI:setVisible(self.view.img_activityMask, false)
  156. end)
  157. end
  158. function this:Close()
  159. if self.timer then
  160. SL:UnSchedule(self.timer)
  161. self.timer = nil
  162. end
  163. SL.ShowMainPanel()
  164. end
  165. return this