miduo_client/Assets/ManagedResources/~Lua/Modules/DynamicActivity/ActivityMainPanel.lua

408 lines
15 KiB
Lua

require("Base/BasePanel")
local ActivityMainPanel = Inherit(BasePanel)
local this = ActivityMainPanel
-- Tab管理器
local TabBox = require("Modules/Common/TabBox")
local GlobalActConfig = ConfigManager.GetConfig(ConfigName.GlobalActivity)
local _CurPageIndex = 0
local orginLayer
local redPointTypeList = {}
local tabs = {}
local subViewList = {}
--初始化组件(用于子类重写)
function ActivityMainPanel:InitComponent()
this.spLoader = SpriteLoader.New()
orginLayer = 0
this.mask = Util.GetGameObject(self.gameObject,"mask")
this.mask:SetActive(false)
this.tabbox = Util.GetGameObject(self.gameObject, "bg/tabbox")
this.btnBack = Util.GetGameObject(self.gameObject, "bg/btnBack")
this.content = Util.GetGameObject(self.gameObject, "bg/pageContent")
this.upView = SubUIManager.Open(SubUIConfig.UpView,self.gameObject.transform)
end
--绑定事件(用于子类重写)
function ActivityMainPanel:BindEvent()
-- 初始化Tab管理器
this.PageTabCtrl = TabBox.New()
this.PageTabCtrl:SetTabAdapter(this.PageTabAdapter)
this.PageTabCtrl:SetTabIsLockCheck(this.PageTabIsLockCheck)
this.PageTabCtrl:SetChangeTabCallBack(this.OnPageTabChange)
-- 关闭界面打开主城
Util.AddClick(this.btnBack, function()
DynamicActivityManager.NiuQiIndex = 1
ShopManager.SetSelectIndex(0,{})
DynamicActivityManager.RemoveUIList()
if #DynamicActivityManager.OpenUIList > 0 then
-- LogRed("jump ")
JumpManager.GoJump(DynamicActivityManager.OpenUIList[#DynamicActivityManager.OpenUIList],function()
DynamicActivityManager.RemoveUIList()
end)
else
-- LogRed("close ")
this:ClosePanel()
end
end)
end
--添加事件监听(用于子类重写)
function ActivityMainPanel:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Activity.OnActivityOpenOrClose, this.onActivityOpenOrClose)
end
--移除事件监听(用于子类重写)
function ActivityMainPanel:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Activity.OnActivityOpenOrClose, this.onActivityOpenOrClose)
end
--
function ActivityMainPanel.onActivityOpenOrClose()
this:OnOpen(this.activityType,_CurPageIndex,true)
end
function ActivityMainPanel:CheckActOpen(_index)
for i = 1, #tabs do
if tabs[i].Sort == _index then
_index = i
end
end
if tabs[_index].IsRecharge == 1 and (not RECHARGEABLE) then
return
end
if tabs[_index].IfBack == 1 then
if tabs[_index].ActiveType > 0 then
local id = ActivityGiftManager.IsActivityTypeOpen(tabs[_index].ActiveType)
if id and id > 0 and ActivityGiftManager.IsQualifiled(tabs[_index].ActiveType) then
if GlobalActConfig[id].ShowArt and GlobalActConfig[id].ShowArt > 0 then
if tabs[_index].ActiveType == ActivityTypeDef.DynamicAct or tabs[_index].ActiveType == ActivityTypeDef.LimitUpHero or tabs[_index].ActiveType == ActivityTypeDef.DynamicActShop or tabs[_index].ActiveType == ActivityTypeDef.NiuQi then
_CurPageIndex = _index
elseif GlobalActConfig[id].ShowArt == this.activityType then
_CurPageIndex = _index
end
else
_CurPageIndex = _index
end
end
elseif tabs[_index].FunType > 0 then
if ActTimeCtrlManager.SingleFuncState(tabs[_index].FunType) then
_CurPageIndex = _index
end
else
_CurPageIndex = _index
end
else
if tabs[_index].ActiveType > 0 then
local id = ActivityGiftManager.IsActivityTypeOpen(tabs[_index].ActiveType)
if id and id > 0 and ActivityGiftManager.IsQualifiled(tabs[_index].ActiveType) then
_CurPageIndex = _index
end
elseif tabs[_index].FunType > 0 then
if ActTimeCtrlManager.SingleFuncState(tabs[_index].FunType) then
_CurPageIndex = _index
end
elseif tabs[_index].ShopData and tabs[_index].ShopData[1][1] == -9999 then
local id = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.DynamicAct)
if id and id > 0 and ActivityGiftManager.IsQualifiled(ActivityTypeDef.DynamicAct) and GlobalActConfig[id].ShowArt == tabs[_index].ActId then
_CurPageIndex = _index
end
else
_CurPageIndex = _index
end
end
end
--界面打开时调用(用于子类重写)
function ActivityMainPanel:OnOpen(_activityType,_index,change)
SoundManager.PlaySound(SoundConfig.UI_Hddakai)
this.activityType = _activityType
DynamicActivityManager.curActivityType = this.activityType
tabs = DynamicActivityManager.GetActivityTableDataByPageInde(this.activityType)
_CurPageIndex = 0
if change then
_index = tabs[_index].Sort
end
if _index and _index > 0 then
self:CheckActOpen(_index)
end
for index = 1, #tabs do
if _CurPageIndex < 1 then
self:CheckActOpen(tabs[index].Sort)
else
break
end
end
if _CurPageIndex < 1 then
DynamicActivityManager.RemoveUIList()
if #DynamicActivityManager.OpenUIList > 0 then
JumpManager.GoJump(DynamicActivityManager.OpenUIList[#DynamicActivityManager.OpenUIList],function()
DynamicActivityManager.RemoveUIList()
end)
else
this:ClosePanel()
end
end
end
-- 限时引导小手
function ActivityMainPanel:ShowGuideGo(guideType)
--
if subViewList[_CurPageIndex] and subViewList[_CurPageIndex].sub and subViewList[_CurPageIndex].sub.ShowGuideGo then
subViewList[_CurPageIndex].sub:ShowGuideGo(guideType)
end
end
-- 打开,重新打开时回调
function ActivityMainPanel:OnShow()
SoundManager.PlayMusic(SoundConfig.BGM_Main)
orginLayer = self.sortingOrder
Log("_CurPageIndex OnShow:".._CurPageIndex)
if _CurPageIndex and (_CurPageIndex > #tabs or _CurPageIndex < 1) then
_CurPageIndex = #tabs
end
this.PageTabCtrl:Init(this.tabbox.gameObject, tabs,_CurPageIndex)
end
function this:OnSortingOrderChange()
orginLayer = self.sortingOrder
for k,v in pairs(subViewList) do
v.sub:OnSortingOrderChange(self.sortingOrder)
end
end
function ActivityMainPanel:OnFocus()
for k,v in pairs(subViewList) do
if v.sub.OnFocus then
v.sub:OnFocus()
end
end
end
----==========================一级页签相关===========================================
-- tab按钮自定义显示设置
function this.PageTabAdapter(tab, index, status)
tab.gameObject.name = "tab"..tabs[index].Id
local img = Util.GetGameObject(tab, "img"):GetComponent("Image")
local lock = Util.GetGameObject(tab, "lock")
local redpot = Util.GetGameObject(tab, "redpot")
local text=Util.GetGameObject(tab,"text"):GetComponent("Text")
local select=Util.GetGameObject(tab,"select")
if status == "lock" then
lock.gameObject:SetActive(true)
Util.SetGray(tab.gameObject, true)
else
Util.SetGray(tab.gameObject, false)
lock.gameObject:SetActive(false)
end
--设置红点
redpot.gameObject:SetActive(false)
if status ~= "lock" then
if redPointTypeList[tabs[index].RpType] then
ClearRedPointObject(tabs[index].RpType,redPointTypeList[tabs[index].RpType])
redPointTypeList[tabs[index].RpType] = nil
end
if not tabs[index].RpType or tabs[index].RpType < 1 then
redpot.gameObject:SetActive(false)
else
BindRedPointObject(tabs[index].RpType,redpot)
redPointTypeList[tabs[index].RpType] = redpot
end
end
--设置图片
local sprite = nil
if tabs[index].ActiveType > 0 then
local id = ActivityGiftManager.IsActivityTypeOpen(tabs[index].ActiveType)
if id and id > 0 then
local actConfig
local actConfig = ConfigManager.TryGetConfigDataByThreeKey(ConfigName.ActivityGroups,"ActId",GlobalActConfig[id].ShowArt,"PageType",this.activityType,"ActiveType",tabs[index].ActiveType)
if not actConfig then
actConfig = ConfigManager.TryGetConfigDataByThreeKey(ConfigName.ActivityGroups,"ActId",id,"PageType",this.activityType,"ActiveType",tabs[index].ActiveType)
end
if actConfig then
sprite = actConfig.Icon[1]--(status == "select" and actConfig.Icon[2] or actConfig.Icon[1])
text.text=actConfig.Sesc
end
end
end
-- if not sprite then
-- sprite = (status == "select" and tabs[index].Icon[2] or tabs[index].Icon[1])
-- end
if sprite==nil or sprite=="" then
local num=1
if index %5==0 then
num=1
else
num=index%5
end
sprite="UI_hz_gonghui_3"..num
end
img.sprite = this.spLoader:LoadSprite(sprite)
-- img:SetNativeSize()
select:SetActive(status == "select")
text.text=tabs[index].Sesc
--设置显示隐藏
if not DynamicActivityManager.IsQualifiled(tabs[index].Id) then
tab.gameObject:SetActive(false)
return
end
if tabs[index].IsRecharge == 1 and not RECHARGEABLE then
tab.gameObject:SetActive(false)
return
end
local isshow = false
if tabs[index].IfBack == 1 then
if tabs[index].ActiveType > 0 then
local id = ActivityGiftManager.IsActivityTypeOpen(tabs[index].ActiveType)
if id and id > 0 and ActivityGiftManager.IsQualifiled(tabs[index].ActiveType) then
if GlobalActConfig[id].ShowArt and GlobalActConfig[id].ShowArt > 0 then
if tabs[index].ActiveType == ActivityTypeDef.DynamicAct or tabs[index].ActiveType == ActivityTypeDef.LimitUpHero or tabs[index].ActiveType == ActivityTypeDef.DynamicActShop or tabs[index].ActiveType == ActivityTypeDef.NiuQi then
isshow = true
elseif GlobalActConfig[id].ShowArt == this.activityType then
isshow = true
end
else
isshow = true
end
end
elseif tabs[index].FunType > 0 then
isshow = ActTimeCtrlManager.SingleFuncState(tabs[index].FunType)
else
isshow = true
end
else
if tabs[index].ActiveType == ActivityTypeDef.FuXingGaoZhao then--福星高照特殊处理
local ActData = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.FuXingGaoZhao)
if ActData then
isshow = ActData.value ~= 2
if ActData.value == 0 then
local data = string.split(ConfigManager.GetConfigDataByKey(ConfigName.SpecialConfig,"Id",109).Value,"#")
local time = ActData.startTime + tonumber(data[1])*86400 - GetTimeStamp()
if time <= 0 then
isshow = false
end
end
else
isshow = false
end
elseif tabs[index].ActiveType > 0 then
isshow = ActivityGiftManager.IsQualifiled(tabs[index].ActiveType)
elseif tabs[index].FunType > 0 then
isshow = ActTimeCtrlManager.IsQualifiled(tabs[index].FunType)
elseif tabs[index].ShopData and tabs[index].ShopData[1][1] == -9999 then
local id = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.DynamicAct)
if id and id > 0 and ActivityGiftManager.IsQualifiled(ActivityTypeDef.DynamicAct) and GlobalActConfig[id].ShowArt == tabs[index].ActId then
isshow = true
else
isshow = false
end
else
isshow = true
end
end
tab.gameObject:SetActive(isshow)
end
-- tab 加锁 页签是否需要加锁显示
function this.PageTabIsLockCheck(index)
-- --充值 每日礼包页签 需要加锁显示
-- if tabs[index].ActiveType and tabs[index].ActiveType == 10004 then
-- if not OperatingManager.HasGoodsByShowType(14) then
-- return true
-- end
-- end
-- return false
end
-- tab改变事件
function this.OnPageTabChange(index)
-- if index == _CurPageIndex then
-- return
-- end
if subViewList[_CurPageIndex] and subViewList[_CurPageIndex].config and subViewList[_CurPageIndex].sub then
subViewList[_CurPageIndex].sub:OnClose()
end
if subViewList[index] and subViewList[index].config and subViewList[index].sub then
--每日每周任务页签拆分用u
if tabs[index].ShopData and tabs[index].ShopData[1][1] == -9999 then
CommonActPageManager.DynamicActType = tabs[index].Sort - 1
end
subViewList[index].sub:OnShow(orginLayer)
else
subViewList[index] = {}
if tabs[index].UIName then
subViewList[index].config = SubUIConfig[tabs[index].UIName[1]]
subViewList[index].sub = SubUIManager.Open(subViewList[index].config,this.content.transform,tabs[index],index,this)
--每日每周任务页签拆分用
if tabs[index].ShopData and tabs[index].ShopData[1][1] == -9999 then
CommonActPageManager.DynamicActType = tabs[index].Sort - 1
end
subViewList[index].sub:OnShow(orginLayer)
end
end
this.SetUpView(tabs[index])
DynamicActivityManager.ChangeUIList(tabs[index].Jump)
_CurPageIndex = index
end
function this.SetUpView(_data)
local data = _data
if _data.ActiveType == ActivityTypeDef.DynamicActShop then
local actId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.DynamicActShop)
if actId then
data = ConfigManager.GetConfigDataByDoubleKey(ConfigName.ActivityGroups,"ActId",actId,"ActiveType",ActivityTypeDef.DynamicActShop)
end
end
if data.UpView and #data.UpView > 0 then
this.upView:OnOpen({showType = data.UpView[1][1], panelType = data.UpView[2] })
this.upView.gameObject:SetActive(true)
else
this.upView.gameObject:SetActive(false)
end
end
--界面关闭时调用(用于子类重写)
function ActivityMainPanel:OnClose()
CommonActPageManager.DynamicActType = 0
if UIManager.IsOpen(UIName.RewardItemSingleShowPopup) then
UIManager.ClosePanel(UIName.RewardItemSingleShowPopup)
end
if UIManager.IsOpen(UIName.HelpPopup) then
UIManager.ClosePanel(UIName.HelpPopup)
end
--清除红点
for k,v in pairs(redPointTypeList) do
ClearRedPointObject(k,v)
end
redPointTypeList = {}
--关闭弹窗界面
for k,v in pairs(subViewList) do
v.sub:OnDestroy()
SubUIManager.Close(v.sub)
end
subViewList = {}
DynamicActivityManager.curActivityType = 0
end
--界面销毁时调用(用于子类重写)
function ActivityMainPanel:OnDestroy()
--清除红点
for k,v in pairs(redPointTypeList) do
ClearRedPointObject(k,v)
end
redPointTypeList = {}
--关闭弹窗界面
for k,v in pairs(subViewList) do
--UIManager.ClosePanel(k)
v.sub:OnDestroy()
this.spLoader:Destroy()
SubUIManager.Close(v.sub)
end
subViewList = {}
DynamicActivityManager.curActivityType = 0
tabs = {}
SubUIManager.Close(this.upView)
this.upView = nil
_CurPageIndex = 0
end
return this