2020-08-20 17:36:19 +08:00
|
|
|
|
local PoZhenZhuXianPage = quick_class("PoZhenZhuXianPage")
|
|
|
|
|
local allData={}
|
|
|
|
|
local itemsGrid = {}--item重复利用
|
|
|
|
|
local singleTaskPre = {}
|
|
|
|
|
local this=PoZhenZhuXianPage
|
|
|
|
|
local parent
|
|
|
|
|
local endtime = 0
|
|
|
|
|
function PoZhenZhuXianPage:ctor(mainPanel, gameObject)
|
|
|
|
|
self.mainPanel = mainPanel
|
|
|
|
|
self.gameObject = gameObject
|
|
|
|
|
self:InitComponent(gameObject)
|
|
|
|
|
self:BindEvent()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PoZhenZhuXianPage:InitComponent(gameObject)
|
2020-08-28 16:36:08 +08:00
|
|
|
|
this.time = Util.GetGameObject(gameObject, "content/tiao/time"):GetComponent("Text")
|
2020-08-20 18:32:14 +08:00
|
|
|
|
this.itemPre = Util.GetGameObject(gameObject, "content/itempre")
|
2020-08-20 17:36:19 +08:00
|
|
|
|
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
|
2020-08-28 16:36:08 +08:00
|
|
|
|
this.Refresh()
|
2020-08-20 17:36:19 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function this.Refresh()
|
2020-08-28 16:36:08 +08:00
|
|
|
|
allData = OperatingManager:InitPoZhenZhuXianData()
|
2020-08-20 17:36:19 +08:00
|
|
|
|
this:OnShowData()
|
|
|
|
|
this:SetTime()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PoZhenZhuXianPage:SetTime()
|
|
|
|
|
if self.timer then
|
|
|
|
|
self.timer:Stop()
|
|
|
|
|
self.timer = nil
|
|
|
|
|
end
|
2020-08-28 16:36:08 +08:00
|
|
|
|
local five_timeDown
|
|
|
|
|
local week_timeDown
|
|
|
|
|
five_timeDown = CalculateSecondsNowTo_N_OClock(5)
|
|
|
|
|
week_timeDown = endtime - GetTimeStamp()
|
|
|
|
|
for k,v in pairs(singleTaskPre) do
|
|
|
|
|
v.com.gameObject:SetActive(true)
|
|
|
|
|
if v and v.data.type == 1 then
|
|
|
|
|
v.com:GetComponent("Text").text = "剩余:"..TimeToHMS(five_timeDown)
|
|
|
|
|
else
|
|
|
|
|
v.com:GetComponent("Text").text = "剩余:"..TimeToHMS(week_timeDown)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
this.time.text = "剩余时间:"..TimeToDHMS(week_timeDown)
|
2020-08-20 17:36:19 +08:00
|
|
|
|
self.timer = Timer.New(function()
|
2020-08-28 16:36:08 +08:00
|
|
|
|
five_timeDown = five_timeDown - 1
|
|
|
|
|
week_timeDown = week_timeDown - 1
|
|
|
|
|
if five_timeDown <= 0 or week_timeDown <= 0 then
|
|
|
|
|
this.Refresh()
|
|
|
|
|
return
|
2020-08-20 17:36:19 +08:00
|
|
|
|
end
|
2020-08-28 16:36:08 +08:00
|
|
|
|
for k,v in pairs(singleTaskPre) do
|
|
|
|
|
v.com.gameObject:SetActive(true)
|
|
|
|
|
if v and v.data.type == 1 then
|
|
|
|
|
v.com:GetComponent("Text").text = "剩余:"..TimeToHMS(five_timeDown)
|
|
|
|
|
else
|
|
|
|
|
v.com:GetComponent("Text").text = "剩余:"..TimeToHMS(week_timeDown)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
this.time.text = "剩余时间:"..TimeToDHMS(week_timeDown)
|
2020-08-20 17:36:19 +08:00
|
|
|
|
end, 1, -1, true)
|
|
|
|
|
self.timer:Start()
|
|
|
|
|
end
|
|
|
|
|
|
2020-08-28 16:36:08 +08:00
|
|
|
|
function PoZhenZhuXianPage:OnShowData()
|
2020-08-20 17:36:19 +08:00
|
|
|
|
if allData then
|
|
|
|
|
endtime = ActivityGiftManager.GetTaskEndTime(ActivityTypeDef.pozhenzhuxian_task)
|
|
|
|
|
this.SortData(allData)
|
|
|
|
|
this.ScrollView:SetData(allData, function (index, go)
|
|
|
|
|
this.SingleDataShow(go, allData[index])
|
2020-08-28 16:36:08 +08:00
|
|
|
|
if not singleTaskPre[go] then
|
|
|
|
|
singleTaskPre[go] = {}
|
|
|
|
|
end
|
|
|
|
|
singleTaskPre[go].com = Util.GetGameObject(go,"btn/Text")
|
|
|
|
|
singleTaskPre[go].data = allData[index]
|
|
|
|
|
end)
|
2020-08-20 17:36:19 +08:00
|
|
|
|
else
|
|
|
|
|
parent.OnPageTabChange(1)
|
|
|
|
|
PopupTipPanel.ShowTip("活动已结束")
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
2020-08-28 16:36:08 +08:00
|
|
|
|
local typeIndex = {
|
|
|
|
|
[0] = 1,
|
|
|
|
|
[1] = 0,
|
|
|
|
|
[2] = 2,
|
|
|
|
|
}
|
2020-08-20 17:36:19 +08:00
|
|
|
|
function PoZhenZhuXianPage:SortData()
|
|
|
|
|
if allData==nil then
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
table.sort(allData, function(a,b)
|
2020-08-28 16:36:08 +08:00
|
|
|
|
if typeIndex[a.state] == typeIndex[b.state] then
|
|
|
|
|
if a.type == b.type then
|
|
|
|
|
return a.id < b.id
|
|
|
|
|
else
|
|
|
|
|
return a.type < b.type
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
return typeIndex[a.state] < typeIndex[b.state]
|
|
|
|
|
end
|
2020-08-20 17:36:19 +08:00
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
local type={
|
2020-08-28 16:36:08 +08:00
|
|
|
|
[0]={sprite = "s_slbz_1anniuhuangse",text = "前往"},
|
|
|
|
|
[1]={sprite = "s_slbz_1anniuongse",text = "领取"},
|
|
|
|
|
[2]={sprite = "s_slbz_1anniuhuise",text = "已领取"},
|
|
|
|
|
|
2020-08-20 17:36:19 +08:00
|
|
|
|
}
|
|
|
|
|
--刷新每一条的显示数据
|
|
|
|
|
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..")"
|
2020-08-28 16:36:08 +08:00
|
|
|
|
local timeText = Util.GetGameObject(activityRewardGo, "btn/Text")
|
2020-08-20 17:36:19 +08:00
|
|
|
|
|
|
|
|
|
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")
|
2020-08-28 16:36:08 +08:00
|
|
|
|
--0-未完成,1-完成未领取 2-已领取
|
|
|
|
|
local state = sConFigData.state
|
|
|
|
|
timeText:SetActive(state == 0)
|
2020-08-20 17:36:19 +08:00
|
|
|
|
|
|
|
|
|
local red = Util.GetGameObject(lingquButton.gameObject, "redPoint")
|
2020-08-28 16:36:08 +08:00
|
|
|
|
red:SetActive(state == 1)
|
2020-08-20 17:36:19 +08:00
|
|
|
|
|
|
|
|
|
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)
|
2020-08-28 16:36:08 +08:00
|
|
|
|
Util.GetGameObject(lingquButton.gameObject, "Button").gameObject:SetActive(state ~= 2)
|
|
|
|
|
Util.GetGameObject(lingquButton.gameObject, "image").gameObject:SetActive(state == 2)
|
2020-08-20 17:36:19 +08:00
|
|
|
|
|
|
|
|
|
Util.AddOnceClick(Util.GetGameObject(lingquButton.gameObject, "Button"), function()
|
2020-08-28 16:36:08 +08:00
|
|
|
|
if state == 1 then
|
|
|
|
|
NetManager.TakeMissionRewardRequest(TaskTypeDef.PoZhenZhuXianTask,sConFigData.id, function(respond)
|
|
|
|
|
UIManager.OpenPanel(UIName.RewardItemPopup, respond.drop, 1,function ()
|
|
|
|
|
this.Refresh()
|
|
|
|
|
end)
|
2020-08-20 17:36:19 +08:00
|
|
|
|
end)
|
|
|
|
|
elseif state == 0 then
|
|
|
|
|
if sConFigData.jump then
|
2020-08-28 16:36:08 +08:00
|
|
|
|
JumpManager.GoJump(sConFigData.jump)
|
2020-08-20 17:36:19 +08:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--界面打开时调用(用于子类重写)
|
|
|
|
|
function PoZhenZhuXianPage:OnOpen()
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function this.RechargeSuccessFunc(id)
|
|
|
|
|
FirstRechargeManager.RefreshAccumRechargeValue(id)
|
|
|
|
|
--OperatingManager.RefreshGiftGoodsBuyTimes(GoodsTypeDef.GiftBuy, id)
|
2020-08-28 16:36:08 +08:00
|
|
|
|
this.Refresh()
|
2020-08-20 17:36:19 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PoZhenZhuXianPage:OnClose()
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
--界面销毁时调用(用于子类重写)
|
|
|
|
|
function PoZhenZhuXianPage:OnDestroy()
|
2020-08-28 16:36:08 +08:00
|
|
|
|
if self.timer then
|
|
|
|
|
self.timer:Stop()
|
|
|
|
|
self.timer = nil
|
|
|
|
|
end
|
2020-08-20 17:36:19 +08:00
|
|
|
|
sortingOrder = 0
|
2020-08-28 16:36:08 +08:00
|
|
|
|
if singleTaskPre then
|
|
|
|
|
singleTaskPre = {}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
itemsGrid = {}
|
2020-08-20 17:36:19 +08:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function PoZhenZhuXianPage:OnHide()
|
|
|
|
|
sortingOrder = 0
|
|
|
|
|
end
|
|
|
|
|
--- 将一段时间转换为天时分秒
|
2020-08-20 18:32:14 +08:00
|
|
|
|
function PoZhenZhuXianPage:TimeToDHMS(second)
|
2020-08-20 17:36:19 +08:00
|
|
|
|
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
|