318 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			Lua
		
	
			
		
		
	
	
			318 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			Lua
		
	
require("Base/BasePanel")
 | 
						|
local EightDayGiftPanel = Inherit(BasePanel)
 | 
						|
local this = EightDayGiftPanel
 | 
						|
 | 
						|
local orginLayer = 0
 | 
						|
local ActRewardConfig = ConfigManager.GetConfig(ConfigName.ActivityRewardConfig)--总表数据
 | 
						|
local HeroConfig = ConfigManager.GetConfig(ConfigName.HeroConfig)
 | 
						|
local ArtConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig)
 | 
						|
local EightDayRewardConfig = ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityRewardConfig,"ActivityId",ActivityTypeDef.EightDayGift)--表内八日奖励数据
 | 
						|
local ItemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)
 | 
						|
local ItemList = {}--奖励List
 | 
						|
local ItemViewList = {}
 | 
						|
local rewardData--后端数据
 | 
						|
local curDay--当前天数
 | 
						|
local Live
 | 
						|
local bgName
 | 
						|
 | 
						|
 | 
						|
local day_picture ={--数字名、文字名、奖励id
 | 
						|
 | 
						|
    [1] = {"b_baridenglu_slogan002",2043,"b_baridenglu_slogan02",10043,{0.5,0.5,0.5},{0,-470.2,0}},
 | 
						|
    [2] = {"b_baridenglu_slogan002",2043,"b_baridenglu_slogan02",10043,{0.5,0.5,0.5},{0,-470.2,0}},
 | 
						|
    [3] = {"b_baridenglu_slogan003",2503,"b_baridenglu_slogan03",10022,{1,1,1},{-69,91,0}},
 | 
						|
    [4] = {"b_baridenglu_slogan008",2022,"b_baridenglu_slogan08",10022,{0.6,0.6,0.6},{0,-470.2,0}},
 | 
						|
    [5] = {"b_baridenglu_slogan008",2022,"b_baridenglu_slogan08",10022,{0.6,0.6,0.6},{0,-470.2,0}},
 | 
						|
    [6] = {"b_baridenglu_slogan008",2022,"b_baridenglu_slogan08",10022,{0.6,0.6,0.6},{0,-470.2,0}},
 | 
						|
    [7] = {"b_baridenglu_slogan008",2022,"b_baridenglu_slogan08",10022,{0.6,0.6,0.6},{0,-470.2,0}},
 | 
						|
    [8] = {"b_baridenglu_slogan008",2022,"b_baridenglu_slogan08",10022,{0.6,0.6,0.6},{0,-470.2,0}},
 | 
						|
}
 | 
						|
 | 
						|
--初始化组件(用于子类重写)
 | 
						|
function EightDayGiftPanel:InitComponent()
 | 
						|
    this.btnClose = Util.GetGameObject(this.gameObject,"panel/bg/btnBack")
 | 
						|
    this.btnPreview = Util.GetGameObject(this.gameObject,"panel/bg/btnPreview")
 | 
						|
    this.show = Util.GetGameObject(this.gameObject,"panel/show")--根节点
 | 
						|
    this.itemPre = Util.GetGameObject(this.gameObject,"panel/show/itemPre")--预设
 | 
						|
    this.effect = Util.GetGameObject(this.gameObject,"panel/effect")
 | 
						|
    this.badeffect = Util.GetGameObject(this.effect,"Partical/uv_zi")
 | 
						|
    this.badeffect:SetActive(false)
 | 
						|
end
 | 
						|
 | 
						|
 | 
						|
--绑定事件(用于子类重写)
 | 
						|
function EightDayGiftPanel:BindEvent()
 | 
						|
    Util.AddClick(this.btnClose,function()
 | 
						|
        this:ClosePanel()
 | 
						|
    end)
 | 
						|
 | 
						|
end
 | 
						|
 | 
						|
--添加事件监听(用于子类重写)
 | 
						|
function EightDayGiftPanel:AddListener()
 | 
						|
    -- Game.GlobalEvent:AddEvent(GameEvent.FiveAMRefresh.ServerNotifyRefresh, this.Refresh)
 | 
						|
 | 
						|
end
 | 
						|
 | 
						|
--移除事件监听(用于子类重写)
 | 
						|
function EightDayGiftPanel:RemoveListener()
 | 
						|
    -- Game.GlobalEvent:RemoveEvent(GameEvent.FiveAMRefresh.ServerNotifyRefresh, this.Refresh)
 | 
						|
end
 | 
						|
 | 
						|
