---- 百宝商会活动弹窗 ---- 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 local effectList = {} local orginLayer = 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 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") end function TreasureStorePopup:BindEvent() Util.AddClick(this.backBtn, function() self:ClosePanel() end) 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) -- 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:OnSortingOrderChange() for i = 1, #effectList do Util.SetParticleSortLayer(effectList[i], self.sortingOrder + 1) end this.scrollView:ForeachItemGO(function(index, go) Util.SetParticleSortLayer(Util.GetGameObject(go, "Fx_Circle"), self.sortingOrder + 1) end) orginLayer = self.sortingOrder 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 self:ClosePanel() 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) return a.Sequence < b.Sequence 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") local effect = Util.GetGameObject(root, "Fx_Circle") 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(Language[12924], 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 = this.spLoader:LoadSprite(GetSpriteNameByItemId(rewardArray[i][1])) itemList[i].Name.text = ConfigManager.GetConfigData(ConfigName.ItemConfig, rewardArray[i][1]).Name .. "×" .. rewardArray[i][2] Util.AddOnceClick(itemList[i].go, function() UIManager.OpenPanel(UIName.RewardItemSingleShowPopup, rewardArray[i][1], function() UIManager.ClosePanel(UIName.RewardItemSingleShowPopup) end) end) end end local boughtNum = OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, data.Id) or 0 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() if data.Limit - boughtNum > 0 then buyBtn:GetComponent("Button").enabled = true Util.SetGray(buyBtn, false) effect.gameObject:SetActive(true) else buyBtn:GetComponent("Button").enabled = false Util.SetGray(buyBtn, true) effect.gameObject:SetActive(false) end Util.AddOnceClick(buyBtn, function() if data.Limit <= boughtNum then PopupTipPanel.ShowTip(Language[10626]) 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() local timeDown = CalculateSecondsNowTo_N_OClock(24) this.time.text = Language[10026] .. TimeToHMS(timeDown) this.timer = Timer.New(function() timeDown = timeDown - 1 if timeDown <= 0 then timeDown = 0 this.time.text = Language[10026] .. TimeToHMS(timeDown) this.timer:Stop() this.timer = nil this.timer = Timer.New(function() this:RefreshPanel(false) this:TimeCountDown() end, 1):Start() return end this.time.text = Language[10026] .. TimeToHMS(timeDown) end, 1, -1, true) this.timer:Start() this.rippleList = {} end return TreasureStorePopup