Add tutorial download support and improve the visuals "slightly"

This commit is contained in:
Dean Herbert
2022-04-27 20:19:11 +09:00
parent b424d20f26
commit 58399a5113
3 changed files with 108 additions and 29 deletions

View File

@ -17,7 +17,7 @@ namespace osu.Game.Tests.Visual.Online
AddStep("Create downloader", () => AddStep("Create downloader", () =>
{ {
downloader?.Expire(); downloader?.Expire();
Add(downloader = new BundledBeatmapDownloader()); Add(downloader = new BundledBeatmapDownloader(false));
}); });
} }
} }

View File

@ -22,15 +22,34 @@ namespace osu.Game.Beatmaps.Drawables
private readonly List<BeatmapDownloadTracker> downloadTrackers = new List<BeatmapDownloadTracker>(); private readonly List<BeatmapDownloadTracker> downloadTrackers = new List<BeatmapDownloadTracker>();
[BackgroundDependencyLoader] private readonly List<string> downloadableFilenames = new List<string>();
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)) 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<BeatmapModelDownloader>(beatmapDownloader = new BundledBeatmapModelDownloader(parent.Get<BeatmapManager>(), parent.Get<IAPIProvider>())
{
PostNotification = parent.Get<INotificationOverlay>().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"); 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 = private static readonly string[] bundled_beatmap_filenames =
{ {
"682286 Yuyoyuppe - Emerald Galaxy.osz", "682286 Yuyoyuppe - Emerald Galaxy.osz",

View File

@ -9,64 +9,122 @@ using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Online; using osu.Game.Online;
using osuTK.Graphics; using osuTK;
namespace osu.Game.Overlays.FirstRunSetup namespace osu.Game.Overlays.FirstRunSetup
{ {
[Description("Bundled Beatmaps")] [Description("Bundled Beatmaps")]
public class ScreenBundledBeatmaps : FirstRunSetupScreen public class ScreenBundledBeatmaps : FirstRunSetupScreen
{ {
private TriangleButton downloadButton; private RoundedButton downloadBundledButton;
private ProgressBar progressBar; private ProgressBar progressBarBundled;
private BundledBeatmapDownloader downloader;
private RoundedButton downloadTutorialButton;
private ProgressBar progressBarTutorial;
private BundledBeatmapDownloader tutorialDownloader;
private BundledBeatmapDownloader bundledDownloader;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load(OsuColour colours)
{ {
Vector2 buttonSize = new Vector2(500, 80);
Content.Children = new Drawable[] Content.Children = new Drawable[]
{ {
new OsuTextFlowContainer(cp => cp.Font = OsuFont.Default.With(size: 20)) 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, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y AutoSizeAxes = Axes.Y
}, },
downloadButton = new TriangleButton downloadTutorialButton = new RoundedButton
{ {
Width = 300, Size = buttonSize,
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
Text = "Download beatmap selection", BackgroundColour = colours.Pink3,
Action = download 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, RelativeSizeAxes = Axes.Both,
Blending = BlendingParameters.Additive, 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, Alpha = 0.5f,
Depth = float.MinValue Depth = float.MinValue
}); });
} }
private void download() private void downloadTutorial()
{ {
AddInternal(downloader = new BundledBeatmapDownloader()); if (tutorialDownloader != null)
downloadButton.Enabled.Value = false; return;
foreach (var tracker in downloader.DownloadTrackers) tutorialDownloader = new BundledBeatmapDownloader(true);
tracker.State.BindValueChanged(_ => updateProgress());
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;
}
} }
} }
} }