KLMainOperateActivityPanel.lua 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. ---@class KLMainOperateActivityPanel:UIKmlLuaPanelBase
  2. ---@field view KLMainOperateActivityPanelView
  3. local KLMainOperateActivityPanel = class(UIKmlLuaPanelBase)
  4. local this =KLMainOperateActivityPanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. self.togDataList = {}
  10. GUI:DataListInitData(self.view.TogInfoList, function()
  11. return self:GetAllTogCount()
  12. end,function()
  13. end,function()
  14. end, function(realIndex)
  15. self:TogUpdateFun(realIndex)
  16. end)
  17. end
  18. function this:GetAllTogCount()
  19. return table.count(self.togDataList)
  20. end
  21. function this:togItemOnTog(control,isOn)
  22. if GUI:Toggle_getIsOn(control) == "1" or isOn then
  23. local subArgs={}
  24. if self.args then
  25. for key, value in pairs(self.args) do
  26. subArgs[key]=value
  27. end
  28. end
  29. subArgs.mainOperateData = control.mainOperateData
  30. GUI:UIPanel_Open(control.mainOperateData.subUIRoute,self.view.subParent,self,subArgs)
  31. self:OnClickMainOperateMask()
  32. else
  33. GUI:UIPanel_Close(control.mainOperateData.subUIRoute)
  34. end
  35. end
  36. function this:TogUpdateFun(realIndex)
  37. local data = self.togDataList[realIndex + 1]
  38. local index = realIndex+1
  39. local togItem = GUI:GetChildControl(self.view.TogInfoList, realIndex, 'togItem')
  40. local txt_togName = GUI:GetChildControl(self.view.TogInfoList, realIndex, 'txt_togName')
  41. togItem.index = index
  42. togItem.togId = data.id
  43. togItem.mainOperateData = data
  44. togItem.redControl = GUI:GetChildControl(self.view.TogInfoList, realIndex, 'img_redPoint')
  45. self.TogControlList[index] = togItem
  46. GUI:setName(togItem,data.togName)
  47. GUI:Text_setString(txt_togName,data.togShowName)
  48. end
  49. ---注册UI事件和服务器消息
  50. function this:RegistEvents()
  51. GUI:AddOnClickEvent(self.view.btn_close,self,self.OnClickClose)
  52. SL:RegisterLUAEvent(LUA_EVENT_MAINOPERATEACTIVITY_CHANGE, self.RefreshTogAndTitleShow, self)
  53. end
  54. function this:OnClickClose()
  55. GUI:UIPanel_Close("dev/outui/MainOperateActivity/Panel/KLMainOperateActivity/KLMainOperateActivityPanel")
  56. SL.ShowMainPanel()
  57. end
  58. ---界面显示时调用一次
  59. function this:Show()
  60. end
  61. function this:RefreshTogState()
  62. for k, _ in ipairs(self.TogControlList) do
  63. GUI:SetActive(self.TogControlList[k],true)
  64. end
  65. end
  66. function this:RefreshIndex()
  67. self:RefreshTogAndTitleShow()
  68. local allClose = true
  69. local showIndex = 0
  70. --默认选首个激活页签
  71. for i, value in ipairs(self.TogControlList) do
  72. if GUI:getVisible(value) then
  73. showIndex = i
  74. allClose = false
  75. break
  76. end
  77. end
  78. --优选传参页签
  79. --从外部跳转时,传cfg_sub_OperateActivity表内id
  80. if self.args and self.args.mainOperateActivityId then
  81. local tempID = tonumber(self.args.mainOperateActivityId)
  82. local realWanttedIndex = -1
  83. for _, value in ipairs(self.TogControlList) do
  84. if value.togId == tempID then
  85. realWanttedIndex = value.index
  86. break
  87. end
  88. end
  89. if realWanttedIndex>0 and GUI:getVisible(self.TogControlList[realWanttedIndex]) then
  90. showIndex = realWanttedIndex
  91. else
  92. SL:TipMessage("界面未激活,无法跳转",1,NoticeType.NoticeMid)
  93. end
  94. end
  95. --关闭所有子界面
  96. for _, v in pairs(self.TogControlList) do
  97. GUI:UIPanel_Close(v.mainOperateData.subUIRoute)
  98. end
  99. if showIndex > 0 and not allClose then
  100. GUI:Toggle_setIsOn(self.TogControlList[showIndex],true)
  101. self:togItemOnTog(self.TogControlList[showIndex],true)
  102. else
  103. SL:TipMessage("当前没有开启的活动",1,NoticeType.NoticeMid)
  104. end
  105. end
  106. --刷新活动标题
  107. function this:RefreshTogAndTitleShow()
  108. local titleName = "好运假日" --初始标题
  109. if InfoManager.mainOperateActivityInfo.isOperateActivityMainBtnShow then
  110. if (not table.isNullOrEmpty(InfoManager.mainOperateActivityInfo.operateMainActivityData)) and
  111. (not table.isNullOrEmpty(InfoManager.mainOperateActivityInfo.operateMainActivityData.operateActivityAllInfo)) then
  112. titleName = InfoManager.mainOperateActivityInfo.operateMainActivityData.operateActivityAllInfo.showTitle
  113. end
  114. end
  115. GUI:Text_setString(self.view.txt_title,titleName)
  116. self:GetAllShowTogData()
  117. end
  118. function this:GetAllShowTogData()
  119. if InfoManager.mainOperateActivityInfo.isOperateHaveShowPanel then
  120. local showTbl = InfoManager.mainOperateActivityInfo.operateMainActivityData.allShowPanelData
  121. if not table.isNullOrEmpty(showTbl) then
  122. table.sort(showTbl,function(a,b)
  123. return a.sortId < b.sortId
  124. end)
  125. self.togDataList = showTbl
  126. GUI:DataListUpdateData(self.view.TogInfoList)
  127. end
  128. end
  129. end
  130. ---创建或者刷新界面数据时调用
  131. function this:Refresh()
  132. --self:GetAllShowTogData()
  133. self.TogControlList = {} --所有页签组件表
  134. SL.HideMainPanel()
  135. local isDelayCall = false
  136. if InfoManager.mainOperateActivityInfo.isOperateHaveShowPanel then
  137. local showTbl = InfoManager.mainOperateActivityInfo.operateMainActivityData.allShowPanelData
  138. if not table.isNullOrEmpty(showTbl) then
  139. table.sort(showTbl,function(a,b)
  140. return a.sortId < b.sortId
  141. end)
  142. self.togDataList = showTbl
  143. isDelayCall = true
  144. GUI:DataListUpdateData(self.view.TogInfoList,_,function()
  145. self:InitToggles()
  146. self:RefreshTogState()
  147. self:RefreshIndex()
  148. self:RefreshTogRedPointShow()
  149. end)
  150. end
  151. end
  152. if not isDelayCall then
  153. self:InitToggles()
  154. self:RefreshTogState()
  155. self:RefreshIndex()
  156. self:RefreshTogRedPointShow()
  157. end
  158. end
  159. function this:InitToggles()
  160. for _ , v in pairs(self.TogControlList) do
  161. GUI:SetToggleOnValueChange(v, self, self.togItemOnTog)
  162. end
  163. end
  164. function this:RefreshTogRedPointShow()
  165. for _, v in pairs(self.TogControlList) do
  166. if InfoManager.mainOperateActivityInfo.operateMainActivityRedsTbl then
  167. if GUI:getVisible(v) then
  168. GUI:SetActive(v.redControl,InfoManager.mainOperateActivityInfo.operateMainActivityRedsTbl[v.mainOperateData.togName])
  169. end
  170. end
  171. end
  172. end
  173. function this:OnClickMainOperateMask()
  174. GUI:setVisible(self.view.img_mainOperateMask, true)
  175. if self.timer then
  176. SL:UnSchedule(self.timer)
  177. end
  178. self.timer = SL:ScheduleOnce(0.5, function()
  179. GUI:setVisible(self.view.img_mainOperateMask, false)
  180. end)
  181. end
  182. function this:Hide()
  183. end
  184. function this:Close()
  185. if self.timer then
  186. SL:UnSchedule(self.timer)
  187. self.timer = nil
  188. end
  189. SL.ShowMainPanel()
  190. end
  191. return this