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

260 lines
8.5 KiB
Lua
Raw Normal View History

local DynamicTaskPage = quick_class("DynamicTaskPage")
2020-08-20 17:36:19 +08:00
local allData={}
local itemsGrid = {}--item重复利用
local singleTaskPre = {}
local this=DynamicTaskPage
2020-08-20 17:36:19 +08:00
local parent
local endtime = 0
local bannerType = {
[1] = "bg1",
[2] = "bg2",
[3] = "bg3",
}
local GlobalActConfig = ConfigManager.GetConfig(ConfigName.GlobalActivity)
function DynamicTaskPage:ctor(mainPanel, gameObject)
2020-08-20 17:36:19 +08:00
self.mainPanel = mainPanel
self.gameObject = gameObject
self:InitComponent(gameObject)
self:BindEvent()
end
function DynamicTaskPage:InitComponent(gameObject)
2020-08-28 17:46:07 +08:00
itemsGrid = {}--item重复利用
singleTaskPre = {}
this.time = Util.GetGameObject(gameObject, "tiao/time"):GetComponent("Text")
this.itemPre = Util.GetGameObject(gameObject, "itempre")
this.scrollItem = Util.GetGameObject(gameObject, "grid")
2020-08-20 17:36:19 +08:00
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
this.gameObject = gameObject
2020-08-20 17:36:19 +08:00
end
--绑定事件(用于子类重写)
function DynamicTaskPage:BindEvent()
2020-08-20 17:36:19 +08:00
end
function this:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.DynamicTask.OnMissionChange, this.Refresh)
2020-08-20 17:36:19 +08:00
end
function this:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.DynamicTask.OnMissionChange, this.Refresh)
2020-08-20 17:36:19 +08:00
end
2020-08-20 17:36:19 +08:00
local sortingOrder = 0
--界面打开时调用(用于子类重写)
function DynamicTaskPage:OnOpen()
2020-08-20 17:36:19 +08:00
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function DynamicTaskPage:OnShow(_sortingOrder,_parent)
local id = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.DynamicAct)
local curindex = GlobalActConfig[id].ShowArt
for k,v in pairs(bannerType) do
Util.GetGameObject(this.gameObject, v):SetActive(false)
end
Util.GetGameObject(this.gameObject, bannerType[curindex]):SetActive(true)
2020-08-20 17:36:19 +08:00
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()
allData = OperatingManager:InitDynamicActData()
2020-08-20 17:36:19 +08:00
this:OnShowData()
this:SetTime()
end
function DynamicTaskPage:SetTime()
2020-08-20 17:36:19 +08:00
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
2020-08-28 17:46:07 +08:00
-- v.com.gameObject:SetActive(true)
2020-08-28 16:36:08 +08:00
if v and v.data.type == 1 then
2020-08-25 15:46:38 +08:00
v.com:GetComponent("Text").text = Language[10561]..TimeToH(five_timeDown)
2020-08-28 16:36:08 +08:00
else
2020-08-25 15:46:38 +08:00
v.com:GetComponent("Text").text = Language[10561]..TimeToDH(week_timeDown)
2020-08-28 16:36:08 +08:00
end
end
2020-08-25 15:46:38 +08:00
this.time.text = Language[12321]..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
2020-08-21 18:30:44 +08:00
if five_timeDown <= 0 then
2020-08-28 16:36:08 +08:00
this.Refresh()
return
2020-08-20 17:36:19 +08:00
end
2020-08-21 18:30:44 +08:00
if week_timeDown <= 0 then
parent:ClosePanel()
return
end
2020-08-28 16:36:08 +08:00
for k,v in pairs(singleTaskPre) do
2020-08-28 17:46:07 +08:00
-- v.com.gameObject:SetActive(true)
2020-08-28 16:36:08 +08:00
if v and v.data.type == 1 then
2020-08-25 15:46:38 +08:00
v.com:GetComponent("Text").text = Language[10561]..TimeToH(five_timeDown)
2020-08-28 16:36:08 +08:00
else
2020-08-25 15:46:38 +08:00
v.com:GetComponent("Text").text = Language[10561]..TimeToDH(week_timeDown)
2020-08-28 16:36:08 +08:00
end
end
2020-08-25 15:46:38 +08:00
this.time.text = Language[12321]..TimeToDHMS(week_timeDown)
2020-08-20 17:36:19 +08:00
end, 1, -1, true)
self.timer:Start()
end
function DynamicTaskPage:OnShowData()
2020-08-20 17:36:19 +08:00
if allData then
endtime = ActivityGiftManager.GetTaskEndTime(ActivityTypeDef.DynamicAct)
2020-08-20 17:36:19 +08:00
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)
2020-08-25 15:46:38 +08:00
PopupTipPanel.ShowTip(Language[12320])
2020-08-20 17:36:19 +08:00
return
end
end
2020-08-28 16:36:08 +08:00
local typeIndex = {
[0] = 1,
[1] = 0,
[2] = 2,
}
function DynamicTaskPage:SortData()
2020-08-20 17:36:19 +08:00
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-25 15:46:38 +08:00
[0]={sprite = "s_slbz_1anniuhuangse",text = Language[10023]},
[1]={sprite = "s_slbz_1anniuongse",text = Language[10022]},
[2]={sprite = "s_slbz_1anniuhuise",text = Language[10350]},
2020-08-28 16:36:08 +08:00
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")
2020-08-21 19:03:41 +08:00
titleText.text = sConFigData.title .."("..(sConFigData.progress > sConFigData.value and sConFigData.value or sConFigData.progress) .."/"..sConFigData.value..")"
2020-08-20 17:36:19 +08:00
local missionText = Util.GetGameObject(activityRewardGo, "mission"):GetComponent("Text")
2020-08-21 19:03:41 +08:00
missionText.text = sConFigData.content
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.DynamicActTask,sConFigData.id, function(respond)
2020-08-28 16:36:08 +08:00
UIManager.OpenPanel(UIName.RewardItemPopup, respond.drop, 1,function ()
this.Refresh()
CheckRedPointStatus(RedPointType.DynamicActTask)
2020-08-28 16:36:08 +08:00
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 DynamicTaskPage:OnOpen()
2020-08-20 17:36:19 +08:00
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 DynamicTaskPage:OnClose()
2020-08-20 17:36:19 +08:00
end
--界面销毁时调用(用于子类重写)
function DynamicTaskPage: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 17:46:07 +08:00
singleTaskPre = {}
2020-08-28 16:36:08 +08:00
itemsGrid = {}
2020-08-20 17:36:19 +08:00
end
function DynamicTaskPage:OnHide()
2020-08-28 17:46:07 +08:00
if self.timer then
self.timer:Stop()
self.timer = nil
end
2020-08-20 17:36:19 +08:00
end
--- 将一段时间转换为天时分秒
function DynamicTaskPage: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 DynamicTaskPage