From 58399a5113e9bc5906e529672fc917b19a33a187 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 27 Apr 2022 20:19:11 +0900 Subject: [PATCH] Add tutorial download support and improve the visuals "slightly" --- .../TestSceneBundledBeatmapDownloader.cs | 2 +- .../Drawables/BundledBeatmapDownloader.cs | 37 +++++-- .../FirstRunSetup/ScreenBundledBeatmaps.cs | 98 +++++++++++++++---- 3 files changed, 108 insertions(+), 29 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneBundledBeatmapDownloader.cs b/osu.Game.Tests/Visual/Online/TestSceneBundledBeatmapDownloader.cs index 895524e79a..2af1c9a0f0 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneBundledBeatmapDownloader.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneBundledBeatmapDownloader.cs @@ -17,7 +17,7 @@ namespace osu.Game.Tests.Visual.Online AddStep("Create downloader", () => { downloader?.Expire(); - Add(downloader = new BundledBeatmapDownloader()); + Add(downloader = new BundledBeatmapDownloader(false)); }); } } diff --git a/osu.Game/Beatmaps/Drawables/BundledBeatmapDownloader.cs b/osu.Game/Beatmaps/Drawables/BundledBeatmapDownloader.cs index 5937186705..0bdaaaca22 100644 --- a/osu.Game/Beatmaps/Drawables/BundledBeatmapDownloader.cs +++ b/osu.Game/Beatmaps/Drawables/BundledBeatmapDownloader.cs @@ -22,15 +22,34 @@ namespace osu.Game.Beatmaps.Drawables private readonly List downloadTrackers = new List(); - [BackgroundDependencyLoader] - private void load(BeatmapManager beatmapManager, IAPIProvider api, INotificationOverlay notifications) - { - var beatmapDownloader = new BundledBeatmapModelDownloader(beatmapManager, api) - { - PostNotification = notifications.Post - }; + private readonly List downloadableFilenames = new List(); - foreach (string filename in bundled_beatmap_filenames.OrderBy(_ => RNG.NextSingle()).Take(10)) + private BundledBeatmapModelDownloader beatmapDownloader; + + public BundledBeatmapDownloader(bool onlyTutorial) + { + if (onlyTutorial) + downloadableFilenames.Add(tutorial_filename); + else + downloadableFilenames.AddRange(bundled_beatmap_filenames); + } + + protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) + { + var localDependencies = new DependencyContainer(base.CreateChildDependencies(parent)); + + localDependencies.CacheAs(beatmapDownloader = new BundledBeatmapModelDownloader(parent.Get(), parent.Get()) + { + PostNotification = parent.Get().Post + }); + + return localDependencies; + } + + [BackgroundDependencyLoader] + private void load() + { + foreach (string filename in downloadableFilenames.OrderBy(_ => RNG.NextSingle()).Take(10)) { var match = Regex.Match(filename, @"([0-9]*) (.*) - (.*)\.osz"); @@ -49,6 +68,8 @@ namespace osu.Game.Beatmaps.Drawables } } + private const string tutorial_filename = "1011011 nekodex - new beginnings.osz"; + private static readonly string[] bundled_beatmap_filenames = { "682286 Yuyoyuppe - Emerald Galaxy.osz", diff --git a/osu.Game/Overlays/FirstRunSetup/ScreenBundledBeatmaps.cs b/osu.Game/Overlays/FirstRunSetup/ScreenBundledBeatmaps.cs index 97f429bcf2..518903e74b 100644 --- a/osu.Game/Overlays/FirstRunSetup/ScreenBundledBeatmaps.cs +++ b/osu.Game/Overlays/FirstRunSetup/ScreenBundledBeatmaps.cs @@ -9,64 +9,122 @@ using osu.Game.Beatmaps.Drawables; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; +using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Online; -using osuTK.Graphics; +using osuTK; namespace osu.Game.Overlays.FirstRunSetup { [Description("Bundled Beatmaps")] public class ScreenBundledBeatmaps : FirstRunSetupScreen { - private TriangleButton downloadButton; + private RoundedButton downloadBundledButton; - private ProgressBar progressBar; - private BundledBeatmapDownloader downloader; + private ProgressBar progressBarBundled; + + private RoundedButton downloadTutorialButton; + private ProgressBar progressBarTutorial; + + private BundledBeatmapDownloader tutorialDownloader; + private BundledBeatmapDownloader bundledDownloader; [BackgroundDependencyLoader] - private void load() + private void load(OsuColour colours) { + Vector2 buttonSize = new Vector2(500, 80); + Content.Children = new Drawable[] { new OsuTextFlowContainer(cp => cp.Font = OsuFont.Default.With(size: 20)) { - Text = "osu! doesn't come with any beatmaps pre-loaded. To get started, we have some recommended beatmaps.", + Text = + "osu! doesn't come with any beatmaps pre-loaded. To get started, we have some recommended beatmaps. You can obtain more beatmaps from the main menu \"browse\" button at any time.", RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y }, - downloadButton = new TriangleButton + downloadTutorialButton = new RoundedButton { - Width = 300, + Size = buttonSize, Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, - Text = "Download beatmap selection", - Action = download + BackgroundColour = colours.Pink3, + Text = "Download tutorial", + Action = downloadTutorial }, + downloadBundledButton = new RoundedButton + { + Size = buttonSize, + Anchor = Anchor.TopCentre, + Origin = Anchor.TopCentre, + BackgroundColour = colours.Blue3, + Text = "Download beatmap selection", + Action = downloadBundled + }, + // TODO: add stable import button if a stable install is detected. }; - downloadButton.Add(progressBar = new ProgressBar(false) + downloadTutorialButton.Add(progressBarTutorial = new ProgressBar(false) { RelativeSizeAxes = Axes.Both, Blending = BlendingParameters.Additive, - FillColour = Color4.Aqua, + FillColour = downloadTutorialButton.BackgroundColour, + Alpha = 0.5f, + Depth = float.MinValue + }); + + downloadBundledButton.Add(progressBarBundled = new ProgressBar(false) + { + RelativeSizeAxes = Axes.Both, + Blending = BlendingParameters.Additive, + FillColour = downloadBundledButton.BackgroundColour, Alpha = 0.5f, Depth = float.MinValue }); } - private void download() + private void downloadTutorial() { - AddInternal(downloader = new BundledBeatmapDownloader()); - downloadButton.Enabled.Value = false; + if (tutorialDownloader != null) + return; - foreach (var tracker in downloader.DownloadTrackers) - tracker.State.BindValueChanged(_ => updateProgress()); + tutorialDownloader = new BundledBeatmapDownloader(true); + + AddInternal(tutorialDownloader); + + var downloadTracker = tutorialDownloader.DownloadTrackers.First(); + + downloadTracker.Progress.BindValueChanged(progress => + { + progressBarTutorial.Current.Value = progress.NewValue; + + if (progress.NewValue == 1) + downloadTutorialButton.Enabled.Value = false; + }, true); } - private void updateProgress() + private void downloadBundled() { - double progress = (double)downloader.DownloadTrackers.Count(t => t.State.Value == DownloadState.LocallyAvailable) / downloader.DownloadTrackers.Count(); + if (bundledDownloader != null) + return; - this.TransformBindableTo(progressBar.Current, progress, 1000, Easing.OutQuint); + // downloadBundledButton.Enabled.Value = false; + + bundledDownloader = new BundledBeatmapDownloader(false); + + AddInternal(bundledDownloader); + + foreach (var tracker in bundledDownloader.DownloadTrackers) + tracker.State.BindValueChanged(_ => updateProgress(), true); + + void updateProgress() + { + double progress = (double)bundledDownloader.DownloadTrackers.Count(t => t.State.Value == DownloadState.LocallyAvailable) / bundledDownloader.DownloadTrackers.Count(); + + this.TransformBindableTo(progressBarBundled.Current, progress, 1000, Easing.OutQuint); + + if (progress == 1) + downloadBundledButton.Enabled.Value = false; + } } } }