local UIHeroSelectShowPanel = require "View/HeroSelect/UIHeroSelectShowPanel" local UIHeroLoadingShowPanel = UIViewClass(UIHeroSelectShowPanel) local speedShowFormatStr = "%s/S" local heroStageDic = {} --key:heroId value:stage 改成upvalue是因为排序要用到 --下载->品质 local function SortRule(heroNumConfig_1, heroNumConfig_2) local curStage = LoginProxy.GetCurStage() local isFinishDownload_1 = curStage >= heroStageDic[heroNumConfig_1.ID] local isFinishDownload_2 = curStage >= heroStageDic[heroNumConfig_2.ID] if isFinishDownload_1 == isFinishDownload_2 then local heroQuality_1 = heroNumConfig_1.HeroQuality local heroQuality_2 = heroNumConfig_2.HeroQuality if heroQuality_1 == heroQuality_2 then return heroNumConfig_1.ID > heroNumConfig_2.ID else return heroQuality_1 > heroQuality_2 end else return isFinishDownload_1 end end local WifiDownloadTip = "HeroSelect/UIDownloadTips" local INTERVAL_GET_SPEED = 1.5 ---------------------------------------------- 系统函数 ---------------------------------------------------------- function UIHeroLoadingShowPanel:OnCreated() speedShowFormatStr = string.FormatByIdsKey("IDS_DownloadSpeed", "%s/S") self.isHasShowDownloadTip = false self.nonOperTime = 0 --玩家不操作的时间 self.progressMat = self.group_LoadingShow.img_ProgressBar.material self.blurProgressMat = self.group_LoadingShow.BlurTips.img_ProgressFrame_Complete.material self.NonOperTimeInterval = DataSheetManager.ConstData:GetDataByID("LoadingHeroShowVoidTime").IntValue --key:heroId value:cell self.refreshCell = {} self.heroDownLoadProgress = 1 self.selectedIndex = -1 self.group_LoadingShow.BlurTips.img_Bottom:StopUpdateTexture() end function UIHeroLoadingShowPanel:OnOpened() self.hasStartShowSpeed = false self:RegistSystemEvent(EventID.UI_Loading_UpdateDownloadProgress, self.UpdateDownloadProgress) self:RegistSystemEvent(EventID.UpdateDownloadState, self.SetDownloadBtn) self:RegistSystemEvent(EventID.Pause_Download, self.OnDownloadPause) self:RegistSystemEvent(EventID.UI_StagePackage_AllDownload, self.OnPackFinish) self:RegistSystemEvent(EventID.OnPerPackFinish, self.OnPerPackFinish) self.currentSkillGroupIndex = 1 --当前技能组显示索引 self.maxDownloadSize = CTL.HotFix.GetStage1TotalDownloadSize() self.hasDownloadSize = CTL.HotFix.GetStage1DownloadedSize(LoginProxy.GetCurStage()) UIManager.ActiveUIModle(false, "UIHeroLoadingShowPanel") end function UIHeroLoadingShowPanel:OnPackFinish() self:CloseView() CTL.Login.ShowLoginUI() end function UIHeroLoadingShowPanel:InitPanel() UIHeroSelectShowPanel.InitPanel(self) UIUtils.SetActive(self.group_LoadingShow.gameObject, true) CTL.Sound.PlayGameSound("MUSIC_Login") -- 首次AB下载 if not GameAppInfo.IsPCPackage() then self:StartRepeatFunc(self.OnUpdateFun, 0, -1, true, false) end self.curPercent = 0 self:SetDownloadPercent(self.curPercent) self:InitHeroData() end function UIHeroLoadingShowPanel:OnUpdateFun(deltaTime, timeSinceUpdate) if not self.isHasShowDownloadTip then self.isHasShowDownloadTip = true UIManager.OpenView(WifiDownloadTip) end if UnityEngine.Input.anyKey then self.nonOperTime = 0 return end self.nonOperTime = self.nonOperTime+deltaTime --一段时间后关掉小提示界面,防止后面模糊屏的时候截图黑色 if self.nonOperTime>=self.NonOperTimeInterval-5 and self.nonOperTime-deltaTime=self.NonOperTimeInterval and self.nonOperTime-deltaTime #self.activeSkillList then self.currentSkillGroupIndex = 1 end self:RefreshActiveSkill() else for index, cell in ipairs(self.group_LoadingShow.group_ActiveSkill) do if comp == cell.btn_Skill then local eventClickPos = self.group_LoadingShow.gameObject.transform:InverseTransformVector(cell.btn_Skill.transform.position); local offsetX = index == 1 and 300 or 180 self.group_LoadingShow.ActiveSkillTips.gameObject.transform:SetAnchoredPosition(eventClickPos.x+offsetX, eventClickPos.y-350) CTL.Tips.CloseSkillTips(self.group_LoadingShow.ActiveSkillTips) if index == 1 then CTL.Tips.OpenSkillTips(self.activeSkillList[self.currentSkillGroupIndex][index], self.group_LoadingShow.ActiveSkillTips, CTL.Tips.SkillType.PassiveSkill, false) else CTL.Tips.OpenSkillTips(self.activeSkillList[self.currentSkillGroupIndex][index], self.group_LoadingShow.ActiveSkillTips, CTL.Tips.SkillType.ActiveSkill, false) end return end end end end function UIHeroLoadingShowPanel:OnClosed() self.progressMat = nil self.blurProgressMat = nil UIManager.ActiveUIModle(true, "UIHeroLoadingShowPanel") end ------------------------------------------------------------------------------------------------------------------- -------------------------------------------- 循环列表函数 -------------------------------------------------------- function UIHeroLoadingShowPanel:OnCellInit(scrollRect, index, cellTable, data) -- 不显示上阵图标和助战图标 UIUtils.SetActive(cellTable.sprite_BgZhen.gameObject, false) UIUtils.SetActive(cellTable.img_AssistanceIcon, false) --不显示爵位图标 UIUtils.SetActive(cellTable.img_Rank, false) -- 不显示等级 UIUtils.SetActive(cellTable.img_BreakLevelBg, false) UIUtils.SetActive(cellTable.txt_Lv, false) UIUtils.SetActive(cellTable.sprite_back, false) UIUtils.SetActive(cellTable.img_QualityLv, false) UTL.Color.SetQualityImageByType(cellTable.img_QualityFrame, data.HeroQuality, UTL.Color.QualityType.HeroSelectFrame) UTL.Color.SetQualityImageByType(cellTable.img_QualityHead, data.HeroQuality, UTL.Color.QualityType.HeroSelectBg) --主将碎片相关 UIUtils.SetActive(cellTable.group_Shards.gameObject, false) UIUtils.SetActive(cellTable.img_unlock, false) cellTable.cell:SetRedPoint(false) cellTable.btn_ClickItem:SetGray(false) -- 设置主将头像 UTL.Item.SetHeroIconByHeroId(cellTable.btn_ClickItem, data.ID) UTL.Item.SetHeroIconByHeroId(cellTable.img_Mask, data.ID) self.refreshCell[data.ID] = cellTable self:UpdateCellItemByHeroId(data.ID, cellTable) end function UIHeroLoadingShowPanel:UpdateCellItemByHeroId(heroId, cellTable) local curStage = LoginProxy.GetCurStage() local heroStage = heroStageDic[heroId] if curStage < heroStage then if heroStage == CTL.HotFix.GetNextStage() then UIUtils.SetAtlasImageFillAmount(cellTable.img_Mask, self:GetDownLoadProgress()) else UIUtils.SetAtlasImageFillAmount(cellTable.img_Mask, 1) end UIUtils.SetActive(cellTable.btn_Mask, true) UIUtils.SetActive(cellTable.lab_Download, true) UIUtils.SetLabelText(cellTable.lab_Download, Const_IDS.IDS_StagePackage_Downloading) else UIUtils.SetActive(cellTable.btn_Mask, false) UIUtils.SetActive(cellTable.lab_Download, false) UIUtils.SetLabel(cellTable.lab_Download, nil) end end function UIHeroLoadingShowPanel:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.group_LoadingShow.loopScroll_Heads then if target == cellTable.btn_Mask then local heroStage = heroStageDic[data.ID] if heroStage and LoginProxy.GetCurStage() < heroStage then self.group_LoadingShow.loopScroll_Heads:SelectIndex(self.selectedIndex) CTL.Tips.AddTipsMsg(Const_IDS["IDS_DownLoadingHeroShow_AllShowTips"]) return end end --索引值可能会变,用来防止连点不准确,改成武将id self.selectedIndex = index if self.selectedId == data.ID then return end self:OnButtonClicked(self.group_LoadingShow.btn_Empty_Bottom) self.selectedId = data.ID self:RefreshHeroData(self.selectedId) self:CreatHeroObj(self.selectedId) end end --0表示完成 function UIHeroLoadingShowPanel:GetDownLoadProgress() if LoginProxy.GetCurStage() >= self.maxHeroStage then return 0 end return self.heroDownLoadProgress end function UIHeroLoadingShowPanel:RefreshHeroDownLoadProgress() for heroId, cell in pairs(self.refreshCell) do self:UpdateCellItemByHeroId(heroId, cell) end end function UIHeroLoadingShowPanel:RefreshHeroData(heroId) self.currentSkillGroupIndex = 1 --当前技能组显示索引 UIHeroSelectShowPanel.RefreshHeroData(self, heroId) self:RefreshActiveSkill() end ------------------------------------------------------------------------------------------------------------------- function UIHeroLoadingShowPanel:InitHeroData() self.heroList = {} for i,v in DataSheetManager.StageHero:GetEnumerator() do if v.StageType == 1 and v.WhetherDisplay == 1 and v.ShowStage >=0 and v.ShowStage <= 1 then --只显示分包1的武将 local data = DataSheetManager.HeroNum:GetDataByID(v.ID) table.insert(self.heroList, data) --最开始的版本要求1G上限的aab包(无PAD)要带有几个高模,然后在分包1界面下载时可见 --为了尽量精简,首包里只保留了高模的Timeline,而将高模的attach资源(模型、变体)挪到分包1 --能这么处理是因为Timeline在引用模型时,用的静态依赖;后来开始启用Timeline动态依赖模型,就会由于模型和Timeline的分包不一致,表现出错 --目前已经没有1G上限aab的需求了,移除首包内对高模attach资源的特殊处理,这样Timeline和模型就能在同一个分包内 --理论上Timeline和高模在同一个分包内,如果出包离包体上限还有空余会按照从小到大将资源填进包内,可能会导致Timeline和高模不在同一分包 --因此,应该取较大值才是正确的武将分包 local heroStage = math.max(AuxUtil.GetAssetBundleStage(UTL.UIRender.GetModelPath(v.ID, true)), AuxUtil.GetAssetBundleStage(data.PreviewTimeline)) heroStageDic[v.ID] = heroStage if self.maxHeroStage == nil or heroStage > self.maxHeroStage then self.maxHeroStage = heroStage end end end table.sort(self.heroList, SortRule) self.group_LoadingShow.loopScroll_Heads:ReloadAll(self.heroList) self:RefreshHeroDownLoadProgress() self.group_LoadingShow.loopScroll_Heads:SelectIndex(0) self.nonOperTime = 0 end --完成每个Pack下载时,需要调整排序ReloadAll function UIHeroLoadingShowPanel:OnPerPackFinish(stage) self.hasStartShowSpeed = false self:StopRepeatFunc(self.ShowDownloadSpeed) if stage <= self.maxHeroStage then table.sort(self.heroList, SortRule) table.clear(self.refreshCell) self.group_LoadingShow.loopScroll_Heads:ReloadAll(self.heroList) local lastSelectIndex = 0 for i, v in ipairs(self.heroList) do if v.ID == self.selectedId then lastSelectIndex = i - 1 break end end self.group_LoadingShow.loopScroll_Heads:SelectIndex(lastSelectIndex) end end local SkillPath = ConstAssetPathConfig.SkillImagePath function UIHeroLoadingShowPanel:RefreshActiveSkill() self.activeSkillList = MDL.HeroSelect.GetHeroDisplaySkillIdList(self.selectedId, true) --多套技能显示切换展示按钮 UIUtils.SetActive(self.group_LoadingShow.btn_Change, #self.activeSkillList > 1) for index, cell in ipairs(self.group_LoadingShow.group_ActiveSkill) do local skillData = DataSheetManager.SkillTipsData:GetDataByID(self.activeSkillList[self.currentSkillGroupIndex][index]) UIUtils.SetImageByAssetBundle(cell.sprite_Skill, string.format(SkillPath, skillData.SkillIcon)) end end --底层获取的速度:每秒速度相加总和/相加总次数,当下载开始1s后才开始计算 --每一个pack的开始,都会重置上一次速度的计算,下一个pack就需要等待1s --因此这里错开时间去取速度 function UIHeroLoadingShowPanel:ShowDownloadSpeed() local speed = LoginProxy.GetDownloadSpeed() self.group_LoadingShow.txt_DownLoadingSpeed.text = string.format(speedShowFormatStr, UTL.String.TransferKiloBytesSize(speed)) self.group_LoadingShow.BlurTips.txt_DownLoadingSpeed.text = string.format(speedShowFormatStr, UTL.String.TransferKiloBytesSize(speed)) end function UIHeroLoadingShowPanel:UpdateDownloadProgress(curSize, maxSize, _) if not curSize or not maxSize then return end if LoginProxy.GetCurStage() < self.maxHeroStage then self.heroDownLoadProgress = (maxSize - curSize) / maxSize self:RefreshHeroDownLoadProgress() end local curSize = curSize + self.hasDownloadSize local maxSize = self.maxDownloadSize local percent = curSize / maxSize if not self.group_LoadingShow.img_ProgressBarBg.gameObject.activeSelf then UIUtils.SetActive(self.img_ProgressBarBg, true) end self.curPercent = percent self.group_LoadingShow.txt_DownLoading.text = string.FormatByIdsKey("IDS_DownloadResources", UTL.String.TransferKiloBytesSize(curSize), UTL.String.TransferKiloBytesSize(maxSize)) self.group_LoadingShow.BlurTips.txt_DownLoading.text = string.FormatByIdsKey("IDS_DownloadResources", UTL.String.TransferKiloBytesSize(curSize), UTL.String.TransferKiloBytesSize(maxSize)) self.group_LoadingShow.txt_Schedule.text = string.format("%d%%", self.curPercent * 100) self.group_LoadingShow.BlurTips.txt_Progress.text = string.format("%d%%", self.curPercent * 100) self:SetDownloadPercent(self.curPercent) if self.hasStartShowSpeed == false then self.hasStartShowSpeed = true self:StartRepeatFunc(self.ShowDownloadSpeed, INTERVAL_GET_SPEED, 0) end end function UIHeroLoadingShowPanel:SetDownloadPercent(percent) self.progressMat:SetFloat("_Percent", percent) self.blurProgressMat:SetFloat("_Percent", percent) percent = percent-0.045 local radius = 48 self.group_LoadingShow.effect_LightPoint.transform:SetLocalPosition(math.sin(percent*math.pi*2)*radius, math.cos(percent*math.pi*2)*radius) self.group_LoadingShow.BlurTips.effect_LightPoint.transform:SetLocalPosition(math.sin(percent*math.pi*2)*radius, math.cos(percent*math.pi*2)*radius) end --下载暂停,将下载速度置零 function UIHeroLoadingShowPanel:OnDownloadPause() local curSize = CTL.HotFix.GetLastDownloadSize() local maxSize = self.maxDownloadSize self:UpdateDownloadProgress(curSize, maxSize, 0) end function UIHeroLoadingShowPanel:SetDownloadBtn(isShow) UIUtils.SetActive(self.group_LoadingShow.btn_Download, isShow) self.hasDownloadSize = CTL.HotFix.GetStage1DownloadedSize(LoginProxy.GetCurStage()) self:RefreshHeroDownLoadProgress() end return UIHeroLoadingShowPanel