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

336 lines
13 KiB
Lua
Raw Normal View History

2025-03-14 11:58:20 +08:00
local DynamicTaskPage = quick_class("DynamicTaskPage")
2024-09-20 11:45:46 +08:00
local allData = {}
local itemsGrid = {} --item重复利用
local singleTaskPre = {}
2024-09-20 11:45:46 +08:00
local this = DynamicTaskPage
local parent
local endtime = 0
local bannerType = {
2024-09-20 11:45:46 +08:00
[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)
2021-04-21 13:12:04 +08:00
this.spLoader = SpriteLoader.New()
2024-09-20 11:45:46 +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")
local rootHight = this.scrollItem.transform.rect.height
local width = this.scrollItem.transform.rect.width
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scrollItem.transform,
2024-09-20 11:45:46 +08:00
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
--界面打开时调用(用于子类重写)
2024-09-20 11:45:46 +08:00
function DynamicTaskPage:OnOpen(_activityConfig, _index, parent)
self.actConfig = _activityConfig
self.pageIndex = _index
self.parent = parent
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
2024-09-20 11:45:46 +08:00
function DynamicTaskPage:OnShow(_sortingOrder, _parent)
local id = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.DynamicAct)
local curindex = GlobalActConfig[id].ShowArt
2024-09-20 11:45:46 +08:00
for k, v in pairs(bannerType) do
2020-10-10 14:37:04 +08:00
Util.GetGameObject(this.gameObject, v.compent):SetActive(false)
end
Util.GetGameObject(this.gameObject, bannerType[curindex].compent):SetActive(true)
2024-09-20 11:45:46 +08:00
Util.GetGameObject(this.gameObject, bannerType[curindex].compent):GetComponent("Image").sprite = this.spLoader
:LoadSprite(bannerType[curindex].titilebg1)
2020-10-10 14:37:04 +08:00
if bannerType[curindex].titilebg2 and bannerType[curindex].titilebg2 ~= "" then
2024-09-20 11:45:46 +08:00
Util.GetGameObject(this.gameObject, bannerType[curindex].compent .. "/Image"):GetComponent("Image").sprite = this
.spLoader:LoadSprite(bannerType[curindex].titilebg2)
end
sortingOrder = _sortingOrder
2024-09-20 11:45:46 +08:00
parent = _parent
this.Refresh(true, true)
end
2024-09-20 11:45:46 +08:00
function this.Refresh(isTop, isAni)
LogRed("isTop " .. tostring(isTop) .. " isAni " .. tostring(isAni))
allData = OperatingManager:InitDynamicActData()
2024-09-20 11:45:46 +08:00
this:OnShowData(isTop, isAni)
this:SetTime()
end
function DynamicTaskPage:SetTime()
if self.timer then
self.timer:Stop()
self.timer = nil
2024-09-20 11:45:46 +08:00
end
local five_timeDown
local week_timeDown
five_timeDown = CalculateSecondsNowTo_N_OClock(0)
week_timeDown = endtime - GetTimeStamp()
2024-09-20 11:45:46 +08:00
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
2024-09-20 11:45:46 +08:00
v.com:GetComponent("Text").text = Language[10569] .. TimeToH(five_timeDown)
else
2024-09-20 11:45:46 +08:00
v.com:GetComponent("Text").text = Language[10569] .. TimeToMS(five_timeDown)
end
else
if week_timeDown > 3600 then
2024-09-20 11:45:46 +08:00
v.com:GetComponent("Text").text = Language[10569] .. TimeToDH(week_timeDown)
else
2024-09-20 11:45:46 +08:00
v.com:GetComponent("Text").text = Language[10569] .. TimeToMS(week_timeDown)
end
2024-09-20 11:45:46 +08:00
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
2024-09-20 11:45:46 +08:00
if five_timeDown <= 0 then
this.Refresh(false, false)
return
end
if week_timeDown <= 0 then
return
end
2024-09-20 11:45:46 +08:00
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
2024-09-20 11:45:46 +08:00
v.com:GetComponent("Text").text = Language[10569] .. TimeToH(five_timeDown)
else
2024-09-20 11:45:46 +08:00
v.com:GetComponent("Text").text = Language[10569] .. TimeToMS(five_timeDown)
end
else
if week_timeDown >= 3600 then
2024-09-20 11:45:46 +08:00
v.com:GetComponent("Text").text = Language[10569] .. TimeToDH(week_timeDown)
else
2024-09-20 11:45:46 +08:00
v.com:GetComponent("Text").text = Language[10569] .. TimeToMS(week_timeDown)
end
2024-09-20 11:45:46 +08:00
end
end
this.time.text = Language[10570] .. TimeToDHMS(week_timeDown)
end, 1, -1, true)
self.timer:Start()
end
2024-09-20 11:45:46 +08:00
function DynamicTaskPage:OnShowData(isTop, isAni)
if allData then
endtime = ActivityGiftManager.GetTaskEndTime(ActivityTypeDef.DynamicAct)
this.SortData(allData)
2024-09-20 11:45:46 +08:00
this.ScrollView:SetData(allData, function(index, go)
this.SingleDataShow(go, allData[index])
if not singleTaskPre[go] then
singleTaskPre[go] = {}
end
2024-09-20 11:45:46 +08:00
singleTaskPre[go].com = Util.GetGameObject(go, "btn/Text")
singleTaskPre[go].data = allData[index]
2024-09-20 11:45:46 +08:00
end, not isTop, not isAni)
else
parent.OnPageTabChange(1)
2024-08-29 21:36:51 +08:00
PopupTipPanel.ShowTip(Language[10510])
return
end
end
2024-09-20 11:45:46 +08:00
local typeIndex = {
[0] = 1,
2024-09-20 11:45:46 +08:00
[1] = 0,
[2] = 2,
}
function DynamicTaskPage:SortData()
2024-09-20 11:45:46 +08:00
if allData == nil then
return
end
2024-09-20 11:45:46 +08:00
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
2024-09-20 11:45:46 +08:00
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] },
}
--刷新每一条的显示数据
2024-09-20 11:45:46 +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
2021-05-07 18:05:09 +08:00
local state = sConFigData.state
local titleText = Util.GetGameObject(activityRewardGo, "title"):GetComponent("Text")
2021-05-07 18:05:09 +08:00
if state == 2 or state == 1 then
2024-09-20 11:45:46 +08:00
titleText.text = GetLanguageStrById(sConFigData.title) ..
"(" .. sConFigData.value .. "/" .. sConFigData.value .. ")"
2021-05-07 18:05:09 +08:00
else
2024-09-20 11:45:46 +08:00
titleText.text = GetLanguageStrById(sConFigData.title) ..
"(" ..
(sConFigData.progress > sConFigData.value and sConFigData.value or sConFigData.progress) ..
"/" .. sConFigData.value .. ")"
2021-05-07 18:05:09 +08:00
end
2024-09-20 11:45:46 +08:00
local missionText = Util.GetGameObject(activityRewardGo, "mission"):GetComponent("Text")
2024-09-20 11:45:46 +08:00
missionText.text = GetLanguageStrById(sConFigData.content)
local timeText = Util.GetGameObject(activityRewardGo, "btn/Text")
local reward = Util.GetGameObject(activityRewardGo.gameObject, "reward")
2024-09-20 11:45:46 +08:00
if (not itemsGrid) then
itemsGrid = {}
end
if not itemsGrid[pre] then
2024-09-20 11:45:46 +08:00
itemsGrid[pre] = SubUIManager.Open(SubUIConfig.ItemView, reward.transform)
end
itemsGrid[pre]:OnOpen(false, sConFigData.reward, 0.9, false)
2024-09-20 11:45:46 +08:00
local lingquButton = Util.GetGameObject(activityRewardGo.gameObject, "btn")
--0-未完成1-完成未领取 2-已领取
2024-09-20 11:45:46 +08:00
timeText:SetActive(state == 0)
2024-09-20 11:45:46 +08:00
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
2021-04-21 13:12:04 +08:00
btn:GetComponent("Image").sprite = this.spLoader:LoadSprite(type[state].sprite)
btn:GetComponent("Button").enabled = state ~= 2
2024-09-20 11:45:46 +08:00
Util.SetGray(btn, state == 2)
Util.AddOnceClick(Util.GetGameObject(lingquButton.gameObject, "Button"), function()
if state == 1 then
2024-09-20 11:45:46 +08:00
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
2024-09-20 11:45:46 +08:00
end
end)
end
--界面打开时调用(用于子类重写)
function DynamicTaskPage:OnOpen()
end
function this.RechargeSuccessFunc(id)
FirstRechargeManager.RefreshAccumRechargeValue(id)
--OperatingManager.RefreshGiftGoodsBuyTimes(GoodsTypeDef.GiftBuy, id)
2024-09-20 11:45:46 +08:00
this.Refresh(false, false)
end
function DynamicTaskPage:OnClose()
end
--界面销毁时调用(用于子类重写)
function DynamicTaskPage:OnDestroy()
2021-04-21 13:12:04 +08:00
this.spLoader:Destroy()
if self.timer then
self.timer:Stop()
self.timer = nil
2024-09-20 11:45:46 +08:00
end
sortingOrder = 0
singleTaskPre = {}
itemsGrid = {}
end
function DynamicTaskPage:OnHide()
if self.timer then
self.timer:Stop()
self.timer = nil
2024-09-20 11:45:46 +08:00
end
end
2024-09-20 11:45:46 +08:00
--- 将一段时间转换为天时分秒
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
2024-09-20 11:45:46 +08:00
return string.format(Language[10571], minute, sec)
else
2024-09-20 11:45:46 +08:00
return string.format(Language[10572], day, hour)
end
end
2024-09-20 11:45:46 +08:00
return DynamicTaskPage