local UIGachaGetLimit = UIViewClass() local GoldMassEffectPath = ConstAssetPathConfig.GoldMassEffectPath local GoldMassBurstEffectPath = ConstAssetPathConfig.GoldMassBurstEffectPath local DarkGoldMassEffectPath = ConstAssetPathConfig.DarkGoldMassEffectPath local DarkGoldMassBurstEffectPath = ConstAssetPathConfig.DarkGoldMassBurstEffectPath local WholeCardMassEffectPath = ConstAssetPathConfig.WholeCardMassEffectPath local WholeCardBurstEffectPath = ConstAssetPathConfig.WholeCardBurstEffectPath local HeroHeadBustImgPath = ConstAssetPathConfig.HeroHeadBustImgPath local ShowAnimStage = { LightMass = 0, Wait = 1, Appear = 2, AppearFast = 3, End = 4, } local WholeCardColorConst = 5 local GoldMassColorConst = 6 local DarkGoldMassColorConst = 7 local LightMassWaitTime = 0.5 local AppearTimeGap = 0.3 -------------------------------- 系统函数 ------------------------------------------- function UIGachaGetLimit:OnOpened(context) self:RegistSystemEvent(EventID.UI_GachaLimit_RefreshGet_CostInfo, self.RefreshCostNum) self:RegistSystemEvent(EventID.UI_GachaLimit_RefreshGet, self.RefreshPanel) UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, false) self.isDirectShow = context.isDirectShow self:RefreshPanel(context) self:SetPushStyle(LuaConst.PushStyleEnum.CLOSENOTRECOVER) end function UIGachaGetLimit:RefreshPanel(msg) local result = msg.result self.drawCardResult = result self.amountCardCount = #result.cardReward self.activityId = result.activityId self.activityType = result.activityType self.activityCfg = MDL.OperationActivity.ActivityBaseData[self.activityType]:GetDataByActivityID(self.activityId) self.drawCardPoolID = self.activityCfg.DrawCardPoolID self.itemStoreID = DataSheetManager.DrawCardData:GetDataByID(self.drawCardPoolID).ItemStoreID self.isSkip = self.amountCardCount > 10 and true or MDL.ActivityGacha.GetSkipState() if self.isSkip then CTL.ActivityGacha.SetTimeLineList(self.drawCardResult) for i, v in ipairs(self.drawCardResult.cardReward) do local wholeHeroId = UTL.Item.IsItemWholeHero(v.rewardItems[1].ItemId) if wholeHeroId then if not CTL.DrawCard.IsHeroTransToPiece(wholeHeroId) then CTL.ActivityGacha.AddTimeLineList(wholeHeroId) end end end end local itemId = CTL.ActivityGacha.GetConsumeItemInfos(self.drawCardPoolID) UTL.Item.SetCurrencyImageIcon(self.img_Icon, itemId) UTL.Item.SetCurrencyImageIcon(self.img_Icon_50, itemId) if self.amountCardCount == 1 then self.state_MultiDraw:SetState(0) elseif self.amountCardCount == 10 then self.state_MultiDraw:SetState(1) else self.state_MultiDraw:SetState(3) end UIUtils.SetLabel(self.UITemplateTitlePanel.lab_Title, CTL.ActivityGacha.GetGachatTitleName(self.drawCardPoolID)) self:RefreshCostNum() UIUtils.SetActive(self.group_Mid, false) UIUtils.SetActive(self.UITemplateTitlePanel.gameObject, false) --stage是标明动画的播放阶段 --0是同时出现,所有物品不显示,只出现光团 --1是中间的等待时间 --2是一个一个按照时间间隔由光团变成物体 --4是结束 self.stage = ShowAnimStage.LightMass self.appearIndex = 0 if self.isDirectShow then self.stage = ShowAnimStage.Appear self:SkipRefresh() else self:RefreshLightMass() if self.isSkip then self.stage = ShowAnimStage.Appear self:StartRepeatFunc(self.SkipRefresh, AppearTimeGap, 1) else self:TrySetAppearIndex(CTL.ActivityGacha.GetLastAppearIndex()) self:StartRepeatFunc(self.OnUpdateFun, AppearTimeGap) end end self.lightMassSoundId = CTL.Sound.PlayGameSound("UI_zuoqi_tupo") -- 此处播放动画 保证收到监听也可以触发动画 UIUtils.SetActive(self.mask, true) self:PlayUIAnimation("AnimationMask", true) end function UIGachaGetLimit:OnUpdateFun(deltaTime, timeSinceUpdate) if self.stage == ShowAnimStage.Wait then --等待 if timeSinceUpdate >= LightMassWaitTime then self.stage = ShowAnimStage.Appear end elseif self.stage == ShowAnimStage.Appear or self.stage == ShowAnimStage.AppearFast then --依次出现 self:RefreshAppearItem() elseif self.stage == ShowAnimStage.End then --结束 self:StageEnd() end end function UIGachaGetLimit:StageEnd() self:StopRepeatFunc(self.OnUpdateFun) UIUtils.SetActive(self.group_Mid, true) UIUtils.SetActive(self.UITemplateTitlePanel.gameObject, true) self.appearIndex = 0 self.stage = ShowAnimStage.End if self.lightMassSoundId then CTL.Sound.StopById(self.lightMassSoundId) self.lightMassSoundId = nil end CTL.ActivityGacha.ExecuteTimelineList() end function UIGachaGetLimit:OnButtonClicked(comp) if comp == self.Bottom then --self:SkipRefresh() elseif comp == self.UITemplateTitlePanel.btn_close then self:CloseView() elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.btn_Confirm then self:CloseView() elseif comp == self.btn_Gacha10 then self:RequestDrawCard(self.amountCardCount >= 10 and 10 or 1) elseif comp == self.btn_Gacha50 then self:RequestDrawCard(50) elseif comp == self.group_SingleCard.event_Click then local data = self.cardReward[1].rewardItems[1] UTL.ItemTips.ShowCommonTipsById(data.ItemId) else for i, v in ipairs(self.group_Cards) do if comp == v.event_Click then UTL.ItemTips.ShowCommonTipsById(self.cardReward[i].rewardItems[1].ItemId) end end end end function UIGachaGetLimit:SetDrawCardsCell(cellTable, data) local wholeHeroId if self.stage == ShowAnimStage.LightMass then UIUtils.SetActive(cellTable.group_2D, false) local itemId = data.ItemId local itemData = DataSheetManager.ItemData:GetDataByID(itemId) if itemData.DrawCardColor == DarkGoldMassColorConst then cellTable.effect_GoldMass:PlayUIEffect(DarkGoldMassEffectPath, -1) elseif itemData.DrawCardColor == GoldMassColorConst then cellTable.effect_GoldMass:PlayUIEffect(GoldMassEffectPath, -1) elseif itemData.DrawCardColor == WholeCardColorConst then cellTable.effect_GoldMass:PlayUIEffect(WholeCardMassEffectPath, -1) else cellTable.effect_NormalMass:PlayUIEffect() end elseif self.stage == ShowAnimStage.Appear or self.stage == ShowAnimStage.AppearFast or self.stage == ShowAnimStage.End then wholeHeroId = self:SetDrawCardReward(cellTable, data) local itemData = DataSheetManager.ItemData:GetDataByID(data.ItemId) if self.stage ~= ShowAnimStage.AppearFast then if itemData.DrawCardColor == DarkGoldMassColorConst then cellTable.effect_GoldMassBurst:PlayUIEffect(DarkGoldMassBurstEffectPath, 2) elseif itemData.DrawCardColor == GoldMassColorConst then cellTable.effect_GoldMassBurst:PlayUIEffect(GoldMassBurstEffectPath, 2) elseif itemData.DrawCardColor == WholeCardColorConst then cellTable.effect_GoldMassBurst:PlayUIEffect(WholeCardBurstEffectPath, 2) else cellTable.effect_NormalMassBurst:PlayUIEffect() end end if not self.isSkip then if self.amountCardCount == 1 then CTL.Sound.PlayGameSound("UI_single_jewel") else CTL.Sound.PlayGameSound("UI_double_jewel") end end return wholeHeroId end end function UIGachaGetLimit:SetDrawCardReward(cellTable, data) local wholeHeroId UIUtils.SetActive(cellTable.group_2D, true) local itemId = data.ItemId local itemData = DataSheetManager.ItemData:GetDataByID(itemId) cellTable.effect_GoldMass:StopUIEffect() cellTable.effect_NormalMass:StopUIEffect() if itemData.FirstType == LuaConst.ItemType.HeroFragment then local heroId = UTL.Item.IsItemWholeHero(itemId) if heroId == false then cellTable.state_Item:SetState(0) UTL.Item.ItemIconWithoutBg(cellTable.img_Hero, itemId) UIUtils.SetActive(cellTable.group_Card, true) else cellTable.state_Item:SetState(2) local heroData = DataSheetManager.HeroNum:GetDataByID(heroId) UIUtils.SetLabelText(cellTable.txt_Name, Const_IDS[heroData.NameIDS]) UIUtils.SetImageByAssetBundle(cellTable.img_WholeHero, string.format(HeroHeadBustImgPath, heroData.HalfCardImage)) UIUtils.SetActive(cellTable.group_Card, false) wholeHeroId = heroId end else cellTable.state_Item:SetState(1) UTL.Item.ItemIconWithoutBg(cellTable.img_Item, itemId) UIUtils.SetActive(cellTable.group_Card, true) end cellTable.txt_Num.text = data.ItemCount cellTable.txt_Name.text = UTL.Item.GetItemDataSpliceByType(itemId).Name local qualityData = DataSheetManager.QualityColor:GetDataByID(itemData.Color) cellTable.effect_Quality:PlayUIEffect(qualityData.LimitDrawCardIconEffect, -1) return wholeHeroId end function UIGachaGetLimit:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_Cards then if cellTable.event_Click == target then UTL.ItemTips.ShowCommonTipsById(data.ItemId) end end end ----------------------------------------------------------------------------------- function UIGachaGetLimit:SkipRefresh() if self.stage == ShowAnimStage.Wait then self.stage = ShowAnimStage.Appear self:StopRepeatFunc(self.OnUpdateFun) self:StartRepeatFunc(self.OnUpdateFun, AppearTimeGap) elseif self.stage == ShowAnimStage.Appear then CTL.Sound.PlayGameSound("UI_completion") self:RefreshLightMass() self:StartRepeatFunc(self.OnUpdateFun, AppearTimeGap) end end function UIGachaGetLimit:RefreshAppearItem() if not self.drawCardResult then return end self.appearIndex = self.appearIndex + 1 self.cardReward = self.drawCardResult.cardReward local wholeHeroId if self.amountCardCount == 1 then wholeHeroId = self:SetDrawCardsCell(self.group_SingleCard, self.cardReward[1].rewardItems[1]) else local cell = self.group_Cards[self.appearIndex] wholeHeroId = self:SetDrawCardsCell(cell, self.cardReward[self.appearIndex].rewardItems[1]) end if self.appearIndex >= self.amountCardCount then self.stage = ShowAnimStage.End end self.wholeHeroId = wholeHeroId --如果是武将整卡,弹出武将展示 if wholeHeroId then self:StopRepeatFunc(self.OnUpdateFun) self:StartRepeatFunc(self.DelayShowWholeHero, 0.5, 1) end end function UIGachaGetLimit:DelayShowWholeHero() CTL.ActivityGacha.ShowWholeHero(self.drawCardResult, self.appearIndex < self.amountCardCount and self.appearIndex or 0, self.wholeHeroId) end function UIGachaGetLimit:TrySetAppearIndex(appearIndex) if appearIndex then self.stage = ShowAnimStage.AppearFast if appearIndex == 0 then if self.amountCardCount == 1 then self:SetDrawCardsCell(self.group_SingleCard, self.cardReward[1].rewardItems[1]) else for i = 1, self.amountCardCount do local cell = self.group_Cards[i] self:SetDrawCardsCell(cell, self.cardReward[i].rewardItems[1]) end end self.stage = ShowAnimStage.End else for i = 1, appearIndex do local cell = self.group_Cards[i] self:SetDrawCardsCell(cell, self.cardReward[i].rewardItems[1]) end self.appearIndex = appearIndex self.stage = ShowAnimStage.Appear end end end function UIGachaGetLimit:RefreshLightMass() if not self.drawCardResult then return end self.cardReward = self.drawCardResult.cardReward if self.amountCardCount == 1 then self:SetDrawCardsCell(self.group_SingleCard, self.cardReward[1].rewardItems[1]) elseif self.amountCardCount == 10 then for i, v in ipairs(self.cardReward) do if i > self.appearIndex then local cell = self.group_Cards[i] self:SetDrawCardsCell(cell, v.rewardItems[1]) end end else if self.loop_Cards.Count > 0 then self.loop_Cards:RefreshCells() else for i, v in ipairs(self.cardReward) do self.loop_Cards:AddData(v.rewardItems[1], 0) end end end self.stage = self.stage == ShowAnimStage.Appear and ShowAnimStage.End or ShowAnimStage.Wait self:ResetRepeatFunc(self.OnUpdateFun) end function UIGachaGetLimit:RefreshCostNum() local itemId, itemStockCount = CTL.ActivityGacha.GetConsumeItemInfos(self.drawCardPoolID) self.txt_CostNum.text = CTL.ActivityGacha.GetGachaCostNumShow(itemId, self.amountCardCount >= 10 and 10 or 1) self.txt_CostNum_50.text = CTL.ActivityGacha.GetGachaCostNumShow(itemId, 50) self:SetGiveItem(self.drawCardPoolID) end function UIGachaGetLimit:SetGiveItem(poolId) local drawCardData = DataSheetManager.DrawCardData:GetDataByID(poolId) UTL.Item.SetItemIcon(self.group_Info.img_GiveItemIcon, drawCardData.PresentedItemID) self.group_Info.txt_GiveItemNum.text = drawCardData.PresentedItemNum * (self.amountCardCount >= 10 and 10 or 1) UTL.Item.SetItemIcon(self.group_Info_50.img_GiveItemIcon, drawCardData.PresentedItemID) self.group_Info_50.txt_GiveItemNum.text = drawCardData.PresentedItemNum * (self.amountCardCount >= 10 and 50 or 1) end function UIGachaGetLimit:RequestDrawCard(drawNum) --活动关闭时,直接关闭页面 if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.GoldHeroActivity) then self:CloseView() return end local itemId, countInBag = CTL.ActivityGacha.GetConsumeItemInfos(self.drawCardPoolID) if countInBag >= drawNum then --购买 self.loop_Cards:ClearCells() MDL.ActivityGacha.RequestActivityDrawCard(self.activityId, self.activityType, drawNum, drawNum >= 10) self.state_MultiDraw:SetState(2) else if self.itemStoreID > 0 then --弹出购买道具框 local store = MDL.OperationActivity.StoreGoodsData:GetDataByID(self.itemStoreID) local currencyID = store.MoneyID local currencyCount = store.BuyPrice UIManager.OpenView(Const_UI_Lua.UIEnum.UIItemBuyPanel, {ItemId = itemId, ItemStoreId = self.itemStoreID, CurrencyId = currencyID, CurrencyCount = currencyCount}) else CTL.OperationActivity.OpenGetActivityItemPanel(itemId, self.activityId, self.activityType) end end end function UIGachaGetLimit:OnClosed() UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) if self.lightMassSoundId then CTL.Sound.StopById(self.lightMassSoundId) self.lightMassSoundId = nil end CTL.ActivityGacha.SetTimeLineList() end function UIGachaGetLimit:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Cards then if index > 15 or self.stage == ShowAnimStage.End then --看不到的直接显示奖励 self:SetDrawCardReward(cellTable, data) else --可看到的显示特效 self:SetDrawCardsCell(cellTable, data) end end end return UIGachaGetLimit