sk-client/Assets/ManagedResources/~Lua/Modules/SelfRecruit/SelfRecruitMainPanel.lua

270 lines
9.3 KiB
Lua

require("Base/BasePanel")
local SelfRecruitMainPanel = Inherit(BasePanel)
local this = SelfRecruitMainPanel
local TabBox = require("Modules/Common/TabBox")-- Tab管理器
local GlobalActConfig = ConfigManager.GetConfig(ConfigName.GlobalActivity)
local AcitvityShowTheme = ConfigManager.GetAllConfigsData(ConfigName.AcitvityShowTheme)
local curPageIndex = 1
local orginLayer
local tabs = {}
local curActivityCount = {
[1] = require("Modules/SelfRecruit/SelfRecruit"), --自选招募
--[2] = require("Modules/SelfRecruit/SelfRecruitOEM"), --招募礼包
-- [3] = require("Modules/SelfRecruit/SelfRecruitRecharge"), --真充回馈
}
--初始化tab信息
function SelfRecruitMainPanel:InitTabs()
tabs = {}
--限时招募
table.insert(tabs, {
Id = 51000,
default = GetPictureFont("X1_bt_zixuanzhaomu_02"),
lock = "X1_tongyong_suo",
select = GetPictureFont("X1_bt_zixuanzhaomu_01"),
rpType = RedPointType.SelfRecruitPage,
panelType = PanelType.Main,
ActType = ActivityTypeDef.SelfRecruit,
tabIndex = 1,
})
--招募礼包
--[[
table.insert(tabs, {
Id = 51001,
default = GetPictureFont("X1_bt_zhaomulibao_02"),
lock = "X1_tongyong_suo",
select = GetPictureFont("X1_bt_zhaomulibao_01"),
rpType = "",
panelType = PanelType.Main,
ActType = ActivityTypeDef.SelfRecruitOEM,
tabIndex = 2,
})
]]
-- --真充回馈
-- table.insert(tabs, {
-- Id = 51002,
-- default = GetPictureFont("X1_zhenchonghuikui_02"),
-- lock = "X1_tongyong_suo",
-- select = GetPictureFont("X1_zhenchonghuikui_01"),
-- rpType = RedPointType.SelfRecruitRecharge,
-- panelType = PanelType.Main,
-- ActType = ActivityTypeDef.SelfRecruitRecharge,
-- tabIndex = 3,
-- })
end
--初始化组件(用于子类重写)
function SelfRecruitMainPanel:InitComponent()
orginLayer = 0
this.tabbox = Util.GetGameObject(this.gameObject, "bg/tabbox")
this.btnBack = Util.GetGameObject(this.gameObject, "bg/btnBack")
this.content = Util.GetGameObject(this.gameObject, "bg/pageContent")
this.tabList = Util.GetGameObject(this.gameObject,"bg/tabbox")
this.PageList = {}
for i = 1,#curActivityCount do
this.PageList[i] = curActivityCount[i].new(self, Util.GetGameObject(self.transform, "bg/pageContent/page"..i),this.UpView)
end
-- 上部货币显示
this.HeadFrameView = SubUIManager.Open(SubUIConfig.PlayerHeadFrameView, self.transform)
this.UpView = SubUIManager.Open(SubUIConfig.UpView, this.gameObject.transform, { showType = UpViewOpenType.ShowLeft})
-- 初始化Tab管理器
this.PageTabCtrl = TabBox.New()
this.PageTabCtrl:SetTabAdapter(self.PageTabAdapter)
this.PageTabCtrl:SetTabIsLockCheck(self.PageTabIsLockCheck)
this.PageTabCtrl:SetChangeTabCallBack(self.OnPageTabChange)
SelfRecruitMainPanel:InitTabs()
end
--绑定事件(用于子类重写)
function SelfRecruitMainPanel:BindEvent()
-- 关闭界面打开主城
Util.AddClick(this.btnBack, function()
this:ClosePanel()
end)
end
function this.SelfOnshow()
this.PageList[1]:OnShow()
end
--添加事件监听(用于子类重写)
function SelfRecruitMainPanel:AddListener()
-- Game.GlobalEvent:AddEvent(GameEvent.Activity.OnActivityOpenOrClose, this.RefreshActivityBtn)
for i = 1, #this.PageList do
if this.PageList[i] then
this.PageList[i]:AddListener()
end
end
Game.GlobalEvent:AddEvent(GameEvent.SelfRecruit.RefreshSelfRecruit, this.SelfOnshow)
--添加事件监听(用于子类重写)
end
--移除事件监听(用于子类重写)
function SelfRecruitMainPanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.SelfRecruit.RefreshSelfRecruit, this.SelfOnshow)
Game.GlobalEvent:RemoveEvent(GameEvent.Activity.OnActivityOpenOrClose, this.RefreshActivityBtn)
for i = 1, #this.PageList do
if this.PageList[i] then
this.PageList[i]:RemoveListener()
end
end
end
this.RefreshActivityBtn = function()
if not ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.DynamicAct) then
this:ClosePanel()
end
end
--界面打开时调用(用于子类重写)
function SelfRecruitMainPanel:OnOpen(chooseIndex)
-- -- 初始化tab数据
if chooseIndex then
for i = 1, #tabs do
if tabs[i].ActType == chooseIndex then
curPageIndex = i
end
end
else
curPageIndex = chooseIndex or 1
end
-- if chooseIndex then
-- curPageIndex = chooseIndex
-- else
-- curPageIndex = 1
-- end
this.PageTabCtrl:Init(this.tabbox, tabs,curPageIndex)
end
-- 打开,重新打开时回调
function SelfRecruitMainPanel:OnShow()
SoundManager.PlayMusic(SoundConfig.BGM_Main)
CheckRedPointStatus(RedPointType.SelfRecruitRecharge) --自选招募真充回馈
-- local activiytId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.DynamicAct)
-- if not activiytId or activiytId <= 0 then
-- self:ClosePanel()
-- end
this.btnBack:SetActive(true)
this.tabList:SetActive(true)
-- if curPageIndex and curPageIndex == 1 then
-- local id = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.DynamicAct)
-- curPageIndex = GlobalActConfig[id].ShowArt
-- this.PageTabCtrl:ChangeTab(curPageIndex)
-- elseif curPageIndex then
this.PageTabCtrl:ChangeTab(curPageIndex)
--end
end
--界面关闭时调用(用于子类重写)
function SelfRecruitMainPanel:OnClose()
if curPageIndex then
this.PageList[tabs[curPageIndex].tabIndex]:OnHide()
this.PageList[tabs[curPageIndex].tabIndex].gameObject:SetActive(false)
end
end
--界面销毁时调用(用于子类重写)
function SelfRecruitMainPanel:OnDestroy()
SubUIManager.Close(this.HeadFrameView)
SubUIManager.Close(this.UpView)
-- 清除红点
SelfRecruitMainPanel:ClearPageRedpot()
-- 这里管理全部子界面的销毁,保证子界面生命周期完整
for _, page in pairs(this.PageList) do
if page.OnDestroy then
page:OnDestroy()
end
end
end
-- tab按钮自定义显示设置
function SelfRecruitMainPanel.PageTabAdapter(tab, index, status)
local img = Util.GetGameObject(tab, "icon"):GetComponent("Image")
local lock = Util.GetGameObject(tab, "lock")
local redpot = Util.GetGameObject(tab, "redPoint")
local selected = Util.GetGameObject(tab, "selected")
img.sprite = Util.LoadSprite(tabs[index].default)
Util.GetGameObject(selected, "icon"):GetComponent("Image").sprite = Util.LoadSprite(tabs[index].select)
selected:SetActive(status == "select")
local islock = status == "lock"
Util.SetGray(img.gameObject, islock)
lock:SetActive(islock)
-- 判断是否需要检测红点
redpot:SetActive(false)
if not islock then
SelfRecruitMainPanel:ClearPageRedpot(index)
SelfRecruitMainPanel:BindPageRedpot(index, redpot)
end
local id = ActivityGiftManager.IsActivityTypeOpen(tabs[index].ActType)
-- Log("id 00 "..id)
if id and id > 0 then --and ActivityGiftManager.IsQualifiled(tabs[index].ActType)
--限时招募
if GlobalActConfig[id].Type == ActivityTypeDef.SelfRecruit then
tab:SetActive(true)
--招募礼包
elseif GlobalActConfig[id].Type == ActivityTypeDef.SelfRecruitOEM then
tab:SetActive(true)
--真充回馈
elseif GlobalActConfig[id].Type == ActivityTypeDef.SelfRecruitRecharge then
tab:SetActive(true)
end
else
tab:SetActive(false)
end
end
-- tab可用性检测
function SelfRecruitMainPanel.PageTabIsLockCheck(index)
return false
end
-- tab改变事件
function SelfRecruitMainPanel.OnPageTabChange(index)
-- if tabs[index].ActType == ActivityTypeDef.Celebration then
-- if PlayerManager.familyId == 0 then
-- UIManager.OpenPanel(UIName.GeneralPopup, GENERAL_POPUP_TYPE.SheJiCheckGuild)
-- return
-- end
-- end
curPageIndex = index
for i = 1, #this.PageList do
if this.PageList[i] then
this.PageList[i]:OnHide()
this.PageList[i].gameObject:SetActive(false)
end
end
this.PageList[tabs[index].tabIndex].gameObject:SetActive(true)
this.PageList[tabs[index].tabIndex]:OnShow(this.sortingOrder, this, tabs[index].ActType)
this.HeadFrameView:OnShow()
this.UpView:OnOpen({ showType = UpViewOpenType.ShowRight, panelType = tabs[index].panelType })
end
-- 绑定数据
local _PageBindData = {}
local _TabBindData = {}
function SelfRecruitMainPanel:BindPageRedpot(page, redpot)
local rpType = tabs[page].rpType
if not rpType then return end
BindRedPointObject(rpType, redpot)
_PageBindData[rpType] = redpot
end
function SelfRecruitMainPanel:ClearPageRedpot(page)
-- 清除红点绑定
if page then -- 清除某个
local rpType = tabs[page].rpType
if not rpType then return end
ClearRedPointObject(rpType, _PageBindData[rpType])
_PageBindData[rpType] = nil
else -- 全部清除
for rpt, redpot in pairs(_PageBindData) do
ClearRedPointObject(rpt, redpot)
end
_PageBindData = {}
end
end
return SelfRecruitMainPanel