2022-04-27 17:57:20 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-04-28 17:57:32 +08:00
|
|
|
using System;
|
2022-04-27 18:41:13 +08:00
|
|
|
using System.Linq;
|
2022-04-27 17:57:20 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
2022-04-28 18:33:16 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Localisation;
|
2022-04-28 17:57:32 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2022-04-27 17:57:20 +08:00
|
|
|
using osu.Game.Beatmaps.Drawables;
|
2022-04-28 15:09:00 +08:00
|
|
|
using osu.Game.Database;
|
2022-04-27 17:57:20 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
2022-04-28 15:09:00 +08:00
|
|
|
using osu.Game.Localisation;
|
2022-04-27 18:41:13 +08:00
|
|
|
using osu.Game.Online;
|
2022-04-27 19:19:11 +08:00
|
|
|
using osuTK;
|
2022-04-28 17:57:32 +08:00
|
|
|
using Realms;
|
2022-04-27 17:57:20 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays.FirstRunSetup
|
|
|
|
{
|
2022-04-28 18:33:16 +08:00
|
|
|
[LocalisableDescription(typeof(FirstRunSetupBeatmapScreenStrings), nameof(FirstRunSetupBeatmapScreenStrings.Header))]
|
2022-04-28 15:09:00 +08:00
|
|
|
public class ScreenBeatmaps : FirstRunSetupScreen
|
2022-04-27 17:57:20 +08:00
|
|
|
{
|
2022-04-28 16:11:29 +08:00
|
|
|
private ProgressRoundedButton downloadBundledButton = null!;
|
|
|
|
private ProgressRoundedButton downloadTutorialButton = null!;
|
2022-04-27 17:57:20 +08:00
|
|
|
|
2022-04-28 17:57:32 +08:00
|
|
|
private OsuTextFlowContainer currentlyLoadedBeatmaps = null!;
|
|
|
|
|
2022-04-28 16:11:29 +08:00
|
|
|
private BundledBeatmapDownloader? tutorialDownloader;
|
|
|
|
private BundledBeatmapDownloader? bundledDownloader;
|
2022-04-27 19:19:11 +08:00
|
|
|
|
2022-04-28 16:11:29 +08:00
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; } = null!;
|
2022-04-27 18:41:13 +08:00
|
|
|
|
2022-04-28 17:57:32 +08:00
|
|
|
[Resolved]
|
|
|
|
private RealmAccess realmAccess { get; set; } = null!;
|
|
|
|
|
|
|
|
private IDisposable? beatmapSubscription;
|
|
|
|
|
2022-05-16 18:21:26 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
2022-04-27 17:57:20 +08:00
|
|
|
{
|
2022-05-10 16:33:37 +08:00
|
|
|
Vector2 buttonSize = new Vector2(400, 50);
|
2022-04-27 19:19:11 +08:00
|
|
|
|
2022-04-27 17:57:20 +08:00
|
|
|
Content.Children = new Drawable[]
|
|
|
|
{
|
2022-05-10 16:33:37 +08:00
|
|
|
new OsuTextFlowContainer(cp => cp.Font = OsuFont.Default.With(size: CONTENT_FONT_SIZE))
|
2022-04-27 17:57:20 +08:00
|
|
|
{
|
2022-04-28 17:57:32 +08:00
|
|
|
Colour = OverlayColourProvider.Content1,
|
2022-04-28 18:33:16 +08:00
|
|
|
Text = FirstRunSetupBeatmapScreenStrings.Description,
|
2022-04-28 15:09:00 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y
|
|
|
|
},
|
2022-04-28 17:57:32 +08:00
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Height = 30,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2022-05-10 16:33:37 +08:00
|
|
|
currentlyLoadedBeatmaps = new OsuTextFlowContainer(cp => cp.Font = OsuFont.Default.With(size: HEADER_FONT_SIZE, weight: FontWeight.SemiBold))
|
2022-04-28 17:57:32 +08:00
|
|
|
{
|
|
|
|
Colour = OverlayColourProvider.Content2,
|
|
|
|
TextAnchor = Anchor.Centre,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2022-05-10 16:33:37 +08:00
|
|
|
new OsuTextFlowContainer(cp => cp.Font = OsuFont.Default.With(size: CONTENT_FONT_SIZE))
|
2022-04-28 15:09:00 +08:00
|
|
|
{
|
2022-04-28 17:57:32 +08:00
|
|
|
Colour = OverlayColourProvider.Content1,
|
2022-04-28 18:33:16 +08:00
|
|
|
Text = FirstRunSetupBeatmapScreenStrings.TutorialDescription,
|
2022-04-27 17:57:20 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y
|
|
|
|
},
|
2022-04-28 16:11:29 +08:00
|
|
|
downloadTutorialButton = new ProgressRoundedButton
|
2022-04-27 19:19:11 +08:00
|
|
|
{
|
|
|
|
Size = buttonSize,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
BackgroundColour = colours.Pink3,
|
2022-04-28 18:33:16 +08:00
|
|
|
Text = FirstRunSetupBeatmapScreenStrings.TutorialButton,
|
2022-04-27 19:19:11 +08:00
|
|
|
Action = downloadTutorial
|
|
|
|
},
|
2022-05-10 16:33:37 +08:00
|
|
|
new OsuTextFlowContainer(cp => cp.Font = OsuFont.Default.With(size: CONTENT_FONT_SIZE))
|
2022-04-28 15:09:00 +08:00
|
|
|
{
|
2022-04-28 17:57:32 +08:00
|
|
|
Colour = OverlayColourProvider.Content1,
|
2022-04-28 18:33:16 +08:00
|
|
|
Text = FirstRunSetupBeatmapScreenStrings.BundledDescription,
|
2022-04-28 15:09:00 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y
|
|
|
|
},
|
2022-04-28 16:11:29 +08:00
|
|
|
downloadBundledButton = new ProgressRoundedButton
|
2022-04-27 17:57:20 +08:00
|
|
|
{
|
2022-04-27 19:19:11 +08:00
|
|
|
Size = buttonSize,
|
2022-04-27 17:57:20 +08:00
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
2022-04-27 19:19:11 +08:00
|
|
|
BackgroundColour = colours.Blue3,
|
2022-04-28 18:33:16 +08:00
|
|
|
Text = FirstRunSetupBeatmapScreenStrings.BundledButton,
|
2022-04-27 19:19:11 +08:00
|
|
|
Action = downloadBundled
|
2022-04-27 18:41:13 +08:00
|
|
|
},
|
2022-05-10 16:33:37 +08:00
|
|
|
new OsuTextFlowContainer(cp => cp.Font = OsuFont.Default.With(size: CONTENT_FONT_SIZE))
|
2022-04-28 15:09:00 +08:00
|
|
|
{
|
2022-04-28 17:57:32 +08:00
|
|
|
Colour = OverlayColourProvider.Content1,
|
2022-04-28 18:33:16 +08:00
|
|
|
Text = FirstRunSetupBeatmapScreenStrings.ObtainMoreBeatmaps,
|
2022-04-28 15:09:00 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y
|
|
|
|
},
|
2022-04-27 17:57:20 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-04-28 17:57:32 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
beatmapSubscription = realmAccess.RegisterForNotifications(r => r.All<BeatmapSetInfo>().Where(s => !s.DeletePending && !s.Protected), beatmapsChanged);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
beatmapSubscription?.Dispose();
|
|
|
|
}
|
|
|
|
|
2022-09-26 13:45:17 +08:00
|
|
|
private void beatmapsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet? changes, Exception error) => Schedule(() =>
|
2022-04-28 17:57:32 +08:00
|
|
|
{
|
2022-04-28 18:33:16 +08:00
|
|
|
currentlyLoadedBeatmaps.Text = FirstRunSetupBeatmapScreenStrings.CurrentlyLoadedBeatmaps(sender.Count);
|
2022-04-28 17:57:32 +08:00
|
|
|
|
2022-04-28 18:08:16 +08:00
|
|
|
if (sender.Count == 0)
|
2022-04-28 17:57:32 +08:00
|
|
|
{
|
2022-04-28 18:08:16 +08:00
|
|
|
currentlyLoadedBeatmaps.FadeColour(colours.Red1, 500, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
else if (changes != null && (changes.DeletedIndices.Any() || changes.InsertedIndices.Any()))
|
|
|
|
{
|
|
|
|
currentlyLoadedBeatmaps.FadeColour(colours.Yellow)
|
|
|
|
.FadeColour(OverlayColourProvider.Content2, 1500, Easing.OutQuint);
|
|
|
|
|
|
|
|
currentlyLoadedBeatmaps.ScaleTo(1.1f)
|
|
|
|
.ScaleTo(1, 1500, Easing.OutQuint);
|
2022-04-28 17:57:32 +08:00
|
|
|
}
|
2022-09-26 13:45:17 +08:00
|
|
|
});
|
2022-04-28 17:57:32 +08:00
|
|
|
|
2022-04-27 19:19:11 +08:00
|
|
|
private void downloadTutorial()
|
2022-04-27 17:57:20 +08:00
|
|
|
{
|
2022-04-28 16:11:29 +08:00
|
|
|
if (tutorialDownloader != null)
|
|
|
|
return;
|
|
|
|
|
2022-04-27 19:19:11 +08:00
|
|
|
tutorialDownloader = new BundledBeatmapDownloader(true);
|
|
|
|
|
|
|
|
AddInternal(tutorialDownloader);
|
|
|
|
|
|
|
|
var downloadTracker = tutorialDownloader.DownloadTrackers.First();
|
2022-04-27 18:41:13 +08:00
|
|
|
|
2022-06-02 15:34:23 +08:00
|
|
|
downloadTracker.State.BindValueChanged(state =>
|
|
|
|
{
|
|
|
|
if (state.NewValue == DownloadState.LocallyAvailable)
|
|
|
|
downloadTutorialButton.Complete();
|
|
|
|
}, true);
|
|
|
|
|
2022-04-27 19:19:11 +08:00
|
|
|
downloadTracker.Progress.BindValueChanged(progress =>
|
|
|
|
{
|
2022-04-28 17:26:29 +08:00
|
|
|
downloadTutorialButton.SetProgress(progress.NewValue, false);
|
2022-04-27 19:19:11 +08:00
|
|
|
}, true);
|
2022-04-27 18:41:13 +08:00
|
|
|
}
|
|
|
|
|
2022-04-27 19:19:11 +08:00
|
|
|
private void downloadBundled()
|
2022-04-27 18:41:13 +08:00
|
|
|
{
|
2022-04-28 16:11:29 +08:00
|
|
|
if (bundledDownloader != null)
|
|
|
|
return;
|
|
|
|
|
2022-04-27 19:19:11 +08:00
|
|
|
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();
|
|
|
|
|
|
|
|
if (progress == 1)
|
2022-04-28 16:11:29 +08:00
|
|
|
downloadBundledButton.Complete();
|
2022-04-28 17:26:29 +08:00
|
|
|
else
|
|
|
|
downloadBundledButton.SetProgress(progress, true);
|
2022-04-28 16:11:29 +08:00
|
|
|
}
|
|
|
|
}
|
2022-04-27 17:57:20 +08:00
|
|
|
}
|
|
|
|
}
|