function EightDayGiftPanel:Refresh()
 | 
						|
    rewardData = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.EightDayGift)
 | 
						|
    curDay = math.ceil((CalculateSecondsNowTo_N_OClock(5) + GetTimeStamp() - PlayerManager.userCreateTime)/86400)
 | 
						|
    -- LogYellow((CalculateSecondsNowTo_N_OClock(5) + GetTimeStamp() - PlayerManager.userCreateTime)/86400)
 | 
						|
    -- LogGreen((CalculateSecondsNowTo_N_OClock(24) + GetTimeStamp() - PlayerManager.userCreateTime)/86400)
 | 
						|
 | 
						|
    if curDay>8 then
 | 
						|
        curDay = 8
 | 
						|
    end
 | 
						|
    this.SetAllReward()
 | 
						|
    this:SetBg()
 | 
						|
end
 | 
						|
 | 
						|
--设置背景
 | 
						|
function EightDayGiftPanel:SetBg(i)
 | 
						|
    -- body
 | 
						|
    local ren = Util.GetGameObject(this.gameObject,"panel/bg/ren")
 | 
						|
    local tip = Util.GetGameObject(this.gameObject,"panel/bg/tip"):GetComponent("Image")
 | 
						|
 | 
						|
    local num,text,id
 | 
						|
    local bgScale = Vector3
 | 
						|
    local bgPos = Vector3
 | 
						|
 | 
						|
 | 
						|
    -- --加载天数、奖励文字、动效(第三天特殊处理)
 | 
						|
        ren:GetComponent("Image").enabled= false
 | 
						|
        ren.transform.localPosition = Vector3.New(0,310,0)
 | 
						|
        if i then
 | 
						|
            if i == 3  then
 | 
						|
                ren.transform.localPosition = Vector3.New(-74,100,0)
 | 
						|
                text = "b_baridenglu_slogan03"--文字
 | 
						|
                id = day_picture[i][4]--itemviewId
 | 
						|
                bgName = "b_baridenglu_erridi"--动效资源名字
 | 
						|
                tip.sprite = Util.LoadSprite(text)
 | 
						|
                ren:GetComponent("Image").sprite = Util.LoadSprite(bgName)
 | 
						|
                ren:GetComponent("Image").enabled= true
 | 
						|
                this.btnPreview:SetActive(false)
 | 
						|
            else
 | 
						|
                this.btnPreview:SetActive(true)
 | 
						|
                text = tostring(day_picture[i][3])--文字
 | 
						|
                id = day_picture[i][4]--itemviewId
 | 
						|
                bgName = ArtConfig[day_picture[i][2]].Name--动效资源名字
 | 
						|
                bgScale = day_picture[i][5]
 | 
						|
                bgPos = day_picture[i][6]
 | 
						|
                tip.sprite = Util.LoadSprite(text)
 | 
						|
                Util.AddOnceClick(this.btnPreview,function()
 | 
						|
                    UIManager.OpenPanel(UIName.RoleGetInfoPopup, false, id, 10)
 | 
						|
                end)
 | 
						|
                Live = poolManager:LoadLive(bgName, ren.transform, Vector3.New(bgScale[1],bgScale[2],bgScale[3]), Vector3.New(bgPos[1],bgPos[2],bgPos[3]))
 | 
						|
            end
 | 
						|
 | 
						|
        else
 | 
						|
            if curDay == 3 or curDay ==2 and rewardData.mission[2].state == 1 then
 | 
						|
                this.btnPreview:SetActive(false)
 | 
						|
                ren.transform.localPosition = Vector3.New(-74,100,0)
 | 
						|
                text = "b_baridenglu_slogan03"--文字
 | 
						|
                id = day_picture[3][4]--itemviewId
 | 
						|
                bgName = "b_baridenglu_erridi"--动效资源名字
 | 
						|
                tip.sprite = Util.LoadSprite(text)
 | 
						|
                ren:GetComponent("Image").sprite = Util.LoadSprite(bgName)
 | 
						|
                ren:GetComponent("Image").enabled= true
 | 
						|
            else
 | 
						|
                this.btnPreview:SetActive(true)
 | 
						|
                if rewardData.mission[curDay].state == 1 and curDay ~= 8 then
 | 
						|
                    text = tostring(day_picture[curDay+1][3])
 | 
						|
                    id = day_picture[curDay+1][4]
 | 
						|
                    bgName = ArtConfig[day_picture[curDay+1][2]].Name
 | 
						|
                    bgScale = day_picture[curDay+1][5]
 | 
						|
                    bgPos = day_picture[curDay+1][6]
 | 
						|
                    tip.sprite = Util.LoadSprite(text)
 | 
						|
                    Util.AddOnceClick(this.btnPreview,function()
 | 
						|
                        UIManager.OpenPanel(UIName.RoleGetInfoPopup, false, id, 10)
 | 
						|
                    end)
 | 
						|
                    Live = poolManager:LoadLive(bgName, ren.transform, Vector3.New(bgScale[1],bgScale[2],bgScale[3]), Vector3.New(bgPos[1],bgPos[2],bgPos[3]))
 | 
						|
                else
 | 
						|
                    text = tostring(day_picture[curDay][3])
 | 
						|
                    id = day_picture[curDay][4]
 | 
						|
                    bgName = ArtConfig[day_picture[curDay][2]].Name
 | 
						|
                    bgScale = day_picture[curDay][5]
 | 
						|
                    bgPos = day_picture[curDay][6]
 | 
						|
                    tip.sprite = Util.LoadSprite(text)
 | 
						|
                    Util.AddOnceClick(this.btnPreview,function()
 | 
						|
                        UIManager.OpenPanel(UIName.RoleGetInfoPopup, false, id, 10)
 | 
						|
                    end)
 | 
						|
                    Live = poolManager:LoadLive(bgName, ren.transform, Vector3.New(bgScale[1],bgScale[2],bgScale[3]), Vector3.New(bgPos[1],bgPos[2],bgPos[3]))
 | 
						|
                end
 | 
						|
            end
 | 
						|
        end
 | 
						|
