require("Base/BasePanel") local SettingPanel = Inherit(BasePanel) local this = SettingPanel local funIndex = 1 --Tab local TabBox = require("Modules/Common/TabBox") local _TabData={ [1] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = "信息" , rpType = RedPointType.Setting_Head}, -- [2] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = "称号" }, [2] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = "坐骑" , rpType = RedPointType.Setting_Ride}, -- [4] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = "时装" }, } local _TabFontColor = { default = Color.New(130 / 255, 128 / 255, 120 / 255, 1), select = Color.New(243 / 255, 235 / 255, 202 / 255, 1)} --子模块脚本 this.contents = { --信息 [1] = {view = require("Modules/Setting/SettingInfo"), panelName = "settingInfo"}, --称号 -- [2] = {view = require("Modules/Setting/SettingPlayerTitle"), panelName = "settingPlayerTitle"}, --时装 [2] = {view = require("Modules/Setting/SettingPlayerRide"), panelName = "settingPlayerRide"}, --坐骑 -- [4] = {view = require("Modules/Setting/SettingPlayerSkin"), panelName = "settingPlayerSkin"}, } --子模块预设 this.prefabs={} --初始化组件(用于子类重写) function SettingPanel:InitComponent() this.btnBack = Util.GetGameObject(this.transform, "btnBack") this.UpView = SubUIManager.Open(SubUIConfig.UpView, self.gameObject.transform, { showType = UpViewOpenType.ShowLeft }) this.settingPlayerBg = Util.GetGameObject(self.transform, "layout/settingPlayerBgImage") this.settingPlayerBg:SetActive(true) --预设赋值 this.layout = Util.GetGameObject(self.transform, "layout") for i=1,#this.contents do this.prefabs[i]=Util.GetGameObject(this.layout,this.contents[i].panelName) end for i = 1, #this.contents do this.contents[i].view:InitComponent(Util.GetGameObject(this.transform, "layout/"..this.contents[i].panelName),self) end this.tabBox = Util.GetGameObject(this.transform, "TabBox") end --绑定事件(用于子类重写) function SettingPanel:BindEvent() Util.AddClick(this.btnBack, function() PlaySoundWithoutClick(SoundConfig.Sound_UICancel) self:ClosePanel() end) for i = 1, #this.contents do this.contents[i].view:BindEvent() end end --添加事件监听(用于子类重写) function SettingPanel:AddListener() for i = 1, #this.contents do this.contents[i].view:AddListener() end end --移除事件监听(用于子类重写) function SettingPanel:RemoveListener() for i = 1, #this.contents do this.contents[i].view:RemoveListener() end end --界面打开时调用(用于子类重写) function SettingPanel:OnOpen(index) funIndex = index or 1 this.TabCtrl = TabBox.New() this.TabCtrl:SetTabAdapter(this.TabAdapter) this.TabCtrl:SetChangeTabCallBack(this.SwitchView) this.TabCtrl:Init(this.tabBox, _TabData,funIndex) -- 绑定红点 local tabList = this.TabCtrl:GetTabList() for index = 1, #tabList do local tab = tabList[index] local redpot = Util.GetGameObject(tab, "Redpot") if _TabData[index].rpType then BindRedPointObject(_TabData[index].rpType, redpot) else redpot:SetActive(false) end end end --界面打开或者重新打开后,界面刷新时调用(用于子类重写) -- function SettingPanel:OnShow() -- 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 = GetCurLanguage() ~= 2 and _TabData[index].name or "".._TabData[index].name.."" tabLab:GetComponent("Text").color = _TabFontColor[status] end --切换视图 function this.SwitchView(index,isNotTop,isNotAni) --先执行上一面板关闭逻辑 local oldSelect oldSelect, funIndex = funIndex, index for i = 1, #this.contents do if oldSelect~=0 then this.contents[oldSelect].view:OnClose() break end end --切换预设显隐 for i = 1, #this.prefabs do this.prefabs[i].gameObject:SetActive(i == index)--切换子模块预设显隐 end --区分显示 this.UpView:OnOpen({ showType = UpViewOpenType.ShowLeft, panelType = PanelType.Main }) this.settingPlayerBg.gameObject:SetActive(index == 2 or index == 3 or index == 4) if index==1 then elseif index==2 then elseif index==3 then elseif index==4 then end --执行子模块初始化 this.contents[index].view:OnShow(this.sortingOrder,this.itemListRoot,isNotTop,isNotAni) end --界面关闭时调用(用于子类重写) function SettingPanel:OnClose() for i = 1, #this.contents do this.contents[i].view:OnClose() end end --界面销毁时调用(用于子类重写) function SettingPanel:OnDestroy() SubUIManager.Close(this.UpView) for i = 1, #this.contents do this.contents[i].view:OnDestroy() end -- 清除红点绑定 for _, v in ipairs(_TabData) do if v.rpType then ClearRedPointObject(v.rpType) end end end return SettingPanel