235 lines
8.5 KiB
Lua
235 lines
8.5 KiB
Lua
---- 百宝商会活动弹窗 ----
|
||
require("Base/BasePanel")
|
||
local TreasureStorePopup = Inherit(BasePanel)
|
||
local this=TreasureStorePopup
|
||
local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig)
|
||
local GlobalActivity = ConfigManager.GetConfig(ConfigName.GlobalActivity)
|
||
local itemsGrid = {}
|
||
local isPlayAnim = true
|
||
local rechargeId = 0
|
||
function TreasureStorePopup:InitComponent()
|
||
this.spLoader = SpriteLoader.New()
|
||
this.panel=Util.GetGameObject(this.gameObject,"Panel")
|
||
this.backBtn=Util.GetGameObject(this.panel,"BackBtn")
|
||
this.time=Util.GetGameObject(this.panel,"Time"):GetComponent("Text")
|
||
this.oneKeyBtn=Util.GetGameObject(this.panel,"oneKeyBtn")
|
||
this.oneKeyBtn:SetActive(false)
|
||
-- this.oneKeyBtnButton=Util.GetGameObject(this.panel,"oneKeyBtn"):GetComponent("Button")
|
||
this.scroll=Util.GetGameObject(this.panel,"Scroll")
|
||
this.scrollPre=Util.GetGameObject(this.scroll,"Pre")
|
||
this.scrollView=SubUIManager.Open(SubUIConfig.ScrollCycleView,this.scroll.transform,this.scrollPre, nil,
|
||
Vector2.New(this.scroll.transform.rect.width,this.scroll.transform.rect.height),2,1,Vector2.New(10,0))
|
||
this.scrollView.gameObject:GetComponent("RectTransform").anchoredPosition= Vector2.New(0,0)
|
||
this.scrollView.gameObject:GetComponent("RectTransform").anchorMin = Vector2.New(0.5, 0.5)
|
||
this.scrollView.gameObject:GetComponent("RectTransform").anchorMax = Vector2.New(0.5, 0.5)
|
||
this.scrollView.gameObject:GetComponent("RectTransform").pivot = Vector2.New(0.5, 0.5)
|
||
this.scrollView.moveTween.MomentumAmount = 1
|
||
this.scrollView.moveTween.Strength = 2
|
||
end
|
||
|
||
function TreasureStorePopup:BindEvent()
|
||
Util.AddClick(this.backBtn,function()
|
||
self:ClosePanel()
|
||
end)
|
||
-- Util.AddClick(this.oneKeyBtn,function()
|
||
-- LogGreen("rechargeId:"..rechargeId)
|
||
-- PayManager.Pay(rechargeId, function(id)
|
||
-- this.RechargeSuccessFunc(id)
|
||
-- end)
|
||
-- end)
|
||
end
|
||
|
||
function TreasureStorePopup:AddListener()
|
||
end
|
||
|
||
function TreasureStorePopup:RemoveListener()
|
||
end
|
||
|
||
function TreasureStorePopup:OnOpen(...)
|
||
|
||
end
|
||
|
||
function TreasureStorePopup:OnShow()
|
||
this:RefreshPanel(true)
|
||
this:TimeCountDown()
|
||
isPlayAnim = true
|
||
end
|
||
|
||
function TreasureStorePopup:OnClose()
|
||
if this.timer then
|
||
this.timer:Stop()
|
||
this.timer = nil
|
||
end
|
||
end
|
||
|
||
function TreasureStorePopup:OnDestroy()
|
||
this.spLoader:Destroy()
|
||
if this.timer then
|
||
this.timer:Stop()
|
||
this.timer = nil
|
||
end
|
||
this.scrollView=nil
|
||
itemsGrid = nil
|
||
end
|
||
|
||
-- function TreasureStorePopup:RefreshOneKeyBuy(allData)
|
||
-- this.oneKeyBtnButton.enabled = true
|
||
-- Util.SetGray(this.oneKeyBtn,false)
|
||
-- for i = 1, #allData do
|
||
-- local boughtNum = OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, allData[i].Id) or 0
|
||
-- if allData[i].Limit - boughtNum < 1 then
|
||
-- this.oneKeyBtnButton.enabled = false
|
||
-- Util.SetGray(this.oneKeyBtn,true)
|
||
-- return
|
||
-- end
|
||
-- end
|
||
-- end
|
||
--刷新面板
|
||
function TreasureStorePopup:RefreshPanel(isAni)
|
||
local allData = {}
|
||
local curActId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.TreasureStore)
|
||
LogGreen("curActId:"..curActId)
|
||
if not curActId then
|
||
return
|
||
end
|
||
rechargeId = tonumber(GlobalActivity[curActId].ShowArt)
|
||
local data = GlobalActivity[curActId].CanBuyRechargeId
|
||
for i = 1, #data do
|
||
local data = ConfigManager.GetConfigDataByKey(ConfigName.RechargeCommodityConfig, "Id", data[i])
|
||
table.insert(allData,data)
|
||
end
|
||
-- self:RefreshOneKeyBuy(allData)
|
||
if allData then
|
||
allData = this.SortData(allData)
|
||
this.scrollView:SetData(allData, function (index, go)
|
||
this:SetScrollPre(go, allData[index])
|
||
end,false,not isAni)
|
||
end
|
||
-- if isPlayAnim then
|
||
-- SecTorPlayAnimByScroll(this.scrollView)
|
||
-- isPlayAnim = false
|
||
-- end
|
||
-- this.scrollView:SetIndex(1)
|
||
|
||
end
|
||
function this.SortData(allData)
|
||
if allData==nil then
|
||
return
|
||
end
|
||
table.sort(allData, function(a,b)
|
||
-- local aboughtNum = a.Limit - OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, a.Id) > 0 and 2 or 1
|
||
-- local bboughtNum = b.Limit - OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, b.Id) > 0 and 2 or 1
|
||
-- if aboughtNum == bboughtNum then
|
||
return a.Id < b.Id
|
||
-- else
|
||
-- return aboughtNum > bboughtNum
|
||
-- end
|
||
end)
|
||
return allData
|
||
end
|
||
--设置每一条
|
||
function this:SetScrollPre(root,data)
|
||
-- if isPlayAnim then
|
||
-- root.gameObject:SetActive(false)
|
||
-- else
|
||
-- root.gameObject:SetActive(true)
|
||
-- end
|
||
local title=Util.GetGameObject(root,"Title"):GetComponent("Text")
|
||
local iRoot=Util.GetGameObject(root,"ItemRoot")
|
||
local buyBtn=Util.GetGameObject(root,"BuyBtn")
|
||
local buyNum=Util.GetGameObject(root,"BuyBtn/BuyNum"):GetComponent("Text")
|
||
local tip=Util.GetGameObject(root,"TipDi/Tip"):GetComponent("Text")
|
||
--ocal item = Util.GetGameObject(iRoot,"Tip"):GetComponent("Text")
|
||
local itemList = {}
|
||
for i = 1,iRoot.transform.childCount do
|
||
itemList[i] = {}
|
||
itemList[i].go = Util.GetGameObject(iRoot,"item"..i)
|
||
itemList[i].icon = Util.GetGameObject(itemList[i].go,"icon"):GetComponent("Image")
|
||
itemList[i].Name = Util.GetGameObject(itemList[i].go,"Name"):GetComponent("Text")
|
||
end
|
||
local config = ConfigManager.GetConfigData(ConfigName.RechargeCommodityConfig,data.Id)
|
||
title.text = string.format("价值%s现仅需%s",MoneyUtil.GetMoneyUnitNameWithMoney(config.Rebate),MoneyUtil.GetMoneyUnitNameWithMoney(config.Price))
|
||
local rewardArray = data.RewardShow
|
||
if not itemsGrid then
|
||
itemsGrid = {}
|
||
end
|
||
|
||
-- --滚动条复用重设itemview
|
||
-- if not itemsGrid[root] then
|
||
-- itemsGrid[root] = {}
|
||
-- end
|
||
-- for i = 1, #itemsGrid[root] do
|
||
-- itemsGrid[root][i].gameObject:SetActive(false)
|
||
-- end
|
||
-- for i = 1, #rewardArray do
|
||
-- if not itemsGrid[root][i] then
|
||
-- itemsGrid[root][i] = SubUIManager.Open(SubUIConfig.ItemView, iRoot.transform)
|
||
-- end
|
||
-- itemsGrid[root][i]:OnOpen(false, {rewardArray[i][1],rewardArray[i][2]}, 0.7)
|
||
-- itemsGrid[root][i].gameObject:SetActive(true)
|
||
-- end
|
||
|
||
for i = 1 , math.max(#rewardArray,#itemList) do
|
||
if not rewardArray[i] then
|
||
itemList[i].go.gameObject:SetActive(false)
|
||
elseif not itemList[i] then
|
||
break
|
||
else
|
||
itemList[i].go.gameObject:SetActive(true)
|
||
itemList[i].icon.sprite = Util.LoadSprite(GetSpriteNameByItemId(rewardArray[i][1]))
|
||
itemList[i].Name.text = ConfigManager.GetConfigData(ConfigName.ItemConfig, rewardArray[i][1]).Name .."\n×" .. rewardArray[i][2]
|
||
end
|
||
end
|
||
|
||
local boughtNum = OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, data.Id) or 0
|
||
tip.text =Language[10580].. (data.Limit-boughtNum) ..Language[10048]
|
||
buyNum.text =string.format(MoneyUtil.GetMoneyUnitName(), MoneyUtil.GetMoney(data.Price))--shopItemData.Price..MoneyUtil.GetMoneyUnitName()
|
||
if data.Limit - boughtNum > 0 then
|
||
buyBtn:GetComponent("Button").enabled = true
|
||
Util.SetGray(buyBtn, false)
|
||
else
|
||
buyBtn:GetComponent("Button").enabled = false
|
||
Util.SetGray(buyBtn, true)
|
||
end
|
||
Util.AddOnceClick(buyBtn, function()
|
||
if data.Limit <= boughtNum then
|
||
PopupTipPanel.ShowTip(Language[10515])
|
||
else
|
||
--直购商品
|
||
PayManager.Pay(data.Id, function(id)
|
||
this.RechargeSuccessFunc(id)
|
||
end)
|
||
end
|
||
end)
|
||
end
|
||
|
||
function this.RechargeSuccessFunc(id)
|
||
FirstRechargeManager.RefreshAccumRechargeValue(id)
|
||
this:RefreshPanel()
|
||
end
|
||
|
||
--倒计时
|
||
function this.TimeCountDown()
|
||
if this.timer then
|
||
this.timer:Stop()
|
||
this.timer = nil
|
||
end
|
||
local endtime = ActivityGiftManager.GetTaskEndTime(ActivityTypeDef.TreasureStore)
|
||
local timeDown = endtime - GetTimeStamp()
|
||
this.time.text = Language[10023]..TimeToHMS(timeDown)
|
||
this.timer = Timer.New(function()
|
||
if timeDown <= 0 then
|
||
this.timer:Stop()
|
||
this.timer = nil
|
||
this.timer = Timer.New(function()
|
||
this:RefreshPanel(false)
|
||
this:TimeCountDown()
|
||
end,1):Start()
|
||
return
|
||
end
|
||
timeDown = timeDown - 1
|
||
this.time.text = Language[10023]..TimeToHMS(timeDown)
|
||
end, 1, -1, true)
|
||
this.timer:Start()
|
||
end
|
||
return TreasureStorePopup |