local UIGachaGet = UIViewClass() local EventSystem = require('Event/EventSystem') local CardAppear = "cell_CardAppear" local SingleCardAppear = "cell_SingleCardAppear" local FragmentOpenCard = ConstAssetPathConfig.FragmentOpenCard local HeroOpenCard = ConstAssetPathConfig.HeroOpenCard local HeroOpenCardDetail = ConstAssetPathConfig.HeroOpenCardDetail local HeroOpenCardMask = ConstAssetPathConfig.HeroOpenCardMask local HeroOpenCardTogether = ConstAssetPathConfig.HeroOpenCard local amountCardFifty = 50 local itemInViewCountTen = 10 local function SortRule(a, b) local itemIdA = a.rewardItems[1].ItemId local itemIdB = b.rewardItems[1].ItemId local heroIdA = UTL.Item.IsItemWholeHero(itemIdA) local heroIdB = UTL.Item.IsItemWholeHero(itemIdB) local itemDataA = DataSheetManager.ItemData:GetDataByID(itemIdA) local itemDataB = DataSheetManager.ItemData:GetDataByID(itemIdB) if heroIdA and heroIdB then if itemDataA.DrawCardColor == itemDataB.DrawCardColor then return itemIdA > itemIdB else return itemDataA.DrawCardColor > itemDataB.DrawCardColor end elseif heroIdA == false and heroIdB == false then if itemDataA.Color == itemDataB.Color then return itemIdA > itemIdB else return itemDataA.Color > itemDataB.Color end else return heroIdA ~= false and true or false end end --------------------------------------- 系统函数 --------------------------------------- function UIGachaGet:OnOpened(context) self.openShowCmpList = {} self.isOriginDrawCardByOne = context.isDrawCardByOne self.rewardNum = #context.rewardList local _, countInBag, _, _ = MDL.DrawCard.GetConstItemAndNum(MDL.DrawCard.GetCurCardPoolID()) self:RegistSystemEvent(EventID.UI_Gacha_RefreshGet_CostInfo, self.RefreshCostNum) self:RegistSystemEvent(EventID.UI_Gacha_RefreshGet, self.RefreshPanel) self:RegistSystemEvent(EventID.UI_DrawCard_OnCloseGamePlay, self.OnCloseGamePlay) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title, Const_IDS["IDS_DrawCard"]) UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, false) UIUtils.SetActive(self.mask, false) self.amountCardCount = 0 self.cardCurIndex = 0 self.aniInitCard = nil self.aniMaskCard = nil if self.rewardNum == amountCardFifty then self.isGachaFifty = true else self.isGachaFifty = false end self.isGacha50Clickable = true self.isGacha10Clickable = true --这里有点特殊,因为有被其他页面CloseSelfAndBack 打开的情况,所以在这统一处理玩法关闭的情况 if not MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.DrawCard) then self:OnCloseGamePlay() return end self:RefreshPanel(context) if countInBag < 50 then UIUtils.SetActive(self.PanelMid.btn_Gacha50, false) UIUtils.SetActive(self.PanelMid.group_Info50, false) end end function UIGachaGet:OnUpdateFun(deltaTime, timeSinceUpdate) self.cardCurIndex = self.cardCurIndex + 1 self:PlayCardOpenAnimation() end function UIGachaGet:OnFocusChanged(isFocus) UIUtils.SetActive(self.PanelMid.btn_Gacha10, isFocus) end function UIGachaGet:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UIGachaGet:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close or comp == self.PanelMid.btn_Confirm then self:CloseView() UIManager.OpenView(Const_UI_Lua.UIEnum.UIGachaMain) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.PanelMid.btn_Gacha10 then if not self.isGacha10Clickable then return end self.isGacha10Clickable = false self.amountCardCount = self.isOriginDrawCardByOne and 1 or 10 MDL.DrawCard.SetIsSkipAnim(true) if self.isOriginDrawCardByOne then UIUtils.SetActive(self.Content.gameObject, true) UIUtils.SetActive(self.group_Cell50, false) else self.isGachaTenAgain = true end self:RequestDrawCard() elseif comp == self.PanelMid.btn_Gacha50 then if not self.isGacha50Clickable then return end self.isGacha50Clickable = false local leftDrawCount = MDL.DrawCard.GetDrawCardSumCountPerDay() self.amountCardCount = 50 MDL.DrawCard.SetIsSkipAnim(true) if leftDrawCount >= amountCardFifty then UIUtils.SetActive(self.Content.gameObject, false) UIUtils.SetActive(self.group_Cell50, true) end self:RequestDrawCard() else for i, v in ipairs (self.Content) do if comp == v.item_Hero.event_Click then UTL.ItemTips.ShowCommonTipsById(self.rewardList[i].rewardItems[1].ItemId) break end end end end function UIGachaGet:OnUIAnimationStoped(playingID) if self.aniInitCard == playingID then self:PlayCardOpenAnimation() elseif self.aniMaskCard == playingID then local isNew = self.rewardNewDict[self.cardCurIndex + 1] self.cardCurIndex = self.cardCurIndex + 1 local rewardItem = self.rewardList[self.cardCurIndex] local comp = self.Content[self.cardCurIndex] local heroId = UTL.Item.IsItemWholeHero(rewardItem.rewardItems[1].ItemId) if heroId then self.params.curIndex = self.cardCurIndex -- 显示新卡特效 if self.rewardNewDict[self.cardCurIndex] then comp.effect_NewCard:PlayUIEffect() end -- 打开武将展示 if self.rewardNum == amountCardFifty then self:RefreshPanel(self.context) UIUtils.SetActive(self.mask, false) else if isNew then UIManager.OpenAndPushAll(Const_UI_Lua.UIEnum.UIGachaExpression, self.params) end end end end if self.rewardNum == amountCardFifty or self.isGachaTenAgain then if self.rewardNum == amountCardFifty then self.isGacha50Clickable = true else self.isGacha10Clickable = true end self.isFristRoundCellInit = not self.isFristRoundCellInit self.group_Cell50:RefreshCells() end if self.rewardNum == 1 then self.isGacha10Clickable = true end end function UIGachaGet:OnCellInit(scrollRect, index, cellTable, data) self:SetCardInfo(data, cellTable, index) if self.cardCurIndex < self.amountCardCount then local rewardData = self.rewardList[self.cardCurIndex + 1] local cmp = cellTable local itemData = DataSheetManager.ItemData:GetDataByID(rewardData.rewardItems[1].ItemId) local heroId = UTL.Item.IsItemWholeHero(rewardData.rewardItems[1].ItemId) CTL.Sound.PlayGameSound("UI_single_open") self.cardCurIndex = self.cardCurIndex + 1 if heroId then -- 显示新卡特效 if self.rewardNewDict[self.cardCurIndex] then cmp.effect_NewCard:PlayUIEffect() end UIUtils.SetActive(self.mask, false) self:StopRepeatFunc(self.OnUpdateFun) self:PlayOpenCardEffect(cmp, itemData.DrawCardColor) else UIUtils.SetActive(cmp.group_Card, true) end end if self.cardCurIndex <= itemInViewCountTen then if self.rewardNum == amountCardFifty or self.isGachaTenAgain and self.isFristRoundCellInit then self:PlayUIAnimation(HeroOpenCardTogether, cellTable.animatonObj.transform) end end end ----------------------------------------------------------------------------------------------- function UIGachaGet:RefreshPanel(rewardResult) self.rewardNum = #rewardResult.rewardList if self.rewardNum == amountCardFifty then self.isGachaFifty = true UIUtils.SetActive(self.Content.gameObject, false) UIUtils.SetActive(self.group_Cell50, true) else self.isGachaFifty = false if self.isGachaTenAgain then UIUtils.SetActive(self.Content.gameObject, false) UIUtils.SetActive(self.group_Cell50, true) end end self.params = rewardResult self.rewardList = rewardResult.rewardList self.rewardNewDict = rewardResult.rewardNewDict local rewardItem = rewardResult.rewardItem local isInit = rewardResult.isInit self.cardCurIndex = rewardResult.curIndex self.amountCardCount = #self.rewardList if self.amountCardCount == itemInViewCountTen then CTL.Sound.PlayGameSound("UI_double_open") end -- 设置操作区域 UIUtils.SetActive(self.PanelMid.gameObject, false) UIUtils.SetActive(self.UITemplateTitlePanel.gameObject, false) self:RefreshCostNum() UIUtils.SetLabelText(self.PanelMid.txt_Gacha10, self.isOriginDrawCardByOne and Const_IDS["IDS_DrawCard_Button_OneDrawAgain"] or Const_IDS["IDS_DrawCard_Button_TenDrawAgain"]) UIUtils.SetLabelText(self.PanelMid.txt_Gacha50, Const_IDS["IDS_Recruit_50Times"]) -- 设置奖励显示 UIUtils.SetActive(self.PanelMid.group_Info, rewardItem ~= nil) if rewardItem then UTL.Item.SetCurrencyImageIcon(self.PanelMid.img_RewardIcon, rewardItem.ItemId) UTL.Item.SetCurrencyImageIcon(self.PanelMid.img_RewardIcon50, rewardItem.ItemId) UIUtils.SetLabel(self.PanelMid.txt_Num, rewardItem.ItemCount) UIUtils.SetLabel(self.PanelMid.txt_Num50, amountCardFifty) end if isInit then self.aniInitCard = nil end if not self.isGachaFifty and not self.isGachaTenAgain then for i = 1, #self.Content do if self.rewardList[i] then UIUtils.SetActive(self.Content[i].gameObject, true) self:StopAllEffect(self.Content[i]) self:SetCardInfo(self.rewardList[i], self.Content[i], i) else UIUtils.SetActive(self.Content[i].gameObject, false) end end else table.sort(self.rewardList, SortRule) if self.isFristRoundCellInit == nil or self.isFristRoundCellInit == false then self.isFristRoundCellInit = true end self.group_Cell50:ClearCells() self.group_Cell50:ReloadAll(self.rewardList) end if isInit then -- 初始化播放声音和初始化卡牌动画 if self.amountCardCount == 1 then CTL.Sound.PlayGameSound("UI_single") else CTL.Sound.PlayGameSound("UI_double") end if not self.aniInitCard then self.aniInitCard = self:PlayUIAnimation(self.amountCardCount == 1 and SingleCardAppear or CardAppear, true) else self:PlayUIAnimation(self.aniInitCard, true) end rewardResult.isInit = false else self:PlayCardOpenAnimation() end self:ShowBasicUI() end function UIGachaGet:RefreshCostNum() local itemId, countInBag, costNum, itemStoreId = MDL.DrawCard.GetConstItemAndNum(MDL.DrawCard.GetCurCardPoolID()) UTL.Item.SetCurrencyImageIcon(self.PanelMid.img_Icon, itemId) local itemCostNum = self.isOriginDrawCardByOne and 1 or 10 UIUtils.SetLabel(self.PanelMid.txt_CostNum, CTL.ActivityGacha.GetGachaCostNumShow(itemId, itemCostNum)) UIUtils.SetLabel(self.PanelMid.txt_CostNum50, CTL.ActivityGacha.GetGachaCostNumShow(itemId, 50)) end function UIGachaGet:SetCardInfoDetail(data, cmp, index) local itemData = DataSheetManager.ItemData:GetDataByID(data.rewardItems[1].ItemId) UTL.Color.SetQualityImageByType(cmp.img_Qua, itemData.DrawCardColor, UTL.Color.QualityType.DrawCardBase) local heroId = UTL.Item.IsItemWholeHero(data.rewardItems[1].ItemId) if heroId then local heroData = DataSheetManager.HeroNum:GetDataByID(heroId) -- 武将整卡 UIUtils.SetActive(cmp.img_Hero, true) UTL.Item.SetHeroHalfCardImageByHeroId(cmp.img_Hero, heroId) local isNew = self.rewardNewDict[index] UIUtils.SetActive(cmp.img_New, isNew or false) if not isNew then -- 转换为武将碎片 UIUtils.SetActive(cmp.group_Name, true) local fragmentItemData = DataSheetManager.ItemData:GetDataByID(heroData.PieceItem) UIUtils.SetLabel(cmp.txt_Num, heroData.WreckPiece) end else UIUtils.SetActive(cmp.item_Hero.gameObject, true) UTL.Item.SetItemCell(cmp.item_Hero, data.rewardItems[1].ItemId, data.rewardItems[1].ItemCount) end self:SetCardEffect(cmp, itemData, heroId, self.cardCurIndex >= index and self.rewardNewDict[index] or false) end function UIGachaGet:SetCardInfo(data, cmp, index) -- 设置显示 UIUtils.SetActive(cmp.item_Hero.gameObject, false) UIUtils.SetActive(cmp.img_Hero, false) UIUtils.SetActive(cmp.img_New, false) UIUtils.SetActive(cmp.group_Name, false) if (self.rewardNum == amountCardFifty or self.isGachaTenAgain and self.cardCurIndex < itemInViewCountTen) and self.isFristRoundCellInit then return end self:SetCardInfoDetail(data, cmp, index) UIUtils.SetActive(cmp.group_Card, self.cardCurIndex >= index) end function UIGachaGet:DelaySetCardInfo(data, cmp, index) self:SetCardInfoDetail(data, cmp, index) UIUtils.SetActive(cmp.group_Card, true) end function UIGachaGet:PlayCardOpenAnimation() local rewardNum = #self.context.rewardList if self.cardCurIndex >= self.amountCardCount then UIUtils.SetActive(self.PanelMid.gameObject, true) UIUtils.SetActive(self.UITemplateTitlePanel.gameObject, true) self:StopRepeatFunc(self.OnUpdateFun) CTL.PlayerGuide.TryStartGaChaGuide() for _, v in ipairs (self.rewardList) do local heroId = UTL.Item.IsItemWholeHero(v.rewardItems[1].ItemId) if heroId then CTL.Sound.PlayGameSound("MUSiC_empty") CTL.Sound.ResumeLevelSound() break end end else local rewardData = self.rewardList[self.cardCurIndex + 1] local cmp = nil if rewardNum == amountCardFifty then return else cmp = self.Content[self.cardCurIndex + 1] end local itemData = DataSheetManager.ItemData:GetDataByID(rewardData.rewardItems[1].ItemId) local heroId = UTL.Item.IsItemWholeHero(rewardData.rewardItems[1].ItemId) CTL.Sound.PlayGameSound("UI_single_open") if heroId then local isNew = self.rewardNewDict[self.cardCurIndex + 1] if not self.isGachaFifty then self:PlayUIAnimation(HeroOpenCard, cmp.gameObject.transform) if isNew then if not self.aniMaskCard then self.aniMaskCard = self:PlayUIAnimation(HeroOpenCardMask, self.mask.transform, true) else if self.aniMaskCard ~= nil then self:PlayUIAnimation(self.aniMaskCard, true) end end UIUtils.SetActive(self.mask, true) self:StopRepeatFunc(self.OnUpdateFun) else UIUtils.SetActive(cmp.group_Card, true) if self.cardCurIndex == 0 then self:StartRepeatFunc(self.OnUpdateFun, 0.1) end end end self:PlayOpenCardEffect(cmp, itemData.DrawCardColor) else self:PlayUIAnimation(FragmentOpenCard, cmp.gameObject.transform) -- 如果当前是第一张卡 或者 上一张卡是武将整卡 启动计时器 if self.cardCurIndex == 0 or UTL.Item.IsItemWholeHero(self.rewardList[self.cardCurIndex].rewardItems[1].ItemId) then self:StartRepeatFunc(self.OnUpdateFun, 0.1) end UIUtils.SetActive(cmp.group_Card, true) end end end function UIGachaGet:StopAllEffect(cmp) cmp.effect_NewCard:StopUIEffect() cmp.effect_OrdinaryCard:StopUIEffect() cmp.effect_OrangeCardUp:StopUIEffect() cmp.effect_OrangeCardDown:StopUIEffect() cmp.effect_OrangeCardLight:StopUIEffect() cmp.effect_RedCardUp:StopUIEffect() cmp.effect_RedCardDown:StopUIEffect() cmp.effect_RedCardLight:StopUIEffect() end function UIGachaGet:PlayOpenCardEffect(cmp, color) if color == LuaConst.QualityColor.Orange then cmp.effect_OrangeCardLight:PlayUIEffect() elseif color == LuaConst.QualityColor.Red then cmp.effect_RedCardLight:PlayUIEffect() end end function UIGachaGet:SetCardEffect(cmp, itemData, heroId, isNew) self:StopAllEffect(cmp) if heroId then if itemData.DrawCardColor == LuaConst.QualityColor.Orange then cmp.effect_OrangeCardUp:PlayUIEffect() cmp.effect_OrangeCardDown:PlayUIEffect() elseif itemData.DrawCardColor == LuaConst.QualityColor.Red then cmp.effect_RedCardUp:PlayUIEffect() cmp.effect_RedCardDown:PlayUIEffect() end if isNew then cmp.effect_NewCard:PlayUIEffect() end else cmp.effect_OrdinaryCard:PlayUIEffect() end end function UIGachaGet:RequestDrawCard() local canBuy, ids = MDL.DrawCard.CanDrawCardByOne() if self.amountCardCount == itemInViewCountTen then canBuy, ids = MDL.DrawCard.CanDrawCardByTen() elseif self.amountCardCount == amountCardFifty then canBuy, ids = MDL.DrawCard.CanDrawCardByFifty() end if not canBuy then CTL.Tips.AddTipsMsg(ids) return end local itemId, countInBag, costNum, itemStoreId = MDL.DrawCard.GetConstItemAndNum(MDL.DrawCard.GetCurCardPoolID()) canBuy = self.amountCardCount == 1 and countInBag >= 1 or countInBag >= costNum if self.amountCardCount == amountCardFifty then canBuy = countInBag >= amountCardFifty end if canBuy then --购买 local isSkipAnim = MDL.DrawCard.GetIsSkipAnim() MDL.DrawCard.RequestDrawCard(MDL.DrawCard.GetCurCardPoolID(), self.amountCardCount, isSkipAnim, self.isOriginDrawCardByOne) else --弹出购买道具框 local store = MDL.OperationActivity.StoreGoodsData:GetDataByID(itemStoreId) local currencyID = store.MoneyID local currencyCount = store.BuyPrice UIManager.OpenView(Const_UI_Lua.UIEnum.UIItemBuyPanel, {ItemId = itemId, ItemStoreId = itemStoreId, CurrencyId = currencyID, CurrencyCount = currencyCount}) self.isGacha10Clickable = true self.isGacha50Clickable = true end end function UIGachaGet:OnCloseGamePlay() self:CloseView(true) end function UIGachaGet:OnClosed() UIUtils.SetActive(self.UITemplateTitlePanel.btn_Info, true) end function UIGachaGet:ShowBasicUI() UIUtils.SetActive(self.PanelMid.gameObject, true) UIUtils.SetActive(self.UITemplateTitlePanel.gameObject, true) end return UIGachaGet