2023-06-23 00:37:25 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-01-24 16:43:03 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-12-25 16:59:28 +08:00
|
|
|
|
|
2019-06-04 10:04:28 +08:00
|
|
|
|
using System;
|
2018-12-25 16:59:28 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-12-25 16:59:28 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2019-03-06 17:18:47 +08:00
|
|
|
|
/// Display a beatmap background from a local source, but fallback to online source if not available.
|
2018-12-25 16:59:28 +08:00
|
|
|
|
/// </summary>
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class UpdateableBeatmapBackgroundSprite : ModelBackedDrawable<IBeatmapInfo>
|
2018-12-25 16:59:28 +08:00
|
|
|
|
{
|
2021-10-27 14:20:01 +08:00
|
|
|
|
public readonly Bindable<IBeatmapInfo> Beatmap = new Bindable<IBeatmapInfo>();
|
2018-12-25 16:59:28 +08:00
|
|
|
|
|
2020-02-27 19:01:23 +08:00
|
|
|
|
protected override double LoadDelay => 500;
|
|
|
|
|
|
2018-12-25 16:59:28 +08:00
|
|
|
|
[Resolved]
|
2023-06-23 00:37:25 +08:00
|
|
|
|
private BeatmapManager beatmaps { get; set; } = null!;
|
2018-12-25 16:59:28 +08:00
|
|
|
|
|
2019-03-05 11:08:14 +08:00
|
|
|
|
private readonly BeatmapSetCoverType beatmapSetCoverType;
|
|
|
|
|
|
2019-03-05 17:59:25 +08:00
|
|
|
|
public UpdateableBeatmapBackgroundSprite(BeatmapSetCoverType beatmapSetCoverType = BeatmapSetCoverType.Cover)
|
2018-12-25 16:59:28 +08:00
|
|
|
|
{
|
2019-02-22 19:13:38 +08:00
|
|
|
|
Beatmap.BindValueChanged(b => Model = b.NewValue);
|
2019-03-05 11:08:14 +08:00
|
|
|
|
this.beatmapSetCoverType = beatmapSetCoverType;
|
2018-12-25 16:59:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-07 16:24:05 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Delay before the background is unloaded while off-screen.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual double UnloadDelay => 10000;
|
|
|
|
|
|
2021-02-12 14:27:37 +08:00
|
|
|
|
protected override DelayedLoadWrapper CreateDelayedLoadWrapper(Func<Drawable> createContentFunc, double timeBeforeLoad) =>
|
|
|
|
|
new DelayedLoadUnloadWrapper(createContentFunc, timeBeforeLoad, UnloadDelay) { RelativeSizeAxes = Axes.Both };
|
2018-12-25 16:59:28 +08:00
|
|
|
|
|
2019-07-06 17:10:30 +08:00
|
|
|
|
protected override double TransformDuration => 400;
|
|
|
|
|
|
2023-06-24 21:07:04 +08:00
|
|
|
|
protected override Drawable CreateDrawable(IBeatmapInfo? model)
|
2019-03-06 17:18:47 +08:00
|
|
|
|
{
|
2019-07-06 17:10:30 +08:00
|
|
|
|
var drawable = getDrawableForModel(model);
|
2019-03-06 17:18:47 +08:00
|
|
|
|
drawable.RelativeSizeAxes = Axes.Both;
|
|
|
|
|
drawable.Anchor = Anchor.Centre;
|
|
|
|
|
drawable.Origin = Anchor.Centre;
|
|
|
|
|
drawable.FillMode = FillMode.Fill;
|
|
|
|
|
|
|
|
|
|
return drawable;
|
|
|
|
|
}
|
2019-03-11 17:45:30 +08:00
|
|
|
|
|
2023-06-23 23:59:36 +08:00
|
|
|
|
private Drawable getDrawableForModel(IBeatmapInfo? model)
|
2019-03-11 17:45:30 +08:00
|
|
|
|
{
|
2024-05-03 13:42:56 +08:00
|
|
|
|
if (model == null)
|
|
|
|
|
return Empty();
|
|
|
|
|
|
2019-03-11 17:45:30 +08:00
|
|
|
|
// prefer online cover where available.
|
2024-05-03 14:11:00 +08:00
|
|
|
|
if (model.BeatmapSet is IBeatmapSetOnlineInfo online)
|
2021-10-27 14:20:01 +08:00
|
|
|
|
return new OnlineBeatmapSetCover(online, beatmapSetCoverType);
|
2019-03-11 17:45:30 +08:00
|
|
|
|
|
2021-10-27 14:20:01 +08:00
|
|
|
|
if (model is BeatmapInfo localModel)
|
|
|
|
|
return new BeatmapBackgroundSprite(beatmaps.GetWorkingBeatmap(localModel));
|
|
|
|
|
|
|
|
|
|
return new BeatmapBackgroundSprite(beatmaps.DefaultBeatmap);
|
2019-03-11 17:45:30 +08:00
|
|
|
|
}
|
2018-12-25 16:59:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|