local UISuperGoldLotteryMain = UIViewClass() local OneCycleCellCount = 9 --转动一圈格子数 local TotalPlayMinSeconds = 1 --最小播放时长(秒) local CycleCount = 2 --奖励物品品质 local RewardAtlas = "UI_SuperGoldenHero" local RewardQualityIcons = { [1] = "nd_bg_di01", [2] = "nd_bg_di02", [3] = "nd_bg_di03", [4] = "nd_bg_di04", [5] = "nd_bg_di05", [6] = "nd_bg_di06", } --region 生命周期方法 function UISuperGoldLotteryMain:OnOpened(context) self.activityId = context.activityId self.activityType = MDL.OperationActivity.ActivityType.SuperGold self:RegistSystemEvent(EventID.UI_SuperGoldLottery_RefreshUI,self.InitData) self:RegistSystemEvent(EventID.UI_SuperGoldLottery_PlayAnimation,self.DoPlayAnimation) self:RegistSystemEvent(EventID.UI_ChapterGoal_RewardPanelClose,self.ShowUnlockWindow) --奖励展示完毕显示解锁弹窗 self:RegistSystemEvent(EventID.UI_OperationActivity_CloseView, self.OnCloseActivitySelf) UIUtils.SetLabelText(self.UITemplateTitlePanel.lab_Title,Const_IDS.IDS_SuperGoldHeroActivity_Title6) --彩金扭蛋 使用独立的 hud CTL.SuperGoldMain.OpenCurrencyPanel(MDL.SuperGoldLottery.GetHeroType(self.activityId),self.__viewClassPath, self.currency_Info, {activityType = self.activityType, activityId = self.activityId, title = "IDS_DrawCard_Title_QuickBuy"}) self:InitData() CTL.SuperGoldMain.SetIsOpenedActivity(self.activityId, true) end function UISuperGoldLotteryMain:OnBackButtonPressed() self:OnButtonClicked(self.UITemplateTitlePanel.btn_close) end function UISuperGoldLotteryMain:OnButtonClicked(comp) if comp == self.UITemplateTitlePanel.btn_close then self:CloseView(true) elseif comp == self.UITemplateTitlePanel.btn_Home then CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.UITemplateTitlePanel.btn_Info then --玩法说明 local heroType = MDL.SuperGoldMain.GetHeroTypeByActivityId( self.activityId) local heroTypeData = DataSheetManager.SuperGoldActivityModeData:GetDataByHeroType(heroType) local itemName = UTL.Item.GetItemColorName(heroTypeData.ActivityItemID) UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.SuperGoldLottery,params = {itemName,itemName}}) elseif comp == self.btn_Probability then --概率预览(仅第四层出现) self:OnClickProbabilityPreview(self.selectIndex,true) elseif comp == self.btn_Spin1 then --抽一次 self:OnClickDraw(1) elseif comp == self.btn_Spin10 then --抽X次 local currentData = self.turnTableInfo[self.selectIndex] local drawCount = CTL.SuperGoldLottery.GetRemainDrawCountByTurnTable(self.activityId,currentData.TurnTableID) self:OnClickDraw(drawCount) else --Tab 点击 local currentTurnTableID = MDL.SuperGoldLottery.GetCurrentTurnTableID(self.activityId) for i = 1, #self.group_Tab do if comp == self.group_Tab[i].btn then local isLock = self.turnTableInfo[i].TurnTableID > currentTurnTableID if isLock then if i < #self.group_Tab then self:OnClickRewardPreview(i) return else self:OnClickProbabilityPreview(i) --最后一层显示概率预览 return end else self.selectIndex = i self:UpdateTabSelectShow() self:SelectTab(self.selectIndex) return end end end --道具点击 local currentData = self.turnTableInfo[self.selectIndex] local turnTableID = currentData.TurnTableID for i = 1 ,#self.group_Item do if comp == self.group_Item[i].event_Click then local rewardData = CTL.SuperGoldLottery.GetRewardData(turnTableID,i) UTL.ItemTips.ShowCommonTipsById(rewardData.Item) return end end end end function UISuperGoldLotteryMain:OnClosed() MDL.Reward.SetCloseNotExpTipShow(false) end --endregion function UISuperGoldLotteryMain:OnCloseActivitySelf(viewClassPath, activityId) if viewClassPath == self.__viewClassPath then if self.activityId and activityId == self.activityId then self:CloseView() end end end --isNotChangeSelectTab 不修改选中的tab function UISuperGoldLotteryMain:InitData(isNotChangeSelectTab) UIUtils.SetActive(self.clickMask,false) self:InitTab(isNotChangeSelectTab) self:SelectTab(self.selectIndex) end --奖池tab function UISuperGoldLotteryMain:InitTab(isNotChangeSelectTab) if not self.turnTableInfo then self.turnTableInfo = MDL.SuperGoldLottery.GetTurnTableInfo(self.activityId) end if #self.turnTableInfo ~= #self.group_Tab then logging.error(LTAG.ERROR,"奖池数据UI长度不匹配") return end local currentTurnTableID = MDL.SuperGoldLottery.GetCurrentTurnTableID(self.activityId) for i = 1, #self.group_Tab do local data = self.turnTableInfo[i] local tabItem = self.group_Tab[i] local isSelect = data.TurnTableID == currentTurnTableID local isLock = data.TurnTableID > currentTurnTableID --上次选中的Tab 不变 if isNotChangeSelectTab then isSelect = self.selectIndex == i end if isSelect then self.selectIndex = i end local isHasGetAll = not CTL.SuperGoldLottery.IsHasLeftRewardInLayer(self.activityId,data.TurnTableID) self:SetTabItem(data,tabItem,isSelect,isLock,isHasGetAll) end end --奖池tab子项数据 function UISuperGoldLotteryMain:SetTabItem(data,tabItem,isSelect,isLock,isHasGetAll) UIUtils.SetLabelText(tabItem.lab_Function,Const_IDS[data.StoreName]) UTL.Item.SetAtlasSprite(tabItem.img_Icon, "UI_SuperGoldenHero", data.StorePic) --选中 if isSelect then tabItem.effect_Tab:PlayUIEffect() else tabItem.effect_Tab:StopUIEffect() end --解锁UI UIUtils.SetActive(tabItem.img_Mask,isLock) --本层是否全部抽取完了 if isHasGetAll then tabItem.state_Color:SetState(1) else tabItem.state_Color:SetState(0) end --红点 local isShowRedPoint = CTL.SuperGoldLottery.IsCanLotteryByTurnTableID(self.activityId,data.TurnTableID) tabItem.btn:SetRedPoint(isShowRedPoint) end --抽取按钮 UI显示 function UISuperGoldLotteryMain:InitBtnUI() if self.selectIndex and self.turnTableInfo then local currentData = self.turnTableInfo[self.selectIndex] local drawCount = CTL.SuperGoldLottery.GetRemainDrawCountByTurnTable(self.activityId,currentData.TurnTableID) --最后一层显示概率预览按钮 UIUtils.SetActive(self.btn_Probability, self.selectIndex == #self.turnTableInfo) if drawCount == 0 then UIUtils.SetActive(self.btn_Spin1,false) UIUtils.SetActive(self.btn_Spin10,false) UIUtils.SetLabelText(self.lab_Notice,Const_IDS.IDS_SuperGoldHeroActivity_Turntable_Hint_3) return end UIUtils.SetActive(self.btn_Spin1,true) UIUtils.SetActive(self.btn_Spin10,true) UIUtils.SetLabelText(self.lab_Notice,Const_IDS.IDS_SuperGoldHeroActivity_Turntable_Hint_1) --单抽 UTL.Item.SetItemIcon(self.img_Icon_One,currentData.MoneyID) if UTL.Item.GetItemStockCount(currentData.MoneyID) < currentData.MoneyNum then UIUtils.SetLabel(self.txt_One,UTL.Color.FormatRedColor(tostring(currentData.MoneyNum))) self.btn_Spin1:SetRedPoint(false) else UIUtils.SetLabel(self.txt_One,tostring(currentData.MoneyNum)) self.btn_Spin1:SetRedPoint(true) end --N抽 UTL.Item.SetItemIcon(self.img_Icon_Ten,currentData.MoneyID) UIUtils.SetLabel(self.lab_DrawTen,string.FormatByIdsId(Const_IDS.IDS_SuperGoldHeroActivity_Turntable_Button_2,tostring(drawCount))) local needCost = currentData.MoneyNum*drawCount if UTL.Item.GetItemStockCount(currentData.MoneyID) < needCost then UIUtils.SetLabel(self.txt_Ten,UTL.Color.FormatRedColor(tostring(currentData.MoneyNum*drawCount))) self.btn_Spin10:SetRedPoint(false) else UIUtils.SetLabel(self.txt_Ten,tostring(currentData.MoneyNum*drawCount)) self.btn_Spin10:SetRedPoint(true) end end end --刷新Tab选中表现 function UISuperGoldLotteryMain:UpdateTabSelectShow() local currentTurnTableID = MDL.SuperGoldLottery.GetCurrentTurnTableID(self.activityId) for i = 1, #self.group_Tab do local data = self.turnTableInfo[i] local tabItem = self.group_Tab[i] local isSelect = i == self.selectIndex local isLock = data.TurnTableID > currentTurnTableID if isSelect then self.selectIndex = i end local isHasGetAll = not CTL.SuperGoldLottery.IsHasLeftRewardInLayer(self.activityId,data.TurnTableID) self:SetTabItem(data,tabItem,isSelect,isLock,isHasGetAll) end end function UISuperGoldLotteryMain:SelectTab(index) self.selectIndex = index --显示下一层提示 UIUtils.SetActive(self.img_Notice,self.selectIndex < #self.group_Tab) self:InitRewards() self:InitBtnUI() end --奖励物品 function UISuperGoldLotteryMain:InitRewards() local currentData = self.turnTableInfo[self.selectIndex] local turnTableID = currentData.TurnTableID self.currentBigReward = nil --转盘底盘图 UIUtils.SetImageByAssetBundle(self.img_DishBg, currentData.TurnTablePic) for i = 1,#self.group_Item do local item = self.group_Item[i] local rewardData = CTL.SuperGoldLottery.GetRewardData(turnTableID,i) UTL.Item.SetItemIcon(item.img_Item,rewardData.Item) UIUtils.SetLabel(item.txt_Num,tostring(rewardData.Num)) local hasGet = CTL.SuperGoldLottery.IsHasGetReward(self.activityId,turnTableID,i) UTL.Item.SetItemIcon(item.img_ItemMask,rewardData.Item) UIUtils.SetActive(item.img_ItemMask,hasGet) local goodsItem = DataSheetManager.ItemData:GetDataByID(rewardData.Item) UTL.Item.SetAtlasSprite(item.img_Quality, RewardAtlas, RewardQualityIcons[goodsItem.Color]) --大奖显示 if rewardData.BigPrizeNode > 0 and item.img_Mask then UIUtils.SetActive(item.img_Mask,false) self.currentBigReward = rewardData.RewardID --保存当前大奖道具顺序 elseif item.img_Mask then --最后一层不显示大奖 UIUtils.SetActive(item.img_Mask,true) end --抽取动画 UIUtils.SetActive(item.img_Light,false) self:AddToAniList(item.img_Light,hasGet,i,rewardData.Item) end end --点击奖励预览 function UISuperGoldLotteryMain:OnClickRewardPreview(index) if index ~= self.selectIndex then UIManager.OpenView(Const_UI_Lua.UIEnum.UISuperGoldLotteryReward,{activityId = self.activityId, index = index}) end end --点击概率预览 function UISuperGoldLotteryMain:OnClickProbabilityPreview(index,forceShow) if forceShow or index ~= self.selectIndex then UIManager.OpenView(Const_UI_Lua.UIEnum.UISuperGoldLotteryProbability,{activityId = self.activityId, index = index}) end end --点击抽取 count 抽取次数 function UISuperGoldLotteryMain:OnClickDraw(count) CTL.Sound.PlayGameSound("UI_open") local currentData = self.turnTableInfo[self.selectIndex] local needCost = count * currentData.MoneyNum if UTL.Item.GetItemStockCount(currentData.MoneyID) < needCost then local goodsItem = DataSheetManager.ItemData:GetDataByID(currentData.MoneyID) CTL.Tips.AddTipsMsg(string.FormatByIdsId(Const_IDS.IDS_DrawCard_Tip_LackItem,UIUtils.GetLocalizedTxt(Const_IDS[goodsItem.Name]))) return end --判断大于抽取次数时,不能点击;抽取 0次 不能点击 local drawCount = CTL.SuperGoldLottery.GetRemainDrawCountByTurnTable(self.activityId,currentData.TurnTableID) if count > drawCount or count == 0 then return end MDL.SuperGoldLottery.ActivityCapsuleSampleReq(self.activityId,currentData.TurnTableID,count) UIUtils.SetActive(self.clickMask,true) end --抽到大奖,显示解锁弹窗 function UISuperGoldLotteryMain:ShowUnlockWindow() if self.isGetBigReward then UIManager.OpenView(Const_UI_Lua.UIEnum.UISuperGoldLotteryUnlock,{activityId = self.activityId,index = self.selectIndex + 1}) end end --region 抽取动画 --添加抽取动画(实际是特效) function UISuperGoldLotteryMain:AddToAniList(effect,hasGet,index,itemId) if not hasGet then if not self.effectList then self.effectList = {} end table.insert(self.effectList,{index = index,effect = effect,itemId = itemId}) end end --播放一个格子的抽取动画、 --endIndex 动画停止的索引 --cycleCount 转的圈数 (先按圈数) function UISuperGoldLotteryMain:PlaySingleAnimation() if self.currentPlayEffectIndex > 1 then local lastEffectData = self.effectList[self.currentPlayEffectIndex - 1] UIUtils.SetActive(lastEffectData.effect,false) end local effectData = self.effectList[self.currentPlayEffectIndex] UIUtils.SetActive(effectData.effect,true) self.currentPlayEffectIndex = self.currentPlayEffectIndex + 1 CTL.Sound.PlayGameSound("UI_treasures_roll") --后1/4减速播放 if self.currentPlayEffectIndex >= #self.effectList *0.75 and self.beginSlowPlayAnimation == nil then self.beginSlowPlayAnimation = true self:StopRepeatFunc(self.PlaySingleAnimation) self:StartRepeatFunc(self.PlaySingleAnimation, TotalPlayMinSeconds/ OneCycleCellCount *2, #self.effectList - self.currentPlayEffectIndex + 1) end --动画播放完毕 if self.currentPlayEffectIndex > #self.effectList then --播放抽到的特效 local item = self.group_Item[effectData.index] CTL.Sound.PlayGameSound("UI_lifeup") item.effect_Stop:PlayUIEffect() self:StopRepeatFunc(self.PlaySingleAnimation) table.clear(self.effectList) --延迟1秒显示奖励弹窗 self:StartRepeatFunc(self.DelayShowRewardPanel, 1, 1) end end function UISuperGoldLotteryMain:DelayShowRewardPanel() CTL.Reward.ShowDelayReward() -- 此时弹出奖励信息显示 self:InitData(true) -- 刷UI end --播放抽奖动画 function UISuperGoldLotteryMain:DoPlayAnimation(rewards) local itemIndex = self:GetShowLastAnimation(rewards) self.isGetBigReward = self.currentBigReward and itemIndex == self.currentBigReward --抽到大奖标识 self:SetPlayAniListData(itemIndex) self.beginSlowPlayAnimation = nil --间隔时间用 播放秒数/最小格子数 ,控制大致播放时长,实际可能因为多转几个格子,会略长 self:StartRepeatFunc(self.PlaySingleAnimation, TotalPlayMinSeconds/ OneCycleCellCount /2, #self.effectList) end --获取需要展示动画的最后一个奖励格子 function UISuperGoldLotteryMain:GetShowLastAnimation(rewards) --多个奖励时,如果有大奖显示大奖,否则显示最后一个 if #rewards > 1 then for i, v in ipairs(rewards) do if v == self.currentBigReward then return self.currentBigReward end end return rewards[#rewards] else return rewards[1] end end --计算需要播放的特效列表 (转动一圈(排除已有的) + 实际需要转动的格子) function UISuperGoldLotteryMain:SetPlayAniListData(endIndex) local temp = {} --计算需要转动的格子 local endCount = 0 for i = 1, #self.effectList do if self.effectList[i].index == endIndex then endCount = i end end local playCount = CycleCount * #self.effectList + endCount --这里按两圈来算 for i = 1 ,playCount do if i <= #self.effectList then table.insert(temp, self.effectList[i]) elseif i <= CycleCount * #self.effectList then table.insert(temp, self.effectList[i - #self.effectList]) else table.insert(temp, self.effectList[i - CycleCount*#self.effectList]) end end self.effectList = temp self.currentPlayEffectIndex = 1 end --endregion return UISuperGoldLotteryMain