local GiftBuy = quick_class("GiftBuy") local this = GiftBuy local itemsGrid = {}--item重复利用 local allData = {} local rechargeCommodityConfig = ConfigManager.GetConfig(ConfigName.RechargeCommodityConfig) local cursortingOrder local endTime = 0 function GiftBuy:ctor(mainPanel, gameObject) self.mainPanel = mainPanel self.gameObject = gameObject self:InitComponent(gameObject) self:BindEvent() end --初始化组件(用于子类重写) function GiftBuy:InitComponent(gameObject) this.spLoader = SpriteLoader.New() this.itemPre = Util.GetGameObject(gameObject, "ItemPre") this.endTime = Util.GetGameObject(gameObject, "Image/endTime"):GetComponent("Text") this.endTimeBg = Util.GetGameObject(gameObject, "Image") this.scrollItem = Util.GetGameObject(gameObject, "scrollItem") local rootHight = this.scrollItem.transform.rect.height local width = this.scrollItem.transform.rect.width this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, this.scrollItem.transform, this.itemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 35)) this.ScrollView.moveTween.MomentumAmount = 1 this.ScrollView.moveTween.Strength = 2 end --绑定事件(用于子类重写) function GiftBuy:BindEvent() end --添加事件监听(用于子类重写) function GiftBuy:AddListener() end --移除事件监听(用于子类重写) function GiftBuy:RemoveListener() end local sortingOrder = 0 --界面打开时调用(用于子类重写) function GiftBuy:OnOpen() end --界面打开或者重新打开后,界面刷新时调用(用于子类重写) function GiftBuy:OnShow(_sortingOrder) sortingOrder = _sortingOrder this:OnShowData(true,true) end function GiftBuy:OnSortingOrderChange(_cursortingOrder) cursortingOrder = _cursortingOrder for i, v in pairs(itemsGrid) do for j = 1, #v do v[j]:SetEffectLayer(cursortingOrder) end end end function GiftBuy:OnShowData(isTop,isAni) allData = ConfigManager.GetAllConfigsDataByDoubleKey(ConfigName.RechargeCommodityConfig, "ShowType", 20, "Type", GoodsTypeDef.DirectPurchaseGift) this.SortData(allData) this.ScrollView:SetData(allData, function (index, go) this.SingleDataShow(go, allData[index]) end,not isTop,not isAni) PatFaceManager.RemainTimeDown(this.endTimeBg,this.endTime,endTime - GetTimeStamp()) end --刷新每一条的显示数据 function this.SingleDataShow(go, data) --绑定组件 local shopItemData = data local name = Util.GetGameObject(go, "context/text"):GetComponent("Text") local price = Util.GetGameObject(go, "btnBuy/price"):GetComponent("Text") local buyInfo = Util.GetGameObject(go, "buyInfo") local buyInfo2 = Util.GetGameObject(go, "buyInfo2") local btnBuy = Util.GetGameObject(go, "btnBuy") local grid = Util.GetGameObject(go, "scrollView/grid") local shadow = Util.GetGameObject(go, "shadow") local LimitText=Util.GetGameObject(go,"tip/tip1/text1"):GetComponent("Text") local goodData = OperatingManager.GetGiftGoodsInfo(GoodsTypeDef.DirectPurchaseGift, data.Id) local boughtNum = OperatingManager.GetGoodsBuyTime(GoodsTypeDef.DirectPurchaseGift, data.Id) or 0 local shows = shopItemData.RewardShow name.text = GetLanguageStrById(shopItemData.Name) LimitText.text = string.format(Language[12232], ""..shopItemData.Limit.."") -- if GetCurLanguage() == 2 then -- LimitText.gameObject.transform.localPosition = Vector3.New(4.7,-5,0) -- else -- LimitText.gameObject.transform.localPosition = Vector3.New(-147,-5,0) -- end buyInfo:SetActive( shopItemData.IsDiscount ~= 0 ) if shopItemData.IsDiscount and shopItemData.IsDiscount > 0 then buyInfo:GetComponent("Text").text = Language[10582]..string.format(MoneyUtil.GetMoneyUnitName(), MoneyUtil.GetMoney(shopItemData.Price) / (shopItemData.IsDiscount/10))--shopItemData.Price / (shopItemData.IsDiscount/10)..MoneyUtil.GetMoneyUnitName() end if goodData then endTime = goodData.endTime end if shopItemData.Limit - boughtNum > 0 then price.text = string.format(MoneyUtil.GetMoneyUnitName(), MoneyUtil.GetMoney(shopItemData.Price))--..MoneyUtil.GetMoneyUnitName() btnBuy:GetComponent("Button").enabled = true Util.SetGray(btnBuy, false) buyInfo2:SetActive(true) buyInfo2:GetComponent("Text").text = Language[10580]..shopItemData.Limit - boughtNum..Language[10048] else price.text = Language[10514] btnBuy:GetComponent("Button").enabled = false Util.SetGray(btnBuy, true) buyInfo2:SetActive(false) end --滚动条复用重设itemview if not itemsGrid[go] then itemsGrid[go] = {} end for k,v in pairs(itemsGrid[go]) do v.gameObject:SetActive(false) end for i = 1, #shows do if not itemsGrid[go][i] then itemsGrid[go][i] = SubUIManager.Open(SubUIConfig.ItemView, grid.transform) itemsGrid[go][i].gameObject:SetActive(false) local obj= newObjToParent(shadow,itemsGrid[go][i].transform) obj.transform:SetAsFirstSibling() obj.transform:DOAnchorPos(Vector3(0,-3,0),0) obj:GetComponent("RectTransform").transform.localScale=Vector3.one*1.1 obj.gameObject:SetActive(true) end itemsGrid[go][i]:OnOpen(false, {shows[i][1],shows[i][2]}, 0.9,false,false,false,cursortingOrder) itemsGrid[go][i].gameObject:SetActive(true) end -- if itemsGrid[go] then -- for i = 1, 4 do -- itemsGrid[go][i].gameObject:SetActive(false) -- end -- for i = 1, #shows do -- if itemsGrid[go][i] then -- itemsGrid[go][i]:OnOpen(false, {shows[i][1],shows[i][2]}, 0.9,false,false,false,cursortingOrder) -- itemsGrid[go][i].gameObject:SetActive(true) -- end -- end -- else -- itemsGrid[go]={} -- for i = 1, 4 do -- itemsGrid[go][i] = SubUIManager.Open(SubUIConfig.ItemView, grid.transform) -- itemsGrid[go][i].gameObject:SetActive(false) -- local obj= newObjToParent(shadow,itemsGrid[go][i].transform) -- obj.transform:SetAsFirstSibling() -- obj.transform:DOAnchorPos(Vector3(0,-3,0),0) -- obj:GetComponent("RectTransform").transform.localScale=Vector3.one*1.1 -- obj.gameObject:SetActive(true) -- end -- for i = 1, #shows do -- itemsGrid[go][i]:OnOpen(false, {shows[i][1],shows[i][2]}, 0.9,false,false,false,cursortingOrder) -- itemsGrid[go][i].gameObject:SetActive(true) -- end -- end --local costId, finalNum, oriCostNum = ShopManager.calculateBuyCost(SHOP_TYPE.FINDTREASURE_GIFT, data.id, 1) Util.AddOnceClick(btnBuy, function() if shopItemData.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) --OperatingManager.RefreshGiftGoodsBuyTimes(GoodsTypeDef.GiftBuy, id) this.OnShowData(false,false) end --购买点击事件 --function this.BuyAction(costId, costNum, shopType, itemId) -- local haveNum = BagManager.GetItemCountById(costId) -- local costName = ConfigManager.GetConfigData(ConfigName.ItemConfig, costId).Name -- if haveNum < costNum then -- NotEnoughPopup:Show(costId) -- else -- local isPopUp = RedPointManager.PlayerPrefsGetStr(PlayerManager.uid .. shopType) -- local currentTime = os.date("%Y%m%d", PlayerManager.serverTime) -- if (isPopUp ~= currentTime and costNum ~= 0) then -- local str = string.format("确认花费%d%s购买本礼包吗?", costNum, costName) -- MsgPanel.ShowTwo(str, function() -- end, function(isShow) -- if (isShow) then -- local currentTime = os.date("%Y%m%d", PlayerManager.serverTime) -- RedPointManager.PlayerPrefsSetStr(PlayerManager.uid .. shopType, currentTime) -- end -- ShopManager.RequestBuyShopItem(shopType, itemId, 1, function() -- self:RefreshGiftData() -- end) end, "取消", "确定",nil,true) -- else -- ShopManager.RequestBuyShopItem(shopType, itemId, 1, function() -- self:RefreshGiftData() -- end) -- end -- end --end function this.SortData(allData) 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) end --界面关闭时调用(用于子类重写) function GiftBuy:OnClose() end --界面销毁时调用(用于子类重写) function GiftBuy:OnDestroy() this.spLoader:Destroy() sortingOrder = 0 itemsGrid = {} end return GiftBuy