154 lines
5.4 KiB
Lua
154 lines
5.4 KiB
Lua
local OnlineRewards = quick_class("OnlineRewards")
|
|
local itemList = {}
|
|
local hourTxt, minTxt, secTxt
|
|
local configData
|
|
local activityId
|
|
|
|
function OnlineRewards:ctor(mainPanel, gameObject)
|
|
self.mainPanel = mainPanel
|
|
self.gameObject = gameObject
|
|
self:InitComponent(gameObject)
|
|
self:BindEvent()
|
|
end
|
|
|
|
function OnlineRewards:InitComponent(gameObject)
|
|
self.time = Util.GetGameObject(gameObject, "time/Text"):GetComponent("Text")
|
|
self.scroll = Util.GetGameObject(gameObject, "scroll")
|
|
self.itemPre = Util.GetGameObject(gameObject, "ItemPre")
|
|
local rootHight = self.scroll.transform.rect.height
|
|
local width = self.scroll.transform.rect.width
|
|
self.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.scroll.transform,
|
|
self.itemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 0))
|
|
self.scrollView.moveTween.MomentumAmount = 1
|
|
self.scrollView.moveTween.Strength = 2
|
|
|
|
hourTxt = Util.GetGameObject(gameObject, "hour"):GetComponent("Text")
|
|
minTxt = Util.GetGameObject(gameObject, "min"):GetComponent("Text")
|
|
secTxt = Util.GetGameObject(gameObject, "sec"):GetComponent("Text")
|
|
|
|
self.btnBuy = Util.GetGameObject(gameObject, "btn")
|
|
end
|
|
|
|
function OnlineRewards:BindEvent()
|
|
Util.AddClick(self.btnBuy, function ()
|
|
JumpManager.GoJump(36011)
|
|
end)
|
|
end
|
|
|
|
function OnlineRewards:OnShow()
|
|
CheckRedPointStatus(RedPointType.OnlineReward)
|
|
self.gameObject:SetActive(true)
|
|
activityId = ActivityGiftManager.GetActivityIdByType(ActivityTypeDef.OnlineReward)
|
|
configData = ConfigManager.GetAllConfigsDataByKey(ConfigName.DailyOnlineTaskConfig, "ActivityId", activityId)
|
|
self.scrollView:SetData(configData, function(index, go)
|
|
self:RefreshShowData(go, configData[index])
|
|
end)
|
|
OnlineRewards:RemainTimeDown()
|
|
end
|
|
|
|
function OnlineRewards:OnHide()
|
|
self.gameObject:SetActive(false)
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
end
|
|
|
|
function OnlineRewards:OnDestroy()
|
|
itemList = {}
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
end
|
|
|
|
function OnlineRewards:OnSortingOrderChange(cursortingOrder)
|
|
end
|
|
|
|
function OnlineRewards:RefreshShowData(go, data)
|
|
local title = Util.GetGameObject(go, "title"):GetComponent("Text")
|
|
local grid = Util.GetGameObject(go, "scrollview/Viewport/grid")
|
|
local btn = Util.GetGameObject(go, "btn")
|
|
local btnTxt = Util.GetGameObject(go, "btn/Text"):GetComponent("Text")
|
|
local redPoint = Util.GetGameObject(go, "btn/redPoint")
|
|
local received = Util.GetGameObject(go, "received")
|
|
|
|
local severData = ActivityGiftManager.GetActivityInfo(activityId, data.Id)
|
|
received:SetActive(severData.state == -1)
|
|
btn:SetActive(severData.state ~= -1)
|
|
if severData.state == 0 then
|
|
btnTxt.text = GetLanguageStrById(10022)
|
|
elseif severData.state == 1 then
|
|
btnTxt.text = GetLanguageStrById(12356)
|
|
end
|
|
local privilegeState = true
|
|
for i = 1, #data.AgainPrivilegeID do
|
|
if not PrivilegeManager.GetPrivilegeOpenStatusById(data.AgainPrivilegeID[i]) then
|
|
privilegeState = false
|
|
end
|
|
end
|
|
|
|
redPoint:SetActive(ActivityGiftManager.onlineRewardTime >= data.TaskValue[2][1] and (severData.state == 0 or (severData.state == 1 and privilegeState)) and severData.state ~= -1)
|
|
|
|
title.text = GetLanguageStrById(data.Desc)
|
|
if not itemList[go] then
|
|
itemList[go] = {}
|
|
end
|
|
for i = 1, #itemList[go] do
|
|
itemList[go][i].gameObject:SetActive(false)
|
|
end
|
|
for i = 1, #data.Reward do
|
|
if not itemList[go][i] then
|
|
itemList[go][i] = SubUIManager.Open(SubUIConfig.ItemView, grid.transform)
|
|
end
|
|
itemList[go][i]:OnOpen(false, data.Reward[i], 0.65)
|
|
itemList[go][i].gameObject:SetActive(true)
|
|
end
|
|
Util.AddOnceClick(btn, function()
|
|
if ActivityGiftManager.onlineRewardTime >= data.TaskValue[2][1] and (severData.state == 0 or (severData.state == 1 and privilegeState)) and severData.state ~= -1 then
|
|
NetManager.GetActivityRewardRequest(data.Id, activityId, function (msg)
|
|
UIManager.OpenPanel(UIName.RewardItemPopup, msg, 1, function ()
|
|
table.remove(ActivityGiftManager.CanGetMissionIds, data.Id)
|
|
self:OnShow()
|
|
end)
|
|
end)
|
|
return
|
|
end
|
|
if severData.state == 1 then
|
|
MsgPanel.ShowTwo(GetLanguageStrById(50446), function() end, function()
|
|
JumpManager.GoJump(36011)
|
|
end, GetLanguageStrById(10719), GetLanguageStrById(10023), nil, false)
|
|
return
|
|
end
|
|
PopupTipPanel.ShowTipByLanguageId(10757)
|
|
end)
|
|
end
|
|
|
|
function OnlineRewards:RemainTimeDown()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
self.timer = Timer.New(function()
|
|
if NetManager.IsConnect() then
|
|
local hour, min, sec = OnlineRewards:GetTime(GetTimeStamp()-ActivityGiftManager.OnlineRewardCurTime)
|
|
hourTxt.text = hour
|
|
minTxt.text = min
|
|
secTxt.text = sec
|
|
end
|
|
end, 1, -1, true)
|
|
self.timer:Start()
|
|
end
|
|
|
|
function OnlineRewards:GetTime(t)
|
|
if not t or t < 0 then
|
|
return "00","00","00"
|
|
end
|
|
local sec = t % 60
|
|
local allMin = math.floor(t / 60)
|
|
local min = allMin % 60
|
|
local hour = math.floor(allMin / 60)
|
|
return string.format("%02d",hour), string.format("%02d",min), string.format("%02d", sec)
|
|
end
|
|
|
|
return OnlineRewards |