local UIPack2DownloadTip = UIViewClass() local CONST_STAGE_GROUP = 2 function UIPack2DownloadTip:OnOpened(context) NotSyncBattleSetter.StopAutoFightPathInTown() self:RegistSystemEvent(EventID.UpdateDownloadState, self.UpdateDownloadState) self:RegistSystemEvent(EventID.Pause_Download, self.UpdateDownloadState) self:RegistSystemEvent(EventID.Resume_Download, self.UpdateDownloadState) self:RegistSystemEvent(EventID.UI_Loading_UpdateDownloadProgress, self.UpdateProgress) self:RegistSystemEvent(EventID.OnPerPackFinish, self.UpdateState) self:ShowReward() self:UpdateDownloadState() self:UpdateProgress(CTL.HotFix.GetLastDownloadSize()) self:UpdateState() end function UIPack2DownloadTip:UpdateDownloadSize() local minStage = CTL.HotFix.GetGroupMinStage(CONST_STAGE_GROUP) local maxStage = CTL.HotFix.GetGroupMaxStage(CONST_STAGE_GROUP) local curStage = LoginProxy.GetCurStage() if curStage > maxStage then self.hasDownloadSize = CTL.HotFix.GetSeriesStageSize(minStage, maxStage) elseif curStage < minStage then self.hasDownloadSize = 0 else self.hasDownloadSize = CTL.HotFix.GetSeriesStageSize(minStage, curStage) end self.totalSize = UTL.String.TransferKiloBytesSize(CTL.HotFix.GetSeriesStageSize(minStage, maxStage)) end function UIPack2DownloadTip:UpdateProgress(curSize, maxSize, speed) if self:GetIfDownloadFinish() == false then self.text_progress.text = string.FormatByIdsId(Const_IDS.IDS_FlowDownloadPackageSizeNotice, UTL.String.TransferKiloBytesSize(curSize + self.hasDownloadSize) .. "/" .. self.totalSize) else self.text_progress.text = nil end end function UIPack2DownloadTip:UpdateState() if self:GetIfDownloadFinish() then self.text_progress.text = nil self.img_Title_State:SetState(1) self.state_middle:SetState(1) else self.img_Title_State:SetState(0) self.state_middle:SetState(0) end end function UIPack2DownloadTip:ShowReward() local id = DataSheetManager.ConstData:GetDataByID("ResourceDownloadGift").IntListValue[1] local awardData = DataSheetManager.StagePackageReward:GetDataByID(id) self.scroll_Reward:ReloadAll(awardData.Item_Table) end function UIPack2DownloadTip:OnCellInit(scrollRect, index, cellTable, data) UTL.Item.SetItemCell(cellTable.item, data.ItemID, data.ItemNum) end function UIPack2DownloadTip:OnCellClicked(scrollRect, index, cellTable, target, data) UTL.ItemTips.ShowCommonTipsById(data.ItemID) end function UIPack2DownloadTip:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() elseif comp == self.btn_Get then if self:GetIfDownloadFinish() == false then local hasTask = false local taskList = MDL.Task.GetTaskList(MDL.Task.Enum_TaskType.PackageSpecifiedRingTask) if taskList then for _, v in pairs(taskList) do CTL.Task.DoTask(v) hasTask = true break end end if hasTask == false then MDL.HotFix.StartPackageBaoDownLoadReq(1) end else local taskList = MDL.Task.GetTaskList(MDL.Task.Enum_TaskType.Major) if taskList then for _, v in pairs(taskList) do CTL.Task.DoTask(v) break end end end CTL.HomeMain.CloseViewBackHomeMain() elseif comp == self.btn_Pause then if CTL.HotFix.IsDownloading() then CTL.HotFix.PauseDownload() else CTL.HotFix.ContinueDownloadStage() end end end function UIPack2DownloadTip:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UIPack2DownloadTip:UpdateDownloadState() self:UpdateDownloadSize() if CTL.HotFix.Get_IsWifi() or self:GetIfDownloadFinish() then UIUtils.SetActive(self.btn_Pause, false) else UIUtils.SetActive(self.btn_Pause, true) if LoginProxy.Get_IsPauseDownload() or CTL.HotFix.IsDownloading() == false then self.btn_State:SetState(0) else self.btn_State:SetState(1) end end end function UIPack2DownloadTip:GetIfDownloadFinish() if UNITY_EDITOR then return CTL.HotFix.CheatFinishPack2 end return CTL.HotFix.IsStage2Finished() end return UIPack2DownloadTip