local UIStagePackage = UIViewClass() local REWARD_KEY = 10101 --奖励id local StageState = { Downloading = 1, Wait = 2, Complete = 3, } local function SortRule(a, b) if a.state ~= b.state then return a.state < b.state end return a.stage < b.stage end function UIStagePackage:GetStageState(stageGroup, downloadStageGroup) if downloadStageGroup == stageGroup then return StageState.Downloading elseif downloadStageGroup > stageGroup then return StageState.Complete else return StageState.Wait end end function UIStagePackage:OnCreated() self.infoList = {} for _, v in DataSheetManager.StageEnum:GetEnumerator() do if (v.ID == 1 and DEF.USE_SMALL_APK) or v.ID ~= 1 then local stageGroup = v.ID local stage = CTL.HotFix.GetGroupMaxStage(stageGroup) local info = { stage = stage, maxSize = CTL.HotFix.GetStageGroupSize(stageGroup), curSize = 0, config = v, } table.insert(self.infoList, info) end end end function UIStagePackage:OnOpened() self:RegistSystemEvent(EventID.UpdateDownloadState, self.UpdateDownloadState) self:RegistSystemEvent(EventID.UI_StagePackage_ForceDownload, self.OnForceDownload) self:RegistSystemEvent(EventID.UI_Loading_UpdateDownloadProgress, self.UpdateProgress) self:RegistSystemEvent(EventID.Pause_Download, self.UpdateDownloadState) self:RegistSystemEvent(EventID.Resume_Download, self.UpdateDownloadState) self:UpdateDownloadState() local state = CTL.HotFix.Get_IfAllDownload() self.btn_Collect:SetGray(not state, true) self.btn_Collect:SetRedPoint(state) --奖励展示 if MDL.HotFix.Get_HasStagePackageAward() then --已经领过奖的不显示 UIUtils.SetActive(self.btn_Collect, false) else UIUtils.SetActive(self.btn_Collect, true) self:RegistSystemEvent(EventID.UI_StagePackage_AllDownload, self.OnAllDownload) local awardData = DataSheetManager.StagePackageReward:GetDataByID(REWARD_KEY) self.scroll_RewardPreview:ReloadAll(awardData.Item_Table) end UIUtils.SetActive(self.toggle_UseCarrier, not GameAppInfo.IsPCPackage()) self:UpdateProgress(CTL.HotFix.GetLastDownloadSize()) end function UIStagePackage:OnForceDownload() UIUtils.SetActive(self.btn_Close, false) UIUtils.SetActive(self.btn_Collect, false) self.scroll_RewardPreview:ClearCells() end function UIStagePackage:UpdateDownloadState() self:UpdateToggleClick() if CTL.HotFix.Get_IfAllDownload() then self:OnAllDownload() return end if LoginProxy.Get_IsDownloading() == false then local nextStageGroup = CTL.HotFix.GetStageNum(CTL.HotFix.GetNextStage()) for _, info in ipairs(self.infoList) do local stageGroup = CTL.HotFix.GetStageNum(info.stage) if nextStageGroup > stageGroup then info.state = StageState.Complete else info.state = StageState.Wait end end table.sort(self.infoList, SortRule) self.loop_Chapters:ReloadAll(self.infoList) else self:UpdateShow(CTL.HotFix.GetNextStage()) end end function UIStagePackage:UpdateShow(stage) local downloadStageGroup = CTL.HotFix.GetStageNum(stage) --更新每个Stage的状态 for _, info in ipairs(self.infoList) do local stageGroup = CTL.HotFix.GetStageNum(info.stage) info.state = self:GetStageState(stageGroup, downloadStageGroup) end table.sort(self.infoList, SortRule) self.loop_Chapters:ReloadAll(self.infoList) end function UIStagePackage:UpdateProgress(curSize, maxSize) local info = self.infoList[1] if info then local leftSize = CTL.HotFix.GetStageGroupLeftKiloBytes(curSize) info.curSize = info.maxSize - leftSize self.loop_Chapters:UpdateIndex(0, info) end end function UIStagePackage:OnAllDownload() local state = CTL.HotFix.Get_IfAllDownload() self.btn_Collect:SetGray(not state, false) self.btn_Collect:SetRedPoint(state) for _, info in ipairs(self.infoList) do info.state = StageState.Complete end table.sort(self.infoList, SortRule) self.loop_Chapters:ReloadAll(self.infoList) end function UIStagePackage:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Chapters then local ids = data.config.StageEnumName local path = data.config.StageEnumImage UIUtils.SetLabelText(cellTable.txt_Chapter, Const_IDS[ids]) UIUtils.SetImageByAssetBundle(cellTable.img_ChapterBackground, path) if data.state == StageState.Wait then cellTable.obj_state:SetState(0) local progress = 0 if data.maxSize > 0 then progress = data.curSize / data.maxSize end cellTable.img_DownLoadFrameProgress.fillAmount = progress cellTable.img_BlackCover.fillAmount = 1 - progress cellTable.txt_Percentage.text = string.format("%u%%", math.floor(progress * 100)) local curSizeShow = UTL.Color.FormatTextByColor("ffdb5e", UTL.String.TransferKiloBytesSize(data.curSize)) cellTable.txt_Progress.text = string.format("%s/%s", curSizeShow, UTL.String.TransferKiloBytesSize(data.maxSize)) UIUtils.SetLabelText(cellTable.txt_State, Const_IDS.IDS_StagePackage_DownloadState_LineUp) elseif data.state == StageState.Downloading then cellTable.obj_state:SetState(1) local progress = 0 if data.maxSize > 0 then progress = data.curSize / data.maxSize end cellTable.img_DownLoadFrameProgress.fillAmount = progress cellTable.img_BlackCover.fillAmount = 1 - progress cellTable.txt_Percentage.text = string.format("%u%%", math.floor(progress * 100)) local curSizeShow = UTL.Color.FormatTextByColor("ffdb5e",UTL.String.TransferKiloBytesSize(data.curSize)) cellTable.txt_Progress.text = string.format("%s/%s", curSizeShow, UTL.String.TransferKiloBytesSize(data.maxSize)) local content = UTL.Color.GetColorfulText("6FEEA5","IDS_StagePackage_DownloadState_Downloading") cellTable.txt_State.text = content else cellTable.obj_state:SetState(2) cellTable.img_DownLoadFrameProgress.fillAmount = 1 cellTable.img_BlackCover.fillAmount = 0 cellTable.txt_Percentage.text = "100%" local maxSize = UTL.String.TransferKiloBytesSize(data.maxSize) cellTable.txt_Progress.text = string.format("%s/%s", maxSize, maxSize) local content = UTL.Color.GetColorfulText("EEBD6F","IDS_StagePackage_DownloadState_Completed") cellTable.txt_State.text = content end else UTL.Item.SetItemCell(cellTable.item, data.ItemID, data.ItemNum) end end function UIStagePackage:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.scroll_RewardPreview then UTL.ItemTips.ShowCommonTipsById(data.ItemID) end end function UIStagePackage:OnBackButtonPressed() if not NetManager.IsLaunch() then self:OnButtonClicked(self.btn_Close) else SDKUtil.Exit() end end function UIStagePackage:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() elseif comp == self.btn_Collect then if CTL.HotFix.Get_IfAllDownload() then MDL.HotFix.StagePackageAwardRequest() else CTL.Tips.AddTipsMsg(Const_IDS["IDS_StagePackage_DownloadUnfinishedCanNotTake"]) end end end function UIStagePackage:OnValueChanged(comp, state) if comp == self.toggle_UseCarrier then if UNITY_IOS and GameAppInfo.IsVietnamPackage() then CTL.HotFix.Set_IsDownloadAnyway(state) else CTL.HotFix.Set_IsAllowCarrier(state) end end end function UIStagePackage:UpdateToggleClick() self.toggle_UseCarrier:SetIsOnWithoutNotify(CTL.HotFix.Get_IsAllowCarrier() or CTL.HotFix.IsDownloading()) end return UIStagePackage