206 lines
6.9 KiB
Lua
206 lines
6.9 KiB
Lua
|
local PoZhenZhuXianPage = quick_class("PoZhenZhuXianPage")
|
||
|
local allData={}
|
||
|
local itemsGrid = {}--item重复利用
|
||
|
local singleTaskPre = {}
|
||
|
local this=PoZhenZhuXianPage
|
||
|
local parent
|
||
|
local endtime = 0
|
||
|
local activityType = {
|
||
|
[1] = {name = "破阵诛仙", bg = "p_pozhengzhuxian_tu",pre = "prefab1"}
|
||
|
}
|
||
|
function PoZhenZhuXianPage:ctor(mainPanel, gameObject)
|
||
|
self.mainPanel = mainPanel
|
||
|
self.gameObject = gameObject
|
||
|
self:InitComponent(gameObject)
|
||
|
self:BindEvent()
|
||
|
end
|
||
|
|
||
|
function PoZhenZhuXianPage:InitComponent(gameObject)
|
||
|
this.time = Util.GetGameObject(gameObject, "content/tiao/time")
|
||
|
this.itemPre = Util.GetGameObject(gameObject, "content/itempre")
|
||
|
this.scrollItem = Util.GetGameObject(gameObject, "content/grid")
|
||
|
local rootHight = this.scrollItem.transform.rect.height
|
||
|
local width = this.scrollItem.transform.rect.width
|
||
|
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scrollItem.transform,
|
||
|
this.itemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 30))
|
||
|
this.ScrollView.moveTween.MomentumAmount = 1
|
||
|
this.ScrollView.moveTween.Strength = 2
|
||
|
end
|
||
|
|
||
|
--绑定事件(用于子类重写)
|
||
|
function PoZhenZhuXianPage:BindEvent()
|
||
|
end
|
||
|
|
||
|
--添加事件监听(用于子类重写)
|
||
|
function PoZhenZhuXianPage:AddListener()
|
||
|
end
|
||
|
|
||
|
--移除事件监听(用于子类重写)
|
||
|
function PoZhenZhuXianPage:RemoveListener()
|
||
|
end
|
||
|
local sortingOrder = 0
|
||
|
--界面打开时调用(用于子类重写)
|
||
|
function PoZhenZhuXianPage:OnOpen()
|
||
|
|
||
|
end
|
||
|
|
||
|
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
|
||
|
function PoZhenZhuXianPage:OnShow(_sortingOrder,_parent)
|
||
|
sortingOrder = _sortingOrder
|
||
|
parent = _parent
|
||
|
this:OnShowData()
|
||
|
end
|
||
|
|
||
|
function this.Refresh()
|
||
|
this:OnShowData()
|
||
|
this:SetTime()
|
||
|
end
|
||
|
|
||
|
function PoZhenZhuXianPage:SetTime()
|
||
|
if self.timer then
|
||
|
self.timer:Stop()
|
||
|
self.timer = nil
|
||
|
end
|
||
|
self.timer = Timer.New(function()
|
||
|
local timeDown
|
||
|
for i = 1,#allData do
|
||
|
if allData[i].type == 1 then
|
||
|
timeDown = CalculateSecondsNowTo_N_OClock(5)
|
||
|
singleTaskPre[allData[i].id].text = "剩余:"..TimeToHMS(timeDown)
|
||
|
else
|
||
|
timeDown = endtime - GetTimeStamp()
|
||
|
singleTaskPre[allData[i].id].text = "剩余:"..TimeToDHMS(timeDown)
|
||
|
end
|
||
|
if timeDown < 1 then
|
||
|
this.Refresh()
|
||
|
return
|
||
|
end
|
||
|
end
|
||
|
timeDown = endtime - GetTimeStamp()
|
||
|
this.time.text = "剩余时间:"..TimeToDHMS(timeDown)
|
||
|
end, 1, -1, true)
|
||
|
self.timer:Start()
|
||
|
end
|
||
|
|
||
|
function PoZhenZhuXianPage:OnShowData()
|
||
|
allData = OperatingManager:InitPoZhenZhuXianData()
|
||
|
if allData then
|
||
|
endtime = ActivityGiftManager.GetTaskEndTime(ActivityTypeDef.pozhenzhuxian_task)
|
||
|
this.SortData(allData)
|
||
|
this.ScrollView:SetData(allData, function (index, go)
|
||
|
this.SingleDataShow(go, allData[index])
|
||
|
singleTaskPre[allData[index].id] = Util.GetGameObject(go,"btn/Text"):GetComponent("Text")
|
||
|
end)
|
||
|
LogError(#allData)
|
||
|
else
|
||
|
parent.OnPageTabChange(1)
|
||
|
PopupTipPanel.ShowTip("活动已结束")
|
||
|
return
|
||
|
end
|
||
|
|
||
|
end
|
||
|
function PoZhenZhuXianPage:SortData()
|
||
|
if allData==nil then
|
||
|
return
|
||
|
end
|
||
|
table.sort(allData, function(a,b)
|
||
|
if a.type == b.type then
|
||
|
return a.id < b.id
|
||
|
else
|
||
|
return a.type < b.type
|
||
|
end
|
||
|
end)
|
||
|
end
|
||
|
local type={
|
||
|
[0]={sprite = "s_slbz_1anniuhuangse",text = "前往"},
|
||
|
[1]={sprite = "s_slbz_1anniuhuise",text = "已领取"},
|
||
|
[2]={sprite = "s_slbz_1anniuongse",text = "领取"},
|
||
|
}
|
||
|
--刷新每一条的显示数据
|
||
|
function this.SingleDataShow(pre,value)
|
||
|
if pre==nil or value==nil then
|
||
|
return
|
||
|
end
|
||
|
--绑定组件
|
||
|
local activityRewardGo = pre
|
||
|
activityRewardGo:SetActive(true)
|
||
|
local sConFigData = value
|
||
|
|
||
|
local titleText = Util.GetGameObject(activityRewardGo, "title"):GetComponent("Text")
|
||
|
titleText.text = sConFigData.title
|
||
|
local missionText = Util.GetGameObject(activityRewardGo, "mission"):GetComponent("Text")
|
||
|
missionText.text = sConFigData.content.."("..(sConFigData.progress > sConFigData.value and sConFigData.value or sConFigData.progress) .."/"..sConFigData.value..")"
|
||
|
|
||
|
local reward = Util.GetGameObject(activityRewardGo.gameObject, "reward")
|
||
|
if (not itemsGrid) then
|
||
|
itemsGrid = {}
|
||
|
end
|
||
|
if not itemsGrid[pre] then
|
||
|
itemsGrid[pre] = SubUIManager.Open(SubUIConfig.ItemView,reward.transform)
|
||
|
end
|
||
|
itemsGrid[pre]:OnOpen(false, sConFigData.reward, 0.9, false)
|
||
|
|
||
|
local lingquButton = Util.GetGameObject(activityRewardGo.gameObject, "btn")
|
||
|
local state = sConFigData.state == 1 and sConFigData.state or (sConFigData.progress >= sConFigData.value and 2 or 0) -- 0 前往 1已领奖 2领奖
|
||
|
|
||
|
local red = Util.GetGameObject(lingquButton.gameObject, "redPoint")
|
||
|
red:SetActive(state == 2)
|
||
|
|
||
|
Util.GetGameObject(lingquButton.gameObject, "Button/Text"):GetComponent("Text").text = type[state].text
|
||
|
Util.GetGameObject(lingquButton.gameObject, "Button"):GetComponent("Image").sprite = Util.LoadSprite(type[state].sprite)
|
||
|
Util.GetGameObject(lingquButton.gameObject, "Button").gameObject:SetActive(state ~= 1)
|
||
|
Util.GetGameObject(lingquButton.gameObject, "image").gameObject:SetActive(state == 1)
|
||
|
|
||
|
Util.AddOnceClick(Util.GetGameObject(lingquButton.gameObject, "Button"), function()
|
||
|
if state == 2 then
|
||
|
local curActivityId = ActivityGiftManager.GetActivityIdByType(ActivityTypeDef.pozhenzhuxian_task)
|
||
|
NetManager.GetActivityRewardRequest(sConFigData.id, curActivityId,function(respond)
|
||
|
UIManager.OpenPanel(UIName.RewardItemPopup, respond, 1)
|
||
|
this.Refresh()
|
||
|
end)
|
||
|
elseif state == 0 then
|
||
|
if sConFigData.jump then
|
||
|
JumpManager.GoJump(sConFigData.jump[1])
|
||
|
end
|
||
|
end
|
||
|
end)
|
||
|
|
||
|
end
|
||
|
|
||
|
--界面打开时调用(用于子类重写)
|
||
|
function PoZhenZhuXianPage:OnOpen()
|
||
|
|
||
|
end
|
||
|
|
||
|
function this.RechargeSuccessFunc(id)
|
||
|
FirstRechargeManager.RefreshAccumRechargeValue(id)
|
||
|
--OperatingManager.RefreshGiftGoodsBuyTimes(GoodsTypeDef.GiftBuy, id)
|
||
|
this.OnShowData()
|
||
|
end
|
||
|
|
||
|
function PoZhenZhuXianPage:OnClose()
|
||
|
|
||
|
end
|
||
|
|
||
|
--界面销毁时调用(用于子类重写)
|
||
|
function PoZhenZhuXianPage:OnDestroy()
|
||
|
sortingOrder = 0
|
||
|
end
|
||
|
|
||
|
function PoZhenZhuXianPage:OnHide()
|
||
|
sortingOrder = 0
|
||
|
end
|
||
|
--- 将一段时间转换为天时分秒
|
||
|
function PoZhenZhuXianPage:TimeToDHMS(second)
|
||
|
local day = math.floor(second / (24 * 3600))
|
||
|
local minute = math.floor(second / 60) % 60
|
||
|
local sec = second % 60
|
||
|
local hour = math.floor(math.floor(second - day * 24 * 3600 - sec - minute * 60) / 3600)
|
||
|
if day <= 0 and hour <= 0 then
|
||
|
return string.format(Language[12231],minute, sec)
|
||
|
else
|
||
|
return string.format(Language[12232],day, hour)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
return PoZhenZhuXianPage
|