miduo_client/Assets/ManagedResources/~Lua/Modules/TreasureStore/TreasureStorePopup.lua

193 lines
6.4 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
function TreasureStorePopup:InitComponent()
this.panel=Util.GetGameObject(this.gameObject,"Panel")
this.backBtn=Util.GetGameObject(this.panel,"BackBtn")
this.time=Util.GetGameObject(this.panel,"Time"):GetComponent("Text")
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),1,1,Vector2.New(0,10))
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)
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()
if this.timer then
this.timer:Stop()
this.timer = nil
end
this.scrollView=nil
itemsGrid = nil
end
--刷新面板
function TreasureStorePopup:RefreshPanel(isAni)
local allData = {}
local curActId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.TreasureStore)
if not curActId then
return
end
local data = GlobalActivity[curActId].CanBuyRechargeId
for i = 1, #data do
local data = ConfigManager.GetConfigDataByKey(ConfigName.RechargeCommodityConfig, "Id", data[i])
table.insert(allData,data)
end
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,"Tip"):GetComponent("Text")
title.text = data.Name
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
local boughtNum = OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, data.Id) or 0
if data.Limit - boughtNum > 0 then
buyNum.text = string.format(MoneyUtil.GetMoneyUnitName(), MoneyUtil.GetMoney(data.Price))--shopItemData.Price..MoneyUtil.GetMoneyUnitName()
buyBtn:GetComponent("Button").enabled = true
Util.SetGray(buyBtn, false)
tip.text =Language[10535].. (data.Limit-boughtNum) ..Language[10054]
else
buyNum.text = Language[10526]
buyBtn:GetComponent("Button").enabled = false
Util.SetGray(buyBtn, true)
tip.text = ""
end
--local costId, finalNum, oriCostNum = ShopManager.calculateBuyCost(SHOP_TYPE.FINDTREASURE_GIFT, data.id, 1)
Util.AddOnceClick(buyBtn, function()
if data.Limit <= boughtNum then
PopupTipPanel.ShowTip(Language[10540])
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[10028]..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[10028]..TimeToHMS(timeDown)
end, 1, -1, true)
this.timer:Start()
end
return TreasureStorePopup