require("Base/BasePanel") MissionDailyPanel = Inherit(BasePanel) local this = MissionDailyPanel --子模块脚本 local contentScripts = { --日常 [1] = {view = require("Modules/Mission/MissionDailyPanel_Daily"), panelName = "MissionDailyPanel_Daily",type=1}, --成就 [2] = {view = require("Modules/Mission/MissionDailyPanel_Achievement"), panelName = "MissionDailyPanel_Achievement",type=2}, } local TabBox = require("Modules/Common/TabBox") local _TabData={ [1] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = Language[11358] }, [2] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = Language[11359] }, } local _TabFontColor = { default = Color.New(130 / 255, 128 / 255, 120 / 255, 1), select = Color.New(243 / 255, 235 / 255, 202 / 255, 1)} --子模块预设 local contentPrefabs={} --打开弹窗索引 local index=0 local redPointList --初始化组件(用于子类重写) function MissionDailyPanel:InitComponent() this.tabBox = Util.GetGameObject(self.gameObject, "TabBox") this.TabCtrl = TabBox.New() this.closeBtn = Util.GetGameObject(self.transform, "bg/closeBtn") this.titleText = Util.GetGameObject(self.transform, "bg/titleText"):GetComponent("Text") this.contents = Util.GetGameObject(self.transform, "Contents") --子模块脚本初始化 for i = 1, #contentScripts do contentScripts[i].view:InitComponent(Util.GetGameObject(this.contents, contentScripts[i].panelName)) end --预设赋值 for i=1,#contentScripts do contentPrefabs[i]=Util.GetGameObject(this.contents,contentScripts[i].panelName) end end --绑定事件(用于子类重写) function MissionDailyPanel:BindEvent() Util.AddClick(this.closeBtn, function() self:ClosePanel() end) for i = 1, #contentScripts do contentScripts[i].view:BindEvent() end end --添加事件监听(用于子类重写) function MissionDailyPanel:AddListener() for i = 1, #contentScripts do contentScripts[i].view:AddListener() end end --移除事件监听(用于子类重写) function MissionDailyPanel:RemoveListener() for i = 1, #contentScripts do contentScripts[i].view:RemoveListener() end end --界面打开时调用(用于子类重写) function MissionDailyPanel:OnOpen(popupType,...) --根据传入类型打开对应面板 index = popupType if not index then index = 1 if RedPointManager.GetRedPointMissionDaily() then index = 1 elseif TaskManager.GetAchievementState() then index = 2 end end --for i,v in pairs(contentScripts) do -- if popupType==v.type then -- index=i -- break -- end --end for i=1,#contentPrefabs do contentPrefabs[i].gameObject:SetActive(false) end contentPrefabs[index].gameObject:SetActive(true) contentScripts[index].view:OnShow(this,...)--1、传入自己 2、传入不定参 end --界面打开或者重新打开后,界面刷新时调用(用于子类重写) function MissionDailyPanel:OnShow() this.TabCtrl:SetTabAdapter(this.TabAdapter) this.TabCtrl:SetChangeTabCallBack(this.SwitchView) this.TabCtrl:Init(this.tabBox, _TabData, index) redPointList = {} for i = 1, Util.GetGameObject(this.tabBox,"box").transform.childCount do redPointList[i] =Util.GetGameObject(Util.GetGameObject(this.tabBox,"box").transform:GetChild(i-1).gameObject,"Redpot") redPointList[i]:SetActive(false) end if redPointList[1] and redPointList[2] then BindRedPointObject(RedPointType.DailyTask, redPointList[1]) BindRedPointObject(RedPointType.Achievement_Main, redPointList[2]) end end function MissionDailyPanel:OnSortingOrderChange() for i = 1, #contentScripts do contentScripts[i].view:OnSortingOrderChange(self.sortingOrder) end end -- tab节点显示自定义 function this.TabAdapter(tab, index, status) local tabLab = Util.GetGameObject(tab, "Text") Util.GetGameObject(tab,"Image"):GetComponent("Image").sprite = Util.LoadSprite(_TabData[index][status]) tabLab:GetComponent("Text").text = _TabData[index].name tabLab:GetComponent("Text").color = _TabFontColor[status] end --切换视图 function this.SwitchView(_index) --先执行上一面板关闭逻辑 local oldSelect oldSelect, index = index, _index for i = 1, #contentScripts do if oldSelect~=0 then contentScripts[oldSelect].view:OnClose() break end end --切换预设显隐 for i = 1, #contentPrefabs do contentPrefabs[i].gameObject:SetActive(i == index)--切换子模块预设显隐 end --执行子模块初始化 contentScripts[index].view:OnShow(this) if index == 1 then this.titleText.text = Language[11358] else this.titleText.text = Language[11360] end end --界面关闭时调用(用于子类重写) function MissionDailyPanel:OnClose() for i = 1, #contentScripts do contentScripts[i].view:OnClose() end ClearRedPointObject(RedPointType.DailyTask) ClearRedPointObject(RedPointType.Achievement_Main) end --界面销毁时调用(用于子类重写) function MissionDailyPanel:OnDestroy() for i = 1, #contentScripts do contentScripts[i].view:OnDestroy() end end return MissionDailyPanel