end
 | 
						|
function EightDayGiftPanel:SetAllReward()
 | 
						|
    for i=1, #EightDayRewardConfig do
 | 
						|
        local item = ItemList[i]
 | 
						|
        if not item then
 | 
						|
            item = newObject(this.itemPre)
 | 
						|
            item.name = "itemPre_"..i
 | 
						|
            item.transform:SetParent(this.show.transform)
 | 
						|
            item.transform.localScale = Vector3.one
 | 
						|
            item.transform.localPosition = Vector3.zero
 | 
						|
            ItemList[i] = item
 | 
						|
        end
 | 
						|
        item.gameObject:SetActive(true)
 | 
						|
        this:SetSingleReward(item,i)
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
function EightDayGiftPanel:SetSingleReward(item,i)
 | 
						|
    local kuang = Util.GetGameObject(item,"kuang"):GetComponent("Image")
 | 
						|
    local reward = Util.GetGameObject(item,"kuang/reward")
 | 
						|
    local event = Util.GetGameObject(item,"kuang/reward/event")
 | 
						|
    local day = Util.GetGameObject(item,"kuang/reward/days"):GetComponent("Text")
 | 
						|
    day.text = TimeToHMS(CalculateSecondsNowTo_N_OClock(24))
 | 
						|
    local icon = Util.GetGameObject(item,"kuang/reward/icon")
 | 
						|
    local name = Util.GetGameObject(item,"kuang/Button/name"):GetComponent("Text")
 | 
						|
    local btnGet = Util.GetGameObject(item,"kuang/Button")
 | 
						|
    local redPoint = Util.GetGameObject(item,"kuang/Button/redPoint")
 | 
						|
    local mask = Util.GetGameObject(item,"kuang/reward/mask")
 | 
						|
    local isCanGet = rewardData.mission[i].state--是否可领取
 | 
						|
    name.text = EightDayRewardConfig[i].ContentsShow--奖励名字
 | 
						|
    --这也要倒计时。。。
 | 
						|
    if i == curDay+1 then
 | 
						|
       this:SetRemainTime(day,i)
 | 
						|
    else
 | 
						|
        day.text = Language[10311]..NumToSimplenessFont[i]..Language[10021]
 | 
						|
    end
 | 
						|
 | 
						|
    --奖励的Icon
 | 
						|
    if not ItemViewList[i] then
 | 
						|
        local view = SubUIManager.Open(SubUIConfig.ItemView,icon.transform)
 | 
						|
        ItemViewList[i] = view
 | 
						|
    end
 | 
						|
    ItemViewList[i]:OnOpen(false,EightDayRewardConfig[i].Reward[1],0.85,false)
 | 
						|
 | 
						|
    --2\3\8可领取的金框
 | 
						|
    if i == 2 or i == 3 or i == 8 then
 | 
						|
        kuang.enabled = true--isCanGet == 0 and curDay >= i
 | 
						|
    end
 | 
						|
 | 
						|
    --设置已达成的按钮状态
 | 
						|
    Util.SetGray(btnGet,isCanGet == 1)--已经领取置灰
 | 
						|
    btnGet:GetComponent("Button").interactable = isCanGet == 0--不可点击
 | 
						|
    mask:SetActive(isCanGet == 1)
 | 
						|
    redPoint:SetActive(false)
 | 
						|
    if isCanGet == 0 then
 | 
						|
        if curDay >= i then
 | 
						|
            name.text = Language[10471]
 | 
						|
            redPoint:SetActive(true)
 | 
						|
        end
 | 
						|
    end
 | 
						|
 | 
						|
    --领取按钮
 | 
						|
    if isCanGet == 0 then
 | 
						|
        Util.AddOnceClick(btnGet,function()
 | 
						|
            if curDay >= i then
 | 
						|
 | 
						|
                --按钮状态置灰
 | 
						|
                Util.SetGray(btnGet,true)--已经领取置灰
 | 
						|
                btnGet:GetComponent("Button").interactable = true--不可点击
 | 
						|
                name.text = EightDayRewardConfig[i].ContentsShow
 | 
						|
                redPoint:SetActive(false)
 | 
						|
 | 
						|
                NetManager.GetActivityRewardRequest(rewardData.mission[i].missionId, rewardData.activityId, function(drop)
 | 
						|
                    UIManager.OpenPanel(UIName.RewardItemPopup,drop,1,function()
 | 
						|
                        ActivityGiftManager.sevenDayGetRewardState[i] = 1
 | 
						|
                        this:SetAllReward()
 | 
						|
                        Game.GlobalEvent:DispatchEvent(GameEvent.EightDay.GetRewardSuccess)
 | 
						|
                    end)
 | 
						|
                end)
 | 
						|
            else
 | 
						|
                PopupTipPanel.ShowTip(Language[10472])
 | 
						|
            end
 | 
						|
        end)
 | 
						|
    end
 | 
						|
 | 
						|
    --点击奖励时更改背景
 | 
						|
    Util.AddOnceClick(event,function()
 | 
						|
        if Live then
 | 
						|
            poolManager:UnLoadLive(bgName, Live)
 | 
						|
            Live = nil
 | 
						|
        end
 | 
						|
        this:SetBg(i)
 | 
						|
        if ItemConfig[EightDayRewardConfig[i].Reward[1][1]].ItemType == 13 then
 | 
						|
            UIManager.OpenPanel(UIName.SoulPrintPopUp,3,nil,EightDayRewardConfig[i].Reward[1][1],nil,nil)
 | 
						|
        else
 | 
						|
            ItemViewList[i]:OnBtnCkickEvent(EightDayRewardConfig[i].Reward[1][1])
 | 
						|
        end
 | 
						|
 | 
						|
 | 
						|
    end)
 | 
						|
    Util.AddOnceClick(reward,function()
 | 
						|
        if Live then
 | 
						|
            poolManager:UnLoadLive(bgName, Live)
 | 
						|
            Live = nil
 | 
						|
        end
 | 
						|
        this:SetBg(i)
 | 
						|
    end)
 | 
						|
 | 
						|
