286 lines
9.2 KiB
Lua
286 lines
9.2 KiB
Lua
local LeiJiChongZhiPage = quick_class("LeiJiChongZhiPage")
|
|
local allData={}
|
|
local itemsGrid = {}--item重复利用
|
|
local moneyGrid = {}--moneyview重复利用
|
|
local this=LeiJiChongZhiPage
|
|
local parent
|
|
local endtime = 0
|
|
local rechargeNum
|
|
local curtype = 0
|
|
function LeiJiChongZhiPage:ctor(mainPanel, gameObject)
|
|
self.mainPanel = mainPanel
|
|
self.gameObject = gameObject
|
|
self:InitComponent(gameObject)
|
|
self:BindEvent()
|
|
end
|
|
|
|
function LeiJiChongZhiPage:InitComponent(gameObject)
|
|
this.spLoader = SpriteLoader.New()
|
|
this.time = Util.GetGameObject(gameObject, "tiao/time"):GetComponent("Text")
|
|
this.text1 = Util.GetGameObject(gameObject, "bg1/Text"):GetComponent("Text")
|
|
this.text2 = Util.GetGameObject(gameObject, "bg1/Text2"):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
|
|
end
|
|
|
|
--绑定事件(用于子类重写)
|
|
function LeiJiChongZhiPage:BindEvent()
|
|
end
|
|
|
|
--添加事件监听(用于子类重写)
|
|
function LeiJiChongZhiPage:AddListener()
|
|
|
|
end
|
|
|
|
--移除事件监听(用于子类重写)
|
|
function LeiJiChongZhiPage:RemoveListener()
|
|
|
|
end
|
|
local sortingOrder = 0
|
|
--界面打开时调用(用于子类重写)
|
|
function LeiJiChongZhiPage:OnOpen()
|
|
|
|
end
|
|
|
|
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
|
|
function LeiJiChongZhiPage:OnShow(_sortingOrder,_parent,_type)
|
|
curtype = _type
|
|
rechargeNum= VipManager.GetChargedNum()--已经充值的金额
|
|
sortingOrder = _sortingOrder
|
|
parent = _parent
|
|
this.Refresh(true,true)
|
|
end
|
|
|
|
function this.Refresh(isTop,isAni)
|
|
this:OnShowData(isTop,isAni)
|
|
this:SetTime()
|
|
end
|
|
|
|
function LeiJiChongZhiPage:SetTime()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
local timeDown = endtime
|
|
if timeDown < 0 then
|
|
return
|
|
end
|
|
this.time.text = Language[10023]..TimeToDHMS(timeDown)
|
|
self.timer = Timer.New(function()
|
|
timeDown = timeDown - 1
|
|
if timeDown < 1 then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
this.time.text = Language[10023]..TimeToDHMS(0)
|
|
this.Refresh(true,true)
|
|
return
|
|
end
|
|
this.time.text = Language[10023]..TimeToDHMS(timeDown)
|
|
end, 1, -1, true)
|
|
self.timer:Start()
|
|
end
|
|
|
|
function LeiJiChongZhiPage:OnShowData(isTop,isAni)
|
|
allData =OperatingManager.InitLeiJiChongZhiData(curtype)
|
|
if allData then
|
|
if curtype == ActivityTypeDef.AccumulativeRechargeExper then
|
|
endtime = CalculateSecondsNowTo_N_OClock(0)
|
|
this.text1.text = Language[10474]
|
|
this.text2.text = Language[10475]
|
|
else
|
|
endtime = ActivityGiftManager.GetTaskEndTime(curtype) - GetTimeStamp()
|
|
this.text1.text = Language[10476]
|
|
this.text2.text = Language[10475]
|
|
end
|
|
|
|
this.SortData(allData)
|
|
this.ScrollView:SetData(allData, function (index, go)
|
|
this.SingleDataShow(go, allData[index])
|
|
end,not isTop,not isAni)
|
|
else
|
|
parent.OnPageTabChange(1)
|
|
PopupTipPanel.ShowTip(Language[10471])
|
|
return
|
|
end
|
|
|
|
end
|
|
local typeIndex = {
|
|
[0] = 2,
|
|
[1] = 3,
|
|
[2] = 1,
|
|
}
|
|
function LeiJiChongZhiPage:SortData()
|
|
if allData==nil then
|
|
return
|
|
end
|
|
table.sort(allData, function(a,b)
|
|
if typeIndex[a.state] == typeIndex[b.state] then
|
|
return a.id < b.id
|
|
else
|
|
return typeIndex[a.state] < typeIndex[b.state]
|
|
end
|
|
end)
|
|
end
|
|
local type={
|
|
[0]={sprite = "Btn_hz_cheng_01",text = Language[10019]},
|
|
[1]={sprite = "Btn_hz_lan_01",text = Language[10101]},
|
|
[2]={sprite = "Btn_hz_cheng_01",text = Language[10018]},
|
|
}
|
|
--刷新每一条的显示数据
|
|
function this.SingleDataShow(pre,value)
|
|
if pre==nil or value==nil then
|
|
return
|
|
end
|
|
--绑定组件
|
|
local activityRewardGo = pre
|
|
activityRewardGo:SetActive(true)
|
|
local sConFigData = value
|
|
Util.GetGameObject(pre, "context/NumTextPre").gameObject:SetActive(false)
|
|
Util.GetGameObject(pre, "context/price").gameObject:SetActive(false)
|
|
-- local numTextPre = Util.GetGameObject(pre, "context/NumTextPre")
|
|
-- local numList = {}
|
|
-- for i = 1, numTextPre.transform.childCount do
|
|
-- table.insert(numList,numTextPre.transform:GetChild(i-1):GetComponent("Text"))
|
|
-- end
|
|
-- CreatNumberPrefab(tostring(sConFigData.value),numList)
|
|
if not moneyGrid[pre] then
|
|
moneyGrid[pre] = SubUIManager.Open(SubUIConfig.MoneyNumView, Util.GetGameObject(pre, "context").transform,
|
|
sConFigData.value, MoneyNumViewType.Image_Horizontal, "ArtFont_1_cfont", 42, 1, Vector2.New(46, 46), Vector2.New(0, -25), MoneyNumViewImageType.Small_1)
|
|
end
|
|
moneyGrid[pre]:SetNum(sConFigData.value)
|
|
moneyGrid[pre]:SetOffsetPosition(Vector2.New(0, 0))
|
|
moneyGrid[pre]:SetOffsetRotation(Vector3.New(0, 0, 0))
|
|
moneyGrid[pre].transform:SetSiblingIndex(2)
|
|
-- num.text = sConFigData.value
|
|
-- this:NumToNum(num, sConFigData.value)
|
|
-- num.text = sConFigData.value
|
|
local progress = Util.GetGameObject(activityRewardGo, "context/progress"):GetComponent("Text")
|
|
progress.text =Language[10477].."("..(sConFigData.progress > sConFigData.value and sConFigData.value or sConFigData.progress) .."/"..sConFigData.value..")"
|
|
|
|
local reward = Util.GetGameObject(activityRewardGo.gameObject, "scrollView/grid")
|
|
if (not itemsGrid) then
|
|
itemsGrid = {}
|
|
end
|
|
if not itemsGrid[pre] then
|
|
itemsGrid[pre] = {}
|
|
end
|
|
for _, item in pairs(itemsGrid[pre]) do
|
|
item.gameObject:SetActive(false)
|
|
end
|
|
for k,v in ipairs(sConFigData.reward) do
|
|
if not itemsGrid[pre][k] then
|
|
itemsGrid[pre][k] = SubUIManager.Open(SubUIConfig.ItemView,reward.transform)
|
|
end
|
|
itemsGrid[pre][k]:OnOpen(false, {v[1],v[2]}, 0.9, false)
|
|
itemsGrid[pre][k].gameObject:SetActive(true)
|
|
end
|
|
|
|
local lingquButton = Util.GetGameObject(activityRewardGo.gameObject, "btnBuy")
|
|
local state = sConFigData.state
|
|
local red = Util.GetGameObject(lingquButton.gameObject, "redPoint")
|
|
red:SetActive(state == 2)
|
|
|
|
Util.GetGameObject(lingquButton.gameObject, "price"):GetComponent("Text").text = type[state].text
|
|
lingquButton:GetComponent("Image").sprite = this.spLoader:LoadSprite(type[state].sprite)
|
|
lingquButton:GetComponent("Button").enabled = (state ~= 1)
|
|
Util.SetGray(lingquButton,state == 1)
|
|
|
|
--强制刷新大小
|
|
ForceRebuildLayout(Util.GetGameObject(pre, "context").transform)
|
|
|
|
Util.AddOnceClick(lingquButton, function()
|
|
if state == 2 then
|
|
local curActivityId = ActivityGiftManager.GetActivityIdByType(curtype)
|
|
NetManager.GetActivityRewardRequest(sConFigData.id, curActivityId,function(drop)
|
|
UIManager.OpenPanel(UIName.RewardItemPopup, drop, 1)
|
|
this.Refresh(false,false)
|
|
end)
|
|
elseif state == 0 then
|
|
if sConFigData.jump then
|
|
JumpManager.GoJump(sConFigData.jump)
|
|
end
|
|
end
|
|
end)
|
|
|
|
end
|
|
|
|
function LeiJiChongZhiPage:NumToNum(num,_value)
|
|
local value = _value
|
|
local isFirst = true
|
|
for i = 1, 5 do
|
|
local m = Util.GetGameObject(num,"num"..i)
|
|
m:SetActive(false)
|
|
local t1 = math.floor(value/math.pow(10, (5-i)))
|
|
value = value%(math.pow(10, (5-i)))
|
|
if t1<1 and isFirst then
|
|
m:SetActive(false)
|
|
else
|
|
m:SetActive(true)
|
|
isFirst = false
|
|
m:GetComponent("Text").text = t1
|
|
end
|
|
|
|
end
|
|
end
|
|
|
|
--界面打开时调用(用于子类重写)
|
|
function LeiJiChongZhiPage:OnOpen()
|
|
|
|
end
|
|
|
|
function this.RechargeSuccessFunc(id)
|
|
|
|
end
|
|
|
|
function LeiJiChongZhiPage:OnClose()
|
|
|
|
end
|
|
|
|
--界面销毁时调用(用于子类重写)
|
|
function LeiJiChongZhiPage:OnDestroy()
|
|
this.spLoader:Destroy()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
sortingOrder = 0
|
|
allData={}
|
|
itemsGrid = {}
|
|
if moneyGrid and LengthOfTable(moneyGrid) > 0 then
|
|
for key, value in pairs(moneyGrid) do
|
|
if value then
|
|
SubUIManager.Close(value)
|
|
value = nil
|
|
end
|
|
end
|
|
moneyGrid = {}
|
|
end
|
|
end
|
|
|
|
function LeiJiChongZhiPage:OnHide()
|
|
if self.timer then
|
|
self.timer:Stop()
|
|
self.timer = nil
|
|
end
|
|
sortingOrder = 0
|
|
end
|
|
--- 将一段时间转换为天时分秒
|
|
function LeiJiChongZhiPage: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[10472],minute, sec)
|
|
else
|
|
return string.format(Language[10473],day, hour)
|
|
end
|
|
end
|
|
|
|
return LeiJiChongZhiPage |