local GrowthGiftPage = {} local sortingOrder = 0 local rewardNameConfig = ConfigManager.GetConfig(ConfigName.ItemConfig)--读取奖励名称信息 local GlobalActivity = ConfigManager.GetConfig(ConfigName.GlobalActivity) local actRewardConfig = ConfigManager.GetConfig(ConfigName.ActivityRewardConfig) local rechargeConfigs = ConfigManager.GetAllConfigsDataByKey(ConfigName.RechargeCommodityConfig,"Type",GoodsTypeDef.GrowthReward) local giftList = { [101] = 6,--表内没有礼包id(101、102、103、104、105)和ActivityId的对应关系, [102] = 7, [103] = 8,--自定义本表建立对应关系 [104] = 9, [105] = 16, } function GrowthGiftPage:New(gameObject) local b = {} b.gameObject = gameObject b.transform = gameObject.transform setmetatable(b, { __index = GrowthGiftPage }) return b end --初始化组件(用于子类重写) function GrowthGiftPage:InitComponent() --定义头部文字和按钮 self.bg = Util.GetGameObject(self.gameObject, "rzyBg") self.tip = Util.GetGameObject(self.gameObject, "rzyBg/bg/tip"):GetComponent("Text") self.tip.text = "超值返利,累计可获10000妖晶" self.btnInvest = Util.GetGameObject(self.gameObject, "rzyBg/bg/btnInvest") self.btnInvestText = Util.GetGameObject(self.gameObject, "rzyBg/bg/btnInvest/Text"):GetComponent("Text") --滚动条和预设 self.scrollItem = Util.GetGameObject(self.gameObject, "rzyBg/scrollItem") self.itemPre = Util.GetGameObject(self.gameObject, "rzyBg/ItemPre") --设置滚动条 local rootHight = self.scrollItem.transform.rect.height local width = self.scrollItem.transform.rect.width self.scrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.scrollItem.transform, self.itemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 0)) self.scrollView.moveTween.MomentumAmount = 1 self.scrollView.moveTween.Strength = 2 end --绑定事件(用于子类重写) function GrowthGiftPage:BindEvent() Util.AddOnceClick(self.btnInvest,function() self:OnBtnInvestClicked() end) end --添加事件监听(用于子类重写) function GrowthGiftPage:AddListener() end --移除事件监听(用于子类重写) function GrowthGiftPage:RemoveListener() end --界面打开时调用(用于子类重写) function GrowthGiftPage:OnOpen(_activityConfig,_index,parent) self.actConfig = _activityConfig self.pageIndex = _index self.parent = parent end -- 打开,重新打开时回调 function GrowthGiftPage:OnShow(_sortingOrder) self.gameObject:SetActive(true) sortingOrder = _sortingOrder self.curActiId = self.actConfig.ActId self.actType = self.actConfig.ActiveType if self.actConfig.IfBack == 1 then if self.actConfig.ActiveType > 0 then local id = ActivityGiftManager.IsActivityTypeOpen(self.actConfig.ActiveType) if id and id > 0 then self.curActiId = id local config = ConfigManager.TryGetConfigDataByThreeKey(ConfigName.ActivityGroups,"PageType",self.actConfig.PageType,"ActiveType",self.actConfig.ActiveType,"ActId",id) if config then self.actConfig = config end end end end self.curGiftsId = GlobalActivity[self.curActiId].CanBuyRechargeId[1] self:RefreshData() end function GrowthGiftPage:RefreshData() self:SetBtnInvestState() self:RefreshGiftData(true) end --设置投资按钮初始状态 function GrowthGiftPage:SetBtnInvestState() self.gift = OperatingManager.GetGiftGoodsInfo(GoodsTypeDef.GrowthReward, self.curGiftsId) if self.gift and self.gift.buyTimes == 0 then self.btnInvest:GetComponent("Button").enabled = true local rechargeConfig = ConfigManager.GetConfigData(ConfigName.RechargeCommodityConfig, self.curGiftsId) self.btnInvestText.text = string.format(MoneyUtil.GetMoneyUnitName(),MoneyUtil.GetMoney(rechargeConfig.Price))--"$98" Util.SetGray(self.btnInvest, false) else self.btnInvest:GetComponent("Button").enabled = false self.btnInvestText.text = "已购买" Util.SetGray(self.btnInvest, true) end end function GrowthGiftPage:RefreshGiftData(anim) self.actiInfo = ActivityGiftManager.GetActivityInfoByType(self.curActiId) table.sort(self.actiInfo.mission, function(a, b) if a.state == 0 and b.state ~= 0 then return true end if a.state ~= 0 and b.state == 0 then return false end if a.state == b.state then return a.missionId < b.missionId end return a.state < b.state end) if not self.missionPre then self.missionPre = {} end for k,v in pairs(self.missionPre) do v.gameObject:SetActive(false) end self.scrollView:SetData(self.actiInfo.mission, function(index, item) self:RefreshShowData(item, self.actiInfo.mission[index]) end,not anim) end --刷新每一条item function GrowthGiftPage:RefreshShowData(item, data) if not self.missionPre[item] then self.missionPre[item] = SubUIManager.Open(SubUIConfig[360],item.transform) end self.missionPre[item].gameObject:SetActive(true) local shows = actRewardConfig[data.missionId].Reward local title = rewardNameConfig[shows[1][1]].Name local content = "达到"..actRewardConfig[data.missionId].Values[1][2].."级可领取" local isCanGetReward = PlayerManager.level >= actRewardConfig[data.missionId].Values[1][2] local goods = OperatingManager.GetHadBuyGoodsTypeId(GoodsTypeDef.GrowthReward)--已购买礼包ID local state = data.state --0 未领取(已达到条件) 1 已领取 -1 未达到等级 2可领取 if data.state == 0 then if PlayerManager.level < actRewardConfig[data.missionId].Values[1][2] then state = -1 elseif self.gift.buyTimes > 0 then state = 2 end else state = data.state end self.missionPre[item]:OnShow(shows,title,content,state,function() end,function() if state == -1 then PopupTipPanel.ShowTip("未达到等级要求~~~") elseif state == 2 then NetManager.GetActivityRewardRequest(data.missionId,self.curActiId, function(drop) UIManager.OpenPanel(UIName.RewardItemPopup, drop, 1) ActivityGiftManager.SetActivityInfo(self.curActiId, data.missionId, 1) RedpotManager.CheckRedPointStatus(RedPointType.GrowthGift) if self:CheckAllGet(self.curActiId,data.missionId) == 0 then self:RefreshGiftData(false) return end if(self.curActiId == 16)then--16是最后一个礼包的ActivityId MsgPanel.ShowOne("恭喜!您已领取全部成长基金!") else MsgPanel.ShowOne("恭喜!您已激活更高等级成长基金,大量妖晶福利等您领取,快来激活吧!") self:OnShow(sortingOrder) end end) else PopupTipPanel.ShowTip("请购买基金后领取") end end,function() end,sortingOrder) end --检测是否全部已领取 function GrowthGiftPage:CheckAllGet(curActiId,missionId) local aciInfo = ActivityGiftManager.GetActivityInfoByType(curActiId) for i = 1, #aciInfo.mission do if aciInfo.mission[i].state ~= 1 and aciInfo.mission[i].missionId ~= missionId then return 0 end end return 1 end --点击进行投资购买礼包 function GrowthGiftPage:OnBtnInvestClicked() self.btnInvest:GetComponent("Button").enabled = false self:RequestBuy() end function GrowthGiftPage:RequestBuy() local giftGoodsInfo = OperatingManager.GetGiftGoodsInfo(GoodsTypeDef.GrowthReward, self.curGiftsId) PayManager.Pay(giftGoodsInfo.goodsId, function(id) self:RefreshStatus() end) end function GrowthGiftPage:RefreshStatus() -- 添加已经购买的物品 OperatingManager.SetHadBuyGoodsId({self.curGiftsId}) -- 增加充值金额 FirstRechargeManager.RefreshAccumRechargeValue(self.curGiftsId) -- 检测红点状态 RedpotManager.CheckRedPointStatus(RedPointType.GrowthGift) -- 刷新当前界面显示 self:RefreshData() end --界面关闭时调用(用于子类重写) function GrowthGiftPage:OnClose() self.gameObject:SetActive(false) end --界面销毁时调用(用于子类重写) function GrowthGiftPage:OnDestroy() for k,v in pairs(self.missionPre) do SubUIManager.Close(v) end self.missionPre = {} end return GrowthGiftPage