336 lines
13 KiB
Lua
336 lines
13 KiB
Lua
local DynamicTaskPage = quick_class("DynamicTaskPage")
|
||
local allData = {}
|
||
local itemsGrid = {} --item重复利用
|
||
local singleTaskPre = {}
|
||
local this = DynamicTaskPage
|
||
local parent
|
||
local endtime = 0
|
||
local bannerType = {
|
||
[1] = { compent = "bg1", titilebg1 = "p_pozhengzhuxian_tu_zh" },
|
||
[2] = { compent = "bg1", titilebg1 = "c_ydsj_banner_zh" },
|
||
[3] = { compent = "bg2", titilebg1 = "c_ccfy_banner", titilebg2 = "c_ccfy_beijin-slogan_zh" },
|
||
[4] = { compent = "bg1", titilebg1 = "d_danxinbixue_banner_zh" },
|
||
[5] = { compent = "bg1", titilebg1 = "s_shibukedang_banner_zh" },
|
||
[6] = { compent = "bg1", titilebg1 = "s_yongwangzhiqian_banner_zh" },
|
||
[7] = { compent = "bg1", titilebg1 = "y_yunchouweiwo_banner_zh" },
|
||
[8] = { compent = "bg1", titilebg1 = "y_yishandaohai_banner_zh" },
|
||
[9] = { compent = "bg1", titilebg1 = "x_xuanjimiaosuan_banner_zh" },
|
||
[10] = { compent = "bg1", titilebg1 = "x_xianglongfuhu_banner_zh" },
|
||
[11] = { compent = "bg1", titilebg1 = "q_qikaidesheng_banner_zh" },
|
||
[12] = { compent = "bg1", titilebg1 = "b_bianhuanmoce_banner_zh" },
|
||
[13] = { compent = "bg1", titilebg1 = "b_bowenduoshi_banner_zh" },
|
||
[14] = { compent = "bg1", titilebg1 = "t_tianxiangjiren_banner_zh" },
|
||
[15] = { compent = "bg1", titilebg1 = "s_suoxiangpimi_banner_zh" },
|
||
[16] = { compent = "bg1", titilebg1 = "x_xialuxiangfeng_banner_zh" },
|
||
[17] = { compent = "bg1", titilebg1 = "t_tongqiangtiebi_banner_zh" },
|
||
[18] = { compent = "bg1", titilebg1 = "p_pozhengzhuxian_banner_zh" },
|
||
[19] = { compent = "bg1", titilebg1 = "c_ydsj_banner01_zh" },
|
||
[20] = { compent = "bg1", titilebg1 = "c_ccfy_banner01_zh" },
|
||
[21] = { compent = "bg1", titilebg1 = "d_danxinbixue_banner2_zh" },
|
||
[22] = { compent = "bg1", titilebg1 = "s_shibukedang_banner01_zh" },
|
||
[23] = { compent = "bg1", titilebg1 = "s_yongwangzhiqian_banner_zh" },
|
||
[24] = { compent = "bg1", titilebg1 = "y_yunchouweiwo_banner_zh" },
|
||
[25] = { compent = "bg1", titilebg1 = "y_yishandaohai_banner_zh" },
|
||
[26] = { compent = "bg1", titilebg1 = "x_xuanjimiaosuan_banner_zh" },
|
||
[27] = { compent = "bg1", titilebg1 = "x_xianglongfuhu_banner2_zh" },
|
||
[28] = { compent = "bg1", titilebg1 = "b_bowenduoshi_banner_zh" },
|
||
[29] = { compent = "bg1", titilebg1 = "t_tianxiangjiren_banner_zh" },
|
||
[30] = { compent = "bg1", titilebg1 = "s_suoxiangpimi_banner_zh" },
|
||
[31] = { compent = "bg1", titilebg1 = "x_xialuxiangfeng_banner_zh" },
|
||
[32] = { compent = "bg1", titilebg1 = "s_suoxiangpimi_banner_zh" },
|
||
[33] = { compent = "bg1", titilebg1 = "x_xialuxiangfeng_banner_zh" },
|
||
[34] = { compent = "bg1", titilebg1 = "t_tongqiangtiebi_banner_zh" },
|
||
[35] = { compent = "bg1", titilebg1 = "d_danxinbixue_banner_zh" },
|
||
[36] = { compent = "bg1", titilebg1 = "s_shibukedang_banner_zh" },
|
||
[37] = { compent = "bg1", titilebg1 = "s_yongwangzhiqian_banner_zh" },
|
||
[38] = { compent = "bg1", titilebg1 = "y_yunchouweiwo_banner_zh" },
|
||
[39] = { compent = "bg1", titilebg1 = "y_yishandaohai_banner_zh" },
|
||
}
|
||
local GlobalActConfig = ConfigManager.GetConfig(ConfigName.GlobalActivity)
|
||
function DynamicTaskPage:ctor(mainPanel, gameObject)
|
||
self.mainPanel = mainPanel
|
||
self.gameObject = gameObject
|
||
self:InitComponent(gameObject)
|
||
self:BindEvent()
|
||
end
|
||
|
||
function DynamicTaskPage:InitComponent(gameObject)
|
||
this.spLoader = SpriteLoader.New()
|
||
itemsGrid = {} --item重复利用
|
||
singleTaskPre = {}
|
||
this.time = Util.GetGameObject(gameObject, "tiao/time"):GetComponent("Text")
|
||
this.itemPre = Util.GetGameObject(gameObject, "itempre")
|
||
this.scrollItem = Util.GetGameObject(gameObject, "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
|
||
this.gameObject = gameObject
|
||
end
|
||
|
||
--绑定事件(用于子类重写)
|
||
function DynamicTaskPage:BindEvent()
|
||
end
|
||
|
||
function this:AddListener()
|
||
Game.GlobalEvent:AddEvent(GameEvent.DynamicTask.OnMissionChange, this.Refresh)
|
||
end
|
||
|
||
function this:RemoveListener()
|
||
Game.GlobalEvent:RemoveEvent(GameEvent.DynamicTask.OnMissionChange, this.Refresh)
|
||
end
|
||
|
||
local sortingOrder = 0
|
||
--界面打开时调用(用于子类重写)
|
||
function DynamicTaskPage:OnOpen(_activityConfig, _index, parent)
|
||
self.actConfig = _activityConfig
|
||
self.pageIndex = _index
|
||
self.parent = parent
|
||
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.compent):SetActive(false)
|
||
end
|
||
Util.GetGameObject(this.gameObject, bannerType[curindex].compent):SetActive(true)
|
||
Util.GetGameObject(this.gameObject, bannerType[curindex].compent):GetComponent("Image").sprite = this.spLoader
|
||
:LoadSprite(bannerType[curindex].titilebg1)
|
||
if bannerType[curindex].titilebg2 and bannerType[curindex].titilebg2 ~= "" then
|
||
Util.GetGameObject(this.gameObject, bannerType[curindex].compent .. "/Image"):GetComponent("Image").sprite = this
|
||
.spLoader:LoadSprite(bannerType[curindex].titilebg2)
|
||
end
|
||
sortingOrder = _sortingOrder
|
||
parent = _parent
|
||
this.Refresh(true, true)
|
||
end
|
||
|
||
function this.Refresh(isTop, isAni)
|
||
LogRed("isTop " .. tostring(isTop) .. " isAni " .. tostring(isAni))
|
||
allData = OperatingManager:InitDynamicActData()
|
||
this:OnShowData(isTop, isAni)
|
||
this:SetTime()
|
||
end
|
||
|
||
function DynamicTaskPage:SetTime()
|
||
if self.timer then
|
||
self.timer:Stop()
|
||
self.timer = nil
|
||
end
|
||
local five_timeDown
|
||
local week_timeDown
|
||
five_timeDown = CalculateSecondsNowTo_N_OClock(0)
|
||
week_timeDown = endtime - GetTimeStamp()
|
||
for k, v in pairs(singleTaskPre) do
|
||
-- v.com.gameObject:SetActive(true)
|
||
if v and v.data.type == 1 then
|
||
if five_timeDown > 3600 then
|
||
v.com:GetComponent("Text").text = Language[10569] .. TimeToH(five_timeDown)
|
||
else
|
||
v.com:GetComponent("Text").text = Language[10569] .. TimeToMS(five_timeDown)
|
||
end
|
||
else
|
||
if week_timeDown > 3600 then
|
||
v.com:GetComponent("Text").text = Language[10569] .. TimeToDH(week_timeDown)
|
||
else
|
||
v.com:GetComponent("Text").text = Language[10569] .. TimeToMS(week_timeDown)
|
||
end
|
||
end
|
||
end
|
||
this.time.text = Language[10570] .. TimeToDHMS(week_timeDown)
|
||
self.timer = Timer.New(function()
|
||
five_timeDown = five_timeDown - 1
|
||
week_timeDown = week_timeDown - 1
|
||
if five_timeDown <= 0 then
|
||
this.Refresh(false, false)
|
||
return
|
||
end
|
||
if week_timeDown <= 0 then
|
||
return
|
||
end
|
||
for k, v in pairs(singleTaskPre) do
|
||
-- v.com.gameObject:SetActive(true)
|
||
if v and v.data.type == 1 then
|
||
if five_timeDown >= 3600 then
|
||
v.com:GetComponent("Text").text = Language[10569] .. TimeToH(five_timeDown)
|
||
else
|
||
v.com:GetComponent("Text").text = Language[10569] .. TimeToMS(five_timeDown)
|
||
end
|
||
else
|
||
if week_timeDown >= 3600 then
|
||
v.com:GetComponent("Text").text = Language[10569] .. TimeToDH(week_timeDown)
|
||
else
|
||
v.com:GetComponent("Text").text = Language[10569] .. TimeToMS(week_timeDown)
|
||
end
|
||
end
|
||
end
|
||
this.time.text = Language[10570] .. TimeToDHMS(week_timeDown)
|
||
end, 1, -1, true)
|
||
self.timer:Start()
|
||
end
|
||
|
||
function DynamicTaskPage:OnShowData(isTop, isAni)
|
||
if allData then
|
||
endtime = ActivityGiftManager.GetTaskEndTime(ActivityTypeDef.DynamicAct)
|
||
this.SortData(allData)
|
||
this.ScrollView:SetData(allData, function(index, go)
|
||
this.SingleDataShow(go, allData[index])
|
||
if not singleTaskPre[go] then
|
||
singleTaskPre[go] = {}
|
||
end
|
||
singleTaskPre[go].com = Util.GetGameObject(go, "btn/Text")
|
||
singleTaskPre[go].data = allData[index]
|
||
end, not isTop, not isAni)
|
||
else
|
||
parent.OnPageTabChange(1)
|
||
PopupTipPanel.ShowTip(Language[10510])
|
||
return
|
||
end
|
||
end
|
||
|
||
local typeIndex = {
|
||
[0] = 1,
|
||
[1] = 0,
|
||
[2] = 2,
|
||
}
|
||
function DynamicTaskPage:SortData()
|
||
if allData == nil then
|
||
return
|
||
end
|
||
table.sort(allData, function(a, b)
|
||
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
|
||
end)
|
||
end
|
||
|
||
local type = {
|
||
[0] = { sprite = "s_slbz_1anniuhuangse", text = Language[10019] },
|
||
[1] = { sprite = "s_slbz_1anniuongse", text = Language[10018] },
|
||
[2] = { sprite = "s_slbz_1anniuhuise", text = Language[10025] },
|
||
}
|
||
--刷新每一条的显示数据
|
||
function this.SingleDataShow(pre, value)
|
||
if pre == nil or value == nil then
|
||
return
|
||
end
|
||
--绑定组件
|
||
local activityRewardGo = pre
|
||
activityRewardGo:SetActive(true)
|
||
local sConFigData = value
|
||
local state = sConFigData.state
|
||
|
||
local titleText = Util.GetGameObject(activityRewardGo, "title"):GetComponent("Text")
|
||
if state == 2 or state == 1 then
|
||
titleText.text = GetLanguageStrById(sConFigData.title) ..
|
||
"(" .. sConFigData.value .. "/" .. sConFigData.value .. ")"
|
||
else
|
||
titleText.text = GetLanguageStrById(sConFigData.title) ..
|
||
"(" ..
|
||
(sConFigData.progress > sConFigData.value and sConFigData.value or sConFigData.progress) ..
|
||
"/" .. sConFigData.value .. ")"
|
||
end
|
||
|
||
local missionText = Util.GetGameObject(activityRewardGo, "mission"):GetComponent("Text")
|
||
missionText.text = GetLanguageStrById(sConFigData.content)
|
||
local timeText = Util.GetGameObject(activityRewardGo, "btn/Text")
|
||
|
||
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")
|
||
--0-未完成,1-完成未领取 2-已领取
|
||
|
||
timeText:SetActive(state == 0)
|
||
|
||
local red = Util.GetGameObject(lingquButton.gameObject, "redPoint")
|
||
red:SetActive(state == 1)
|
||
|
||
local btn = Util.GetGameObject(lingquButton.gameObject, "Button")
|
||
Util.GetGameObject(btn, "Text"):GetComponent("Text").text = type[state].text
|
||
btn:GetComponent("Image").sprite = this.spLoader:LoadSprite(type[state].sprite)
|
||
btn:GetComponent("Button").enabled = state ~= 2
|
||
Util.SetGray(btn, state == 2)
|
||
|
||
Util.AddOnceClick(Util.GetGameObject(lingquButton.gameObject, "Button"), function()
|
||
if state == 1 then
|
||
NetManager.TakeMissionRewardRequest(TaskTypeDef.DynamicActTask, sConFigData.id, function(respond)
|
||
UIManager.OpenPanel(UIName.RewardItemPopup, respond.drop, 1, function()
|
||
this.Refresh(false, false)
|
||
CheckRedPointStatus(RedPointType.DynamicActTask_MeiRi)
|
||
CheckRedPointStatus(RedPointType.DynamicActTask_MeiZhou)
|
||
end)
|
||
end)
|
||
elseif state == 0 then
|
||
if sConFigData.jump then
|
||
JumpManager.GoJump(sConFigData.jump)
|
||
end
|
||
end
|
||
end)
|
||
end
|
||
|
||
--界面打开时调用(用于子类重写)
|
||
function DynamicTaskPage:OnOpen()
|
||
|
||
end
|
||
|
||
function this.RechargeSuccessFunc(id)
|
||
FirstRechargeManager.RefreshAccumRechargeValue(id)
|
||
--OperatingManager.RefreshGiftGoodsBuyTimes(GoodsTypeDef.GiftBuy, id)
|
||
this.Refresh(false, false)
|
||
end
|
||
|
||
function DynamicTaskPage:OnClose()
|
||
|
||
end
|
||
|
||
--界面销毁时调用(用于子类重写)
|
||
function DynamicTaskPage:OnDestroy()
|
||
this.spLoader:Destroy()
|
||
if self.timer then
|
||
self.timer:Stop()
|
||
self.timer = nil
|
||
end
|
||
sortingOrder = 0
|
||
singleTaskPre = {}
|
||
itemsGrid = {}
|
||
end
|
||
|
||
function DynamicTaskPage:OnHide()
|
||
if self.timer then
|
||
self.timer:Stop()
|
||
self.timer = nil
|
||
end
|
||
end
|
||
|
||
--- 将一段时间转换为天时分秒
|
||
function DynamicTaskPage: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[10571], minute, sec)
|
||
else
|
||
return string.format(Language[10572], day, hour)
|
||
end
|
||
end
|
||
|
||
return DynamicTaskPage
|