diff --git a/osu.Game/Beatmaps/Drawables/BundledBeatmapDownloader.cs b/osu.Game/Beatmaps/Drawables/BundledBeatmapDownloader.cs index 6b14ed760d..5937186705 100644 --- a/osu.Game/Beatmaps/Drawables/BundledBeatmapDownloader.cs +++ b/osu.Game/Beatmaps/Drawables/BundledBeatmapDownloader.cs @@ -1,37 +1,55 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using osu.Framework.Allocation; using osu.Framework.Graphics.Containers; using osu.Framework.Utils; +using osu.Game.Database; +using osu.Game.Online; +using osu.Game.Online.API; +using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; +using osu.Game.Overlays; namespace osu.Game.Beatmaps.Drawables { public class BundledBeatmapDownloader : CompositeDrawable { - [Resolved] - private BeatmapModelDownloader beatmapDownloader { get; set; } + public IEnumerable DownloadTrackers => downloadTrackers; + + private readonly List downloadTrackers = new List(); [BackgroundDependencyLoader] - private void load() + private void load(BeatmapManager beatmapManager, IAPIProvider api, INotificationOverlay notifications) { + var beatmapDownloader = new BundledBeatmapModelDownloader(beatmapManager, api) + { + PostNotification = notifications.Post + }; + foreach (string filename in bundled_beatmap_filenames.OrderBy(_ => RNG.NextSingle()).Take(10)) { var match = Regex.Match(filename, @"([0-9]*) (.*) - (.*)\.osz"); - beatmapDownloader.Download(new APIBeatmapSet + var beatmapSet = new APIBeatmapSet { OnlineID = int.Parse(match.Groups[1].Value), Artist = match.Groups[2].Value, Title = match.Groups[3].Value, - }); + }; + + var beatmapDownloadTracker = new BeatmapDownloadTracker(beatmapSet); + downloadTrackers.Add(beatmapDownloadTracker); + AddInternal(beatmapDownloadTracker); + + beatmapDownloader.Download(beatmapSet); } } - private static readonly string[] bundled_beatmap_filenames = new[] + private static readonly string[] bundled_beatmap_filenames = { "682286 Yuyoyuppe - Emerald Galaxy.osz", "682287 baker - For a Dead Girl+.osz", @@ -223,5 +241,26 @@ private void load() "1009907 James Landino & Kabuki - Birdsong.osz", "1015169 Thaehan - Insert Coin.osz", }; + + private class BundledBeatmapModelDownloader : BeatmapModelDownloader + { + public BundledBeatmapModelDownloader(IModelImporter beatmapImporter, IAPIProvider api) + : base(beatmapImporter, api) + { + } + + protected override ArchiveDownloadRequest CreateDownloadRequest(IBeatmapSetInfo set, bool minimiseDownloadSize) + => new BundledBeatmapDownloadRequest(set, minimiseDownloadSize); + + public class BundledBeatmapDownloadRequest : DownloadBeatmapSetRequest + { + protected override string Uri => $"https://assets.ppy.sh/client-resources/bundled/{Model.OnlineID}.osz"; + + public BundledBeatmapDownloadRequest(IBeatmapSetInfo beatmapSetInfo, bool minimiseDownloadSize) + : base(beatmapSetInfo, minimiseDownloadSize) + { + } + } + } } } diff --git a/osu.Game/Overlays/FirstRunSetup/ScreenBundledBeatmaps.cs b/osu.Game/Overlays/FirstRunSetup/ScreenBundledBeatmaps.cs index fae852860b..97f429bcf2 100644 --- a/osu.Game/Overlays/FirstRunSetup/ScreenBundledBeatmaps.cs +++ b/osu.Game/Overlays/FirstRunSetup/ScreenBundledBeatmaps.cs @@ -2,12 +2,15 @@ // See the LICENCE file in the repository root for full licence text. using System.ComponentModel; +using System.Linq; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Game.Beatmaps.Drawables; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; +using osu.Game.Online; +using osuTK.Graphics; namespace osu.Game.Overlays.FirstRunSetup { @@ -16,6 +19,9 @@ public class ScreenBundledBeatmaps : FirstRunSetupScreen { private TriangleButton downloadButton; + private ProgressBar progressBar; + private BundledBeatmapDownloader downloader; + [BackgroundDependencyLoader] private void load() { @@ -34,14 +40,33 @@ private void load() Origin = Anchor.TopCentre, Text = "Download beatmap selection", Action = download - } + }, }; + + downloadButton.Add(progressBar = new ProgressBar(false) + { + RelativeSizeAxes = Axes.Both, + Blending = BlendingParameters.Additive, + FillColour = Color4.Aqua, + Alpha = 0.5f, + Depth = float.MinValue + }); } private void download() { - AddInternal(new BundledBeatmapDownloader()); + AddInternal(downloader = new BundledBeatmapDownloader()); downloadButton.Enabled.Value = false; + + foreach (var tracker in downloader.DownloadTrackers) + tracker.State.BindValueChanged(_ => updateProgress()); + } + + private void updateProgress() + { + double progress = (double)downloader.DownloadTrackers.Count(t => t.State.Value == DownloadState.LocallyAvailable) / downloader.DownloadTrackers.Count(); + + this.TransformBindableTo(progressBar.Current, progress, 1000, Easing.OutQuint); } } }