end
 | 
						|
 | 
						|
function EightDayGiftPanel:SetRemainTime(day,i)
 | 
						|
    if self.localTimer then
 | 
						|
        self.localTimer:Stop()
 | 
						|
        self.localTimer = nil
 | 
						|
    end
 | 
						|
    if not self.localTimer then
 | 
						|
        self.localTimer = Timer.New(function ()
 | 
						|
            local t = CalculateSecondsNowTo_N_OClock(5)
 | 
						|
            if t-1 < 0 then
 | 
						|
                Timer.New(function()
 | 
						|
                    if Live then
 | 
						|
                        poolManager:UnLoadLive(bgName, Live)
 | 
						|
                        Live = nil
 | 
						|
                    end
 | 
						|
                    this:Refresh()
 | 
						|
                end, 1, 1, true):Start()
 | 
						|
            end
 | 
						|
            day.text = TimeToHMS(t)
 | 
						|
        end, 1, -1, true)
 | 
						|
        self.localTimer:Start()
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
function EightDayGiftPanel:OnSortingOrderChange()
 | 
						|
    Util.AddParticleSortLayer(this.effect, self.sortingOrder - orginLayer)
 | 
						|
    orginLayer = self.sortingOrder
 | 
						|
end
 | 
						|
 | 
						|
 | 
						|
--界面打开时调用(用于子类重写)
 | 
						|
function EightDayGiftPanel:OnOpen(...)
 | 
						|
end
 | 
						|
 | 
						|
-- 打开,重新打开时回调
 | 
						|
function EightDayGiftPanel:OnShow()
 | 
						|
    this.Refresh()
 | 
						|
end
 | 
						|
 | 
						|
 | 
						|
--界面关闭时调用(用于子类重写)
 | 
						|
function EightDayGiftPanel:OnClose()
 | 
						|
    if Live then
 | 
						|
        poolManager:UnLoadLive(bgName, Live)
 | 
						|
        Live = nil
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
--界面销毁时调用(用于子类重写)
 | 
						|
function EightDayGiftPanel:OnDestroy()
 | 
						|
    orginLayer = 0
 | 
						|
    ItemList={}
 | 
						|
    ItemViewList = {}
 | 
						|
    if self.localTimer then
 | 
						|
        self.localTimer:Stop()
 | 
						|
        self.localTimer = nil
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
return EightDayGiftPanel |