KLMainRechargePanel.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. ---@class KLMainRechargePanel:UIKmlLuaPanelBase
  2. ---@field view KLMainRechargePanelView
  3. local KLMainRechargePanel = class(UIKmlLuaPanelBase)
  4. local this =KLMainRechargePanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. self.togDataList = {}
  10. --获取sub_mainRecharge表内所有数据
  11. self.togDataList = SL:GetConfigTable("sub_mainRecharge")
  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.mainRechargeData = control.mainRechargeData
  32. GUI:UIPanel_Open(control.mainRechargeData.subUIRoute,self.view.subParent,self,subArgs)
  33. self:OnClickRechargeMask()
  34. else
  35. GUI:UIPanel_Close(control.mainRechargeData.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. togItem.index = index
  44. togItem.togId = data.id
  45. togItem.mainRechargeData = data
  46. togItem.redControl = GUI:GetChildControl(self.view.TogInfoList, realIndex, 'img_redPoint')
  47. self.TogControlList[index] = togItem
  48. GUI:setName(togItem,data.togName)
  49. GUI:Text_setString(txt_togName,data.showTogName)
  50. end
  51. ---注册UI事件和服务器消息
  52. function this:RegistEvents()
  53. GUI:AddOnClickEvent(self.view.btn_close,self,self.OnClickClose)
  54. end
  55. function this:OnClickClose()
  56. GUI:UIPanel_Close("dev/outui/MainRecharge/Panel/KLMainRecharge/KLMainRechargePanel")
  57. SL.ShowMainPanel()
  58. end
  59. ---界面显示时调用一次
  60. function this:Show()
  61. end
  62. ---创建或者刷新界面数据时调用
  63. function this:Refresh()
  64. self.TogControlList = {} --所有页签组件表
  65. table.sort(self.togDataList,function(a,b)
  66. return a.sortId < b.sortId
  67. end)
  68. SL.HideMainPanel()
  69. GUI:DataListUpdateData(self.view.TogInfoList,_,function()
  70. self:InitToggles()
  71. self:RefreshTogState()
  72. self:RefreshIndex()
  73. self:RefreshTogRedPointShow()
  74. end)
  75. end
  76. function this:RefreshTogState()
  77. for k, v in ipairs(self.TogControlList) do
  78. local isShow = this:IsOpenJudge(v.mainRechargeData.showCondition,v.mainRechargeData.id)
  79. GUI:SetActive(self.TogControlList[k],isShow)
  80. end
  81. end
  82. function this:IsOpenJudge(condition,id)
  83. local isShow = condition == "" or ConditionManager.Check4D(condition)
  84. ---if else 可特殊处理页签显示隐藏
  85. return isShow
  86. end
  87. function this:RefreshIndex()
  88. local allClose = true
  89. local showIndex = 0
  90. --默认选首个激活页签
  91. for i, value in ipairs(self.TogControlList) do
  92. if GUI:getVisible(value) then
  93. showIndex = i
  94. allClose = false
  95. break
  96. end
  97. end
  98. --优选传参页签
  99. --从外部跳转时,传sub_mainRecharge表内id
  100. if self.args and self.args.mainRechargeId then
  101. local tempID = tonumber(self.args.mainRechargeId)
  102. local realWanttedIndex = -1
  103. for _, value in ipairs(self.TogControlList) do
  104. if value.togId == tempID then
  105. realWanttedIndex = value.index
  106. break
  107. end
  108. end
  109. if realWanttedIndex>0 and GUI:getVisible(self.TogControlList[realWanttedIndex]) then
  110. showIndex = realWanttedIndex
  111. else
  112. SL:TipMessage("界面未激活,无法跳转",1,NoticeType.NoticeMid)
  113. end
  114. end
  115. --关闭所有子界面
  116. for _, v in pairs(self.TogControlList) do
  117. GUI:UIPanel_Close(v.mainRechargeData.subUIRoute)
  118. end
  119. if showIndex > 0 and not allClose then
  120. GUI:Toggle_setIsOn(self.TogControlList[showIndex],true)
  121. self:togItemOnTog(self.TogControlList[showIndex],true)
  122. else
  123. SL:TipMessage("当前没有开启的活动",1,NoticeType.NoticeMid)
  124. end
  125. end
  126. function this:InitToggles()
  127. for _ , v in pairs(self.TogControlList) do
  128. GUI:SetToggleOnValueChange(v, self, self.togItemOnTog)
  129. end
  130. end
  131. function this:RefreshTogRedPointShow()
  132. for _, v in pairs(self.TogControlList) do
  133. if InfoManager.mainRechargeInfo.mainRechargeRedsTbl then
  134. if GUI:getVisible(v) then
  135. GUI:SetActive(v.redControl,InfoManager.mainRechargeInfo.mainRechargeRedsTbl[v.mainRechargeData.togName])
  136. end
  137. end
  138. end
  139. end
  140. function this:OnClickRechargeMask()
  141. if self.view == nil then return end---新手礼包那里关闭了界面导致报错
  142. GUI:setVisible(self.view.img_rechargeMask, true)
  143. if self.timer then
  144. SL:UnSchedule(self.timer)
  145. end
  146. self.timer = SL:ScheduleOnce(0.5, function()
  147. GUI:setVisible(self.view.img_rechargeMask, false)
  148. end)
  149. end
  150. function this:Close()
  151. if self.timer then
  152. SL:UnSchedule(self.timer)
  153. self.timer = nil
  154. end
  155. SL.ShowMainPanel()
  156. end
  157. return this