2023-09-04 15:17:21 +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.
|
|
|
|
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2023-09-04 16:14:04 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2023-09-04 15:17:21 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Online;
|
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
using osu.Game.Overlays.Notifications;
|
|
|
|
|
using osu.Game.Scoring;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Database
|
|
|
|
|
{
|
|
|
|
|
public partial class MissingBeatmapNotification : ProgressNotification
|
|
|
|
|
{
|
|
|
|
|
[Resolved]
|
|
|
|
|
private BeatmapModelDownloader beatmapDownloader { get; set; } = null!;
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private ScoreManager scoreManager { get; set; } = null!;
|
|
|
|
|
|
|
|
|
|
private readonly MemoryStream scoreStream;
|
|
|
|
|
|
|
|
|
|
private readonly APIBeatmapSet beatmapSetInfo;
|
|
|
|
|
|
|
|
|
|
private Bindable<bool> autodownloadConfig = null!;
|
2023-09-04 16:14:04 +08:00
|
|
|
|
private Bindable<bool> noVideoSetting = null!;
|
2023-09-04 15:17:21 +08:00
|
|
|
|
|
|
|
|
|
public MissingBeatmapNotification(APIBeatmap beatmap, MemoryStream scoreStream)
|
|
|
|
|
{
|
|
|
|
|
beatmapSetInfo = beatmap.BeatmapSet!;
|
|
|
|
|
|
|
|
|
|
this.scoreStream = scoreStream;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2023-09-04 16:14:04 +08:00
|
|
|
|
private void load(OsuConfigManager config, BeatmapSetOverlay? beatmapSetOverlay)
|
2023-09-04 15:17:21 +08:00
|
|
|
|
{
|
2023-09-04 16:14:04 +08:00
|
|
|
|
BeatmapDownloadTracker downloadTracker = new BeatmapDownloadTracker(beatmapSetInfo);
|
|
|
|
|
downloadTracker.State.BindValueChanged(downloadStatusChanged);
|
|
|
|
|
|
2023-09-04 15:17:21 +08:00
|
|
|
|
autodownloadConfig = config.GetBindable<bool>(OsuSetting.AutomaticallyDownloadWhenSpectating);
|
2023-09-04 16:14:04 +08:00
|
|
|
|
noVideoSetting = config.GetBindable<bool>(OsuSetting.PreferNoVideo);
|
2023-09-04 15:17:21 +08:00
|
|
|
|
|
|
|
|
|
Text = "You do not have the required beatmap for this replay";
|
|
|
|
|
|
2023-09-04 16:14:04 +08:00
|
|
|
|
Content.Add(new ClickableContainer
|
2023-09-04 15:17:21 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 70,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
|
CornerRadius = 4,
|
2023-09-04 16:14:04 +08:00
|
|
|
|
Masking = true,
|
|
|
|
|
Action = () => beatmapSetOverlay?.FetchAndShowBeatmapSet(beatmapSetInfo.OnlineID),
|
2023-09-04 15:17:21 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
downloadTracker,
|
|
|
|
|
new DelayedLoadWrapper(() => new UpdateableOnlineBeatmapSetCover(BeatmapSetCoverType.Card)
|
|
|
|
|
{
|
|
|
|
|
OnlineInfo = beatmapSetInfo,
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
},
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Black,
|
|
|
|
|
Alpha = 0.4f
|
|
|
|
|
},
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Padding = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Left = 10f,
|
|
|
|
|
Top = 5f
|
|
|
|
|
},
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new TruncatingSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = beatmapSetInfo.Title,
|
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 17, italics: true),
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
},
|
|
|
|
|
new TruncatingSpriteText
|
|
|
|
|
{
|
|
|
|
|
Text = beatmapSetInfo.Artist,
|
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 12, italics: true),
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2023-09-04 16:14:04 +08:00
|
|
|
|
new BeatmapDownloadButton(beatmapSetInfo)
|
2023-09-04 15:17:21 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
Width = 50,
|
|
|
|
|
Height = 30,
|
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Bottom = 1f
|
2023-09-04 16:14:04 +08:00
|
|
|
|
}
|
2023-09-04 15:17:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-04 16:14:04 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
2023-09-04 15:17:21 +08:00
|
|
|
|
|
|
|
|
|
if (autodownloadConfig.Value)
|
2023-09-04 16:14:04 +08:00
|
|
|
|
beatmapDownloader.Download(beatmapSetInfo, noVideoSetting.Value);
|
2023-09-04 15:17:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void downloadStatusChanged(ValueChangedEvent<DownloadState> status)
|
|
|
|
|
{
|
|
|
|
|
if (status.NewValue != DownloadState.LocallyAvailable)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var importTask = new ImportTask(scoreStream, "score.osr");
|
|
|
|
|
scoreManager.Import(this, new[] { importTask });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|