sk-client/Assets/ManagedResources/~Lua/Modules/FestivalActivity/Festival_Task.lua

123 lines
4.7 KiB
Lua

local Festival_Task = quick_class("Festival_Task")
local this = Festival_Task
local GlobalActConfig = ConfigManager.GetConfig(ConfigName.GlobalActivity)
local AcitvityShowTheme = ConfigManager.GetConfig(ConfigName.AcitvityShowTheme)
local itemList = {}
function Festival_Task:InitComponent(gameObject)
this.gameObject = gameObject
this.banner = Util.GetGameObject(gameObject, "banner"):GetComponent("Image")
this.time = Util.GetGameObject(gameObject, "time")
this.timeTxt = Util.GetGameObject(gameObject, "time/Text"):GetComponent("Text")
this.scroll = Util.GetGameObject(gameObject, "scroll")
this.pre = Util.GetGameObject(gameObject, "scroll/ItemPre")
local rootHight = this.scroll.transform.rect.height
local width = this.scroll.transform.rect.width
this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scroll.transform,
this.pre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 7))
this.ScrollView.moveTween.MomentumAmount = 1
this.ScrollView.moveTween.Strength = 2
end
--绑定事件(用于子类重写)
function this:BindEvent()
end
function this:AddListener()
Game.GlobalEvent:AddEvent(GameEvent.Activity.OnActivityProgressStateChange, this.OnShow)
Game.GlobalEvent:AddEvent(GameEvent.MissionDaily.OnMissionDailyChanged, this.OnShow)
end
function this:RemoveListener()
Game.GlobalEvent:RemoveEvent(GameEvent.Activity.OnActivityProgressStateChange, this.OnShow)
Game.GlobalEvent:RemoveEvent(GameEvent.MissionDaily.OnMissionDailyChanged, this.OnShow)
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function this:OnShow(parent)
CheckRedPointStatus(RedPointType.Festival_rpTask)
this.activityId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.Festival_Task)
local allData = ConfigManager.GetAllConfigsDataByKey(ConfigName.ThemeActivityTaskConfig, "ActivityId", this.activityId)
-- table.sort(allData, function (a, b)
-- return a.Sort < b.Sort
-- end)
table.insert(allData, {})
this.ScrollView:SetData(allData, function (index, go)
if index == #allData then
go:SetActive(false)
return
end
go:SetActive(true)
this.SingleDataShow(go, allData[index])
end)
-- local AllData = TaskManager.GetTypeTaskList(TaskTypeDef.Festival)
local info = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.Festival_Task)
CardActivityManager.TimeDown(this.timeTxt, info.endTime - GetTimeStamp())
local showArt = AcitvityShowTheme[GlobalActConfig[this.activityId].ShowArt]
this.banner.sprite = Util.LoadSprite(GetPictureFont(showArt.Compent))
end
--界面打开时调用(用于子类重写)
function this:OnOpen()
end
function this:OnClose()
CardActivityManager.StopTimeDown()
end
--界面销毁时调用(用于子类重写)
function this:OnDestroy()
itemList = {}
end
function this.SingleDataShow(go, configData)
local title = Util.GetGameObject(go, "title"):GetComponent("Text")
local reward = Util.GetGameObject(go, "reward")
local btn = Util.GetGameObject(go, "btn")
local btnTxt = Util.GetGameObject(go, "btn/Text"):GetComponent("Text")
local redPoint = Util.GetGameObject(go, "btn/redPoint")
local slider = Util.GetGameObject(go, "slider/Image"):GetComponent("Image")
title.text = GetLanguageStrById(configData.Show)
if not itemList[go] then
itemList[go] = {}
end
for i = 1, #itemList[go] do
itemList[go][i].gameObject:SetActive(false)
end
for i = 1, #configData.Integral do
if not itemList[go][i] then
itemList[go][i] = SubUIManager.Open(SubUIConfig.ItemView, reward.transform)
end
itemList[go][i]:OnOpen(false, configData.Integral[i], 0.65)
itemList[go][i].gameObject:SetActive(true)
end
local serverData = TaskManager.GetTypeTaskInfo(TaskTypeDef.Festival, configData.Id)
SetBtnReceiveState(serverData.state, btn, btnTxt)
redPoint:SetActive(serverData.state == 1)
if serverData.state ~= 0 then
slider.fillAmount = 1
else
slider.fillAmount = serverData.progress/configData.TaskValue[2][1]
end
Util.AddOnceClick(btn, function ()
if serverData.state == 1 then
NetManager.TakeMissionRewardRequest(TaskTypeDef.Festival, configData.Id, function(msg)
TaskManager.SetTypeTaskState(TaskTypeDef.Festival, configData.Id, 2)
UIManager.OpenPanel(UIName.RewardItemPopup, msg.drop, 1, function ()
this:OnShow()
end)
end)
elseif serverData.state == 0 then
JumpManager.GoJump(configData.Jump[1])
end
end)
end
return Festival_Task