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

299 lines
11 KiB
Lua
Raw Normal View History

2025-03-14 11:58:20 +08:00
---- 百宝商会活动弹窗 ----
2020-05-09 13:31:21 +08:00
require("Base/BasePanel")
local TreasureStorePopup = Inherit(BasePanel)
2024-09-20 18:03:36 +08:00
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()
2024-09-20 18:03:36 +08:00
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")
2021-05-27 16:43:59 +08:00
this.oneKeyBtn:SetActive(false)
-- this.oneKeyBtnButton=Util.GetGameObject(this.panel,"oneKeyBtn"):GetComponent("Button")
2024-09-20 18:03:36 +08:00
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)
2020-05-09 13:31:21 +08:00
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
2024-09-20 18:03:36 +08:00
table.insert(effectList, Util.GetGameObject(this.panel, "Fx_Flower" .. i))
2021-06-02 15:42:46 +08:00
end
2024-09-20 18:03:36 +08:00
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()
2024-09-20 18:03:36 +08:00
Util.AddClick(this.backBtn, function()
2020-05-09 13:31:21 +08:00
self:ClosePanel()
end)
2024-09-20 18:03:36 +08:00
Util.AddClick(this.lianyiBtn, function()
LogGreen(Input.mousePosition.x .. "|" .. Input.mousePosition.y)
2021-06-02 15:42:46 +08:00
if not this.rippleList then
this.rippleList = {}
end
local rip = nil
2024-09-20 18:03:36 +08:00
for i = 1, #this.rippleList do
2021-06-02 15:42:46 +08:00
if this.rippleList[i] and not this.rippleList[i].activeSelf then
rip = this.rippleList[i]
break
end
end
if not rip then
2024-09-20 18:03:36 +08:00
rip = newObjToParent(this.Fx_Ripple, this.panel)
table.insert(this.rippleList, rip)
2021-06-02 15:42:46 +08:00
end
2024-09-20 18:03:36 +08:00
local uisize = Vector3.New(UIManager.realWidth, UIManager.realHeigt, 0)
2021-06-02 15:42:46 +08:00
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
2024-09-20 18:03:36 +08:00
uipos.x = screenpos2.x * (uisize.x / UIManager.width) --转换后的屏幕坐标*画布与屏幕宽高比
uipos.y = screenpos2.y * (uisize.y / UIManager.height)
2021-06-02 15:42:46 +08:00
uipos.z = -50
2024-09-20 18:03:36 +08:00
LogGreen(uipos.x .. "|" .. uipos.y)
2021-06-02 15:42:46 +08:00
rip:GetComponent("RectTransform").anchoredPosition3D = uipos
rip.gameObject:SetActive(true)
2024-09-20 18:03:36 +08:00
Timer.New(function()
2021-06-02 15:42:46 +08:00
rip.gameObject:SetActive(false)
2024-09-20 18:03:36 +08:00
end, 1, 1, false):Start()
2021-06-02 15:42:46 +08:00
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()
2024-09-20 18:03:36 +08:00
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
2024-09-20 18:03:36 +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
2024-09-20 18:03:36 +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)
2024-09-20 18:03:36 +08:00
-- return
2021-05-27 16:43:59 +08:00
-- 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)
2024-09-20 18:03:36 +08:00
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()
2024-09-20 18:03:36 +08:00
return
2020-09-27 16:52:40 +08:00
end
rechargeId = tonumber(GlobalActivity[curActId].ShowArt)
2024-09-20 18:03:36 +08:00
local data = GlobalActivity[curActId].CanBuyRechargeId
2020-09-27 16:52:40 +08:00
for i = 1, #data do
local data = ConfigManager.GetConfigDataByKey(ConfigName.RechargeCommodityConfig, "Id", data[i])
2024-09-20 18:03:36 +08:00
table.insert(allData, data)
2020-09-27 16:52:40 +08:00
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)
2024-09-20 18:03:36 +08:00
this.scrollView:SetData(allData, function(index, go)
2020-09-27 16:52:40 +08:00
this:SetScrollPre(go, allData[index])
2024-09-20 18:03:36 +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-09-27 16:52:40 +08:00
end
2024-09-20 18:03:36 +08:00
2020-09-27 16:52:40 +08:00
function this.SortData(allData)
2024-09-20 18:03:36 +08:00
if allData == nil then
2020-09-27 16:52:40 +08:00
return
end
2024-09-20 18:03:36 +08:00
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
2024-09-20 18:03:36 +08:00
2020-05-09 13:31:21 +08:00
--设置每一条
2024-09-20 18:03:36 +08:00
function this:SetScrollPre(root, data)
-- if isPlayAnim then
-- root.gameObject:SetActive(false)
-- else
-- root.gameObject:SetActive(true)
-- end
2024-09-20 18:03:36 +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")
local tip = Util.GetGameObject(root, "TipDi/Tip"):GetComponent("Text")
local effect = Util.GetGameObject(root, "Fx_Circle")
2021-05-28 18:53:54 +08:00
local itemList = {}
2024-09-20 18:03:36 +08:00
for i = 1, iRoot.transform.childCount do
2021-05-28 18:53:54 +08:00
itemList[i] = {}
2024-09-20 18:03:36 +08:00
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)
2025-01-15 11:26:51 +08:00
title.text = string.format(Language[12924], MoneyUtil.GetMoneyUnitNameWithMoney(config.Rebate),
MoneyUtil.GetMoneyUnitNameWithMoney(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
2024-09-20 18:03:36 +08:00
-- for i = 1, #rewardArray do
2021-05-28 18:53:54 +08:00
-- 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
2024-09-20 18:03:36 +08:00
for i = 1, math.max(#rewardArray, #itemList) do
2021-05-28 18:53:54 +08:00
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]))
2024-09-20 18:03:36 +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
2024-09-20 18:03:36 +08:00
LogGreen("boughtNum:" .. boughtNum)
tip.text = Language[10566] .. (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)
2024-09-20 18:03:36 +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
2024-08-29 21:36:51 +08:00
PopupTipPanel.ShowTip(Language[10626])
2020-09-27 16:52:40 +08:00
else
--直购商品
PayManager.Pay(data.Id, function(id)
this.RechargeSuccessFunc(id)
end)
end
end)
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)
2024-09-20 18:03:36 +08:00
this.time.text = Language[10026] .. 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
2024-09-20 18:03:36 +08:00
timeDown = 0
this.time.text = Language[10026] .. 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()
2024-09-20 18:03:36 +08:00
end, 1):Start()
2020-05-09 13:31:21 +08:00
return
2024-09-20 18:03:36 +08:00
end
this.time.text = Language[10026] .. TimeToHMS(timeDown)
2020-05-09 13:31:21 +08:00
end, 1, -1, true)
this.timer:Start()
2024-09-20 18:03:36 +08:00
this.rippleList = {}
2020-05-09 13:31:21 +08:00
end
2024-09-20 18:03:36 +08:00
return TreasureStorePopup