---@class KLMainRechargePanel:UIKmlLuaPanelBase ---@field view KLMainRechargePanelView local KLMainRechargePanel = class(UIKmlLuaPanelBase) local this =KLMainRechargePanel function this:AsyncLoadUI() end ---创建时调用一次 function this:Init() self.togDataList = {} --获取sub_mainRecharge表内所有数据 self.togDataList = SL:GetConfigTable("sub_mainRecharge") GUI:DataListInitData(self.view.TogInfoList, function() return self:GetAllTogCount() end,function() end,function() end, function(realIndex) self:TogUpdateFun(realIndex) end) end function this:GetAllTogCount() return table.count(self.togDataList) end function this:togItemOnTog(control,isOn) if GUI:Toggle_getIsOn(control) == "1" or isOn then local subArgs={} if self.args then for key, value in pairs(self.args) do subArgs[key]=value end end subArgs.mainRechargeData = control.mainRechargeData GUI:UIPanel_Open(control.mainRechargeData.subUIRoute,self.view.subParent,self,subArgs) self:OnClickRechargeMask() else GUI:UIPanel_Close(control.mainRechargeData.subUIRoute) end end function this:TogUpdateFun(realIndex) local data = self.togDataList[realIndex + 1] local index = realIndex+1 local togItem = GUI:GetChildControl(self.view.TogInfoList, realIndex, 'togItem') local txt_togName = GUI:GetChildControl(self.view.TogInfoList, realIndex, 'txt_togName') togItem.index = index togItem.togId = data.id togItem.mainRechargeData = data togItem.redControl = GUI:GetChildControl(self.view.TogInfoList, realIndex, 'img_redPoint') self.TogControlList[index] = togItem GUI:setName(togItem,data.togName) GUI:Text_setString(txt_togName,data.showTogName) end ---注册UI事件和服务器消息 function this:RegistEvents() GUI:AddOnClickEvent(self.view.btn_close,self,self.OnClickClose) end function this:OnClickClose() GUI:UIPanel_Close("dev/outui/MainRecharge/Panel/KLMainRecharge/KLMainRechargePanel") SL.ShowMainPanel() end ---界面显示时调用一次 function this:Show() end ---创建或者刷新界面数据时调用 function this:Refresh() self.TogControlList = {} --所有页签组件表 table.sort(self.togDataList,function(a,b) return a.sortId < b.sortId end) SL.HideMainPanel() GUI:DataListUpdateData(self.view.TogInfoList,_,function() self:InitToggles() self:RefreshTogState() self:RefreshIndex() self:RefreshTogRedPointShow() end) end function this:RefreshTogState() for k, v in ipairs(self.TogControlList) do local isShow = this:IsOpenJudge(v.mainRechargeData.showCondition,v.mainRechargeData.id) GUI:SetActive(self.TogControlList[k],isShow) end end function this:IsOpenJudge(condition,id) local isShow = condition == "" or ConditionManager.Check4D(condition) ---if else 可特殊处理页签显示隐藏 return isShow end function this:RefreshIndex() local allClose = true local showIndex = 0 --默认选首个激活页签 for i, value in ipairs(self.TogControlList) do if GUI:getVisible(value) then showIndex = i allClose = false break end end --优选传参页签 --从外部跳转时,传sub_mainRecharge表内id if self.args and self.args.mainRechargeId then local tempID = tonumber(self.args.mainRechargeId) local realWanttedIndex = -1 for _, value in ipairs(self.TogControlList) do if value.togId == tempID then realWanttedIndex = value.index break end end if realWanttedIndex>0 and GUI:getVisible(self.TogControlList[realWanttedIndex]) then showIndex = realWanttedIndex else SL:TipMessage("界面未激活,无法跳转",1,NoticeType.NoticeMid) end end --关闭所有子界面 for _, v in pairs(self.TogControlList) do GUI:UIPanel_Close(v.mainRechargeData.subUIRoute) end if showIndex > 0 and not allClose then GUI:Toggle_setIsOn(self.TogControlList[showIndex],true) self:togItemOnTog(self.TogControlList[showIndex],true) else SL:TipMessage("当前没有开启的活动",1,NoticeType.NoticeMid) end end function this:InitToggles() for _ , v in pairs(self.TogControlList) do GUI:SetToggleOnValueChange(v, self, self.togItemOnTog) end end function this:RefreshTogRedPointShow() for _, v in pairs(self.TogControlList) do if InfoManager.mainRechargeInfo.mainRechargeRedsTbl then if GUI:getVisible(v) then GUI:SetActive(v.redControl,InfoManager.mainRechargeInfo.mainRechargeRedsTbl[v.mainRechargeData.togName]) end end end end function this:OnClickRechargeMask() if self.view == nil then return end---新手礼包那里关闭了界面导致报错 GUI:setVisible(self.view.img_rechargeMask, true) if self.timer then SL:UnSchedule(self.timer) end self.timer = SL:ScheduleOnce(0.5, function() GUI:setVisible(self.view.img_rechargeMask, false) end) end function this:Close() if self.timer then SL:UnSchedule(self.timer) self.timer = nil end SL.ShowMainPanel() end return this