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

295 lines
11 KiB
Lua
Raw Normal View History

2021-04-21 13:12:04 +08:00
---- 百宝商会活动弹窗 ----
2020-05-09 13:31:21 +08:00
require("Base/BasePanel")
local TreasureStorePopup = Inherit(BasePanel)
local this=TreasureStorePopup
local itemConfig=ConfigManager.GetConfig(ConfigName.ItemConfig)
2020-09-27 16:52:40 +08:00
local GlobalActivity = ConfigManager.GetConfig(ConfigName.GlobalActivity)
local itemsGrid = {}
local isPlayAnim = true
local rechargeId = 0
2021-06-02 15:42:46 +08:00
local effectList = {}
local orginLayer = 0
2020-05-09 13:31:21 +08:00
function TreasureStorePopup:InitComponent()
2021-04-21 13:12:04 +08:00
this.spLoader = SpriteLoader.New()
2020-05-09 13:31:21 +08:00
this.panel=Util.GetGameObject(this.gameObject,"Panel")
this.backBtn=Util.GetGameObject(this.panel,"BackBtn")
2020-09-27 16:52:40 +08:00
this.time=Util.GetGameObject(this.panel,"Time"):GetComponent("Text")
this.oneKeyBtn=Util.GetGameObject(this.panel,"oneKeyBtn")
2021-05-27 16:43:59 +08:00
this.oneKeyBtn:SetActive(false)
-- this.oneKeyBtnButton=Util.GetGameObject(this.panel,"oneKeyBtn"):GetComponent("Button")
2020-05-09 13:31:21 +08:00
this.scroll=Util.GetGameObject(this.panel,"Scroll")
this.scrollPre=Util.GetGameObject(this.scroll,"Pre")
2020-09-27 16:52:40 +08:00
this.scrollView=SubUIManager.Open(SubUIConfig.ScrollCycleView,this.scroll.transform,this.scrollPre, nil,
2021-05-28 18:53:54 +08:00
Vector2.New(this.scroll.transform.rect.width,this.scroll.transform.rect.height),2,1,Vector2.New(10,0))
2020-05-09 13:31:21 +08:00
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
2021-06-02 15:42:46 +08:00
effectList = {}
for i = 1, 4 do
table.insert(effectList,Util.GetGameObject(this.panel,"Fx_Flower"..i))
end
table.insert(effectList,Util.GetGameObject(this.panel,"Fx_moon"))
this.Fx_Ripple = Util.GetGameObject(this.panel,"Fx_Ripple")
table.insert(effectList,this.Fx_Ripple)
this.lianyiBtn = Util.GetGameObject(this.panel,"lianyiBtn")
2020-05-09 13:31:21 +08:00
end
function TreasureStorePopup:BindEvent()
Util.AddClick(this.backBtn,function()
self:ClosePanel()
end)
2021-06-02 15:42:46 +08:00
Util.AddClick(this.lianyiBtn,function()
LogGreen(Input.mousePosition.x.."|"..Input.mousePosition.y)
if not this.rippleList then
this.rippleList = {}
end
local rip = nil
for i = 1,#this.rippleList do
if this.rippleList[i] and not this.rippleList[i].activeSelf then
rip = this.rippleList[i]
break
end
end
if not rip then
rip = newObjToParent(this.Fx_Ripple,this.panel)
table.insert(this.rippleList,rip)
end
local uisize = Vector3.New(UIManager.realWidth, UIManager.realHeigt,0)
local screenpos = Input.mousePosition
local screenpos2 = Vector3.zero
screenpos2.x = screenpos.x - (UIManager.width / 2) --//转换为以屏幕中心为原点的屏幕坐标
screenpos2.y = screenpos.y - (UIManager.height / 2)
local uipos = Vector3.zero
uipos.x = screenpos2.x* (uisize.x / UIManager.width) --转换后的屏幕坐标*画布与屏幕宽高比
uipos.y = screenpos2.y * ( uisize.y / UIManager.height)
uipos.z = -50
LogGreen(uipos.x.."|"..uipos.y)
rip:GetComponent("RectTransform").anchoredPosition3D = uipos
rip.gameObject:SetActive(true)
Timer.New(function()
rip.gameObject:SetActive(false)
end,1,1,false):Start()
end)
2021-05-27 16:43:59 +08:00
-- Util.AddClick(this.oneKeyBtn,function()
-- LogGreen("rechargeId:"..rechargeId)
-- PayManager.Pay(rechargeId, function(id)
-- this.RechargeSuccessFunc(id)
-- end)
-- end)
2020-05-09 13:31:21 +08:00
end
function TreasureStorePopup:AddListener()
end
function TreasureStorePopup:RemoveListener()
end
function TreasureStorePopup:OnOpen(...)
end
2021-06-02 15:42:46 +08:00
function TreasureStorePopup:OnSortingOrderChange()
for i = 1,#effectList do
2021-06-03 10:38:37 +08:00
Util.SetParticleSortLayer(effectList[i], self.sortingOrder + 1)
2021-06-02 15:42:46 +08:00
end
2021-06-03 10:38:37 +08:00
this.scrollView:ForeachItemGO(function(index,go)
Util.SetParticleSortLayer(Util.GetGameObject(go,"Fx_Circle"), self.sortingOrder + 1)
end)
2021-06-02 15:42:46 +08:00
orginLayer = self.sortingOrder
end
2020-05-09 13:31:21 +08:00
function TreasureStorePopup:OnShow()
2021-02-26 17:26:45 +08:00
this:RefreshPanel(true)
2020-09-27 16:52:40 +08:00
this:TimeCountDown()
isPlayAnim = true
2020-05-09 13:31:21 +08:00
end
function TreasureStorePopup:OnClose()
if this.timer then
this.timer:Stop()
this.timer = nil
end
end
function TreasureStorePopup:OnDestroy()
2021-04-21 13:12:04 +08:00
this.spLoader:Destroy()
2020-09-27 16:52:40 +08:00
if this.timer then
this.timer:Stop()
this.timer = nil
end
2020-05-09 13:31:21 +08:00
this.scrollView=nil
2020-09-27 16:52:40 +08:00
itemsGrid = nil
2020-05-09 13:31:21 +08:00
end
2021-05-27 16:43:59 +08:00
-- 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
2020-05-09 13:31:21 +08:00
--刷新面板
2021-02-26 17:26:45 +08:00
function TreasureStorePopup:RefreshPanel(isAni)
2020-09-27 16:52:40 +08:00
local allData = {}
local curActId = ActivityGiftManager.IsActivityTypeOpen(ActivityTypeDef.TreasureStore)
LogGreen("curActId:"..curActId)
2020-09-27 16:52:40 +08:00
if not curActId then
2021-05-29 21:31:01 +08:00
self:ClosePanel()
2020-09-27 16:52:40 +08:00
return
end
rechargeId = tonumber(GlobalActivity[curActId].ShowArt)
2020-09-27 16:52:40 +08:00
local data = GlobalActivity[curActId].CanBuyRechargeId
for i = 1, #data do
local data = ConfigManager.GetConfigDataByKey(ConfigName.RechargeCommodityConfig, "Id", data[i])
table.insert(allData,data)
end
2021-05-27 16:43:59 +08:00
-- self:RefreshOneKeyBuy(allData)
2020-09-27 16:52:40 +08:00
if allData then
allData = this.SortData(allData)
this.scrollView:SetData(allData, function (index, go)
this:SetScrollPre(go, allData[index])
2021-02-26 17:26:45 +08:00
end,false,not isAni)
2020-09-27 16:52:40 +08:00
end
-- if isPlayAnim then
-- SecTorPlayAnimByScroll(this.scrollView)
-- isPlayAnim = false
-- end
2021-02-26 17:26:45 +08:00
-- this.scrollView:SetIndex(1)
2020-05-09 13:31:21 +08:00
2020-09-27 16:52:40 +08:00
end
function this.SortData(allData)
if allData==nil then
return
end
table.sort(allData, function(a,b)
2021-07-07 11:44:40 +08:00
return a.Sequence < b.Sequence
2020-09-27 16:52:40 +08:00
end)
return allData
end
2020-05-09 13:31:21 +08:00
--设置每一条
2020-09-27 16:52:40 +08:00
function this:SetScrollPre(root,data)
-- if isPlayAnim then
-- root.gameObject:SetActive(false)
-- else
-- root.gameObject:SetActive(true)
-- end
2020-05-09 13:31:21 +08:00
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")
2021-05-28 18:53:54 +08:00
local tip=Util.GetGameObject(root,"TipDi/Tip"):GetComponent("Text")
2021-06-02 15:42:46 +08:00
local effect = Util.GetGameObject(root,"Fx_Circle")
2021-05-28 18:53:54 +08:00
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)
2021-07-07 11:28:50 +08:00
title.text = string.format("\n\n%s\n\n\n\n%s",MoneyUtil.GetMoneyUnitNameWithMoney1(config.Rebate),MoneyUtil.GetMoneyUnitNameWithMoney1(config.Price))
2020-09-27 16:52:40 +08:00
local rewardArray = data.RewardShow
if not itemsGrid then
itemsGrid = {}
end
2021-05-28 18:53:54 +08:00
-- --滚动条复用重设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)
2021-08-27 18:39:45 +08:00
itemList[i].icon.sprite = this.spLoader:LoadSprite(GetSpriteNameByItemId(rewardArray[i][1]))
2021-05-29 18:52:42 +08:00
itemList[i].Name.text = ConfigManager.GetConfigData(ConfigName.ItemConfig, rewardArray[i][1]).Name .."×" .. rewardArray[i][2]
2021-06-01 14:49:51 +08:00
Util.AddOnceClick(itemList[i].go, function()
UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, rewardArray[i][1], function()
UIManager.ClosePanel(UIName.RewardItemSingleShowPopup)
end)
end)
2020-09-27 16:52:40 +08:00
end
end
local boughtNum = OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, data.Id) or 0
2021-07-07 11:44:40 +08:00
LogGreen("boughtNum:"..boughtNum)
2021-05-29 18:36:27 +08:00
tip.text =Language[10580].. (data.Limit-boughtNum) ..Language[10048]
buyNum.text =string.format(MoneyUtil.GetMoneyUnitName(), MoneyUtil.GetMoney(data.Price))--shopItemData.Price..MoneyUtil.GetMoneyUnitName()
2020-09-27 16:52:40 +08:00
if data.Limit - boughtNum > 0 then
buyBtn:GetComponent("Button").enabled = true
Util.SetGray(buyBtn, false)
2021-06-02 15:42:46 +08:00
effect.gameObject:SetActive(true)
2021-05-29 18:36:27 +08:00
else
2020-09-27 16:52:40 +08:00
buyBtn:GetComponent("Button").enabled = false
Util.SetGray(buyBtn, true)
2021-06-02 15:42:46 +08:00
effect.gameObject:SetActive(false)
2020-09-27 16:52:40 +08:00
end
Util.AddOnceClick(buyBtn, function()
if data.Limit <= boughtNum then
2021-03-02 16:53:12 +08:00
PopupTipPanel.ShowTip(Language[10515])
2020-09-27 16:52:40 +08:00
else
--直购商品
PayManager.Pay(data.Id, function(id)
this.RechargeSuccessFunc(id)
end)
end
end)
2021-06-01 14:49:51 +08:00
2020-05-09 13:31:21 +08:00
end
2020-09-27 16:52:40 +08:00
function this.RechargeSuccessFunc(id)
FirstRechargeManager.RefreshAccumRechargeValue(id)
this:RefreshPanel()
end
2020-05-09 13:31:21 +08:00
--倒计时
2020-09-27 16:52:40 +08:00
function this.TimeCountDown()
2020-05-09 13:31:21 +08:00
if this.timer then
this.timer:Stop()
this.timer = nil
end
-- local endTime = ActivityGiftManager.GetTaskEndTime(ActivityTypeDef.TreasureStore)
-- local timeDown = endTime - GetTimeStamp()
local timeDown = CalculateSecondsNowTo_N_OClock(24)
2021-03-02 16:53:12 +08:00
this.time.text = Language[10023]..TimeToHMS(timeDown)
2020-05-09 13:31:21 +08:00
this.timer = Timer.New(function()
2021-05-29 21:31:01 +08:00
timeDown = timeDown - 1
2020-09-27 16:52:40 +08:00
if timeDown <= 0 then
2021-05-29 21:31:01 +08:00
timeDown = 0
2021-05-29 21:31:39 +08:00
this.time.text = Language[10023]..TimeToHMS(timeDown)
2020-05-09 13:31:21 +08:00
this.timer:Stop()
this.timer = nil
2020-09-27 16:52:40 +08:00
this.timer = Timer.New(function()
2021-02-26 17:26:45 +08:00
this:RefreshPanel(false)
2020-09-27 16:52:40 +08:00
this:TimeCountDown()
end,1):Start()
2020-05-09 13:31:21 +08:00
return
2021-05-29 21:31:01 +08:00
end
2021-03-02 16:53:12 +08:00
this.time.text = Language[10023]..TimeToHMS(timeDown)
2020-05-09 13:31:21 +08:00
end, 1, -1, true)
this.timer:Start()
2021-06-02 15:42:46 +08:00
this.rippleList = {}
2020-05-09 13:31:21 +08:00
end
2020-06-23 18:36:24 +08:00
return TreasureStorePopup