2019-01-24 08:43:03 +00: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.
|
2018-12-25 08:59:28 +00:00
|
|
|
|
2019-06-04 02:04:28 +00:00
|
|
|
using System;
|
2018-12-25 08:59:28 +00:00
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
using osu.Framework.Bindables;
|
2018-12-25 08:59:28 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables
|
|
|
|
{
|
|
|
|
/// <summary>
|
2019-03-06 09:18:47 +00:00
|
|
|
/// Display a beatmap background from a local source, but fallback to online source if not available.
|
2018-12-25 08:59:28 +00:00
|
|
|
/// </summary>
|
|
|
|
public class UpdateableBeatmapBackgroundSprite : ModelBackedDrawable<BeatmapInfo>
|
|
|
|
{
|
2019-02-11 10:11:34 +00:00
|
|
|
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
|
2018-12-25 08:59:28 +00:00
|
|
|
|
2020-02-27 11:01:23 +00:00
|
|
|
protected override double LoadDelay => 500;
|
|
|
|
|
2018-12-25 08:59:28 +00:00
|
|
|
[Resolved]
|
|
|
|
private BeatmapManager beatmaps { get; set; }
|
|
|
|
|
2019-03-05 03:08:14 +00:00
|
|
|
private readonly BeatmapSetCoverType beatmapSetCoverType;
|
|
|
|
|
2019-03-05 09:59:25 +00:00
|
|
|
public UpdateableBeatmapBackgroundSprite(BeatmapSetCoverType beatmapSetCoverType = BeatmapSetCoverType.Cover)
|
2018-12-25 08:59:28 +00:00
|
|
|
{
|
2019-02-22 11:13:38 +00:00
|
|
|
Beatmap.BindValueChanged(b => Model = b.NewValue);
|
2019-03-05 03:08:14 +00:00
|
|
|
this.beatmapSetCoverType = beatmapSetCoverType;
|
2018-12-25 08:59:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-07 08:24:05 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Delay before the background is unloaded while off-screen.
|
|
|
|
/// </summary>
|
|
|
|
protected virtual double UnloadDelay => 10000;
|
|
|
|
|
2019-06-04 02:04:28 +00:00
|
|
|
protected override DelayedLoadWrapper CreateDelayedLoadWrapper(Func<Drawable> createContentFunc, double timeBeforeLoad)
|
|
|
|
=> new DelayedLoadUnloadWrapper(createContentFunc, timeBeforeLoad, UnloadDelay);
|
2018-12-25 08:59:28 +00:00
|
|
|
|
2019-07-06 09:10:30 +00:00
|
|
|
protected override double TransformDuration => 400;
|
|
|
|
|
2019-03-06 09:18:47 +00:00
|
|
|
protected override Drawable CreateDrawable(BeatmapInfo model)
|
|
|
|
{
|
2019-07-06 09:10:30 +00:00
|
|
|
var drawable = getDrawableForModel(model);
|
2019-03-06 09:18:47 +00:00
|
|
|
drawable.RelativeSizeAxes = Axes.Both;
|
|
|
|
drawable.Anchor = Anchor.Centre;
|
|
|
|
drawable.Origin = Anchor.Centre;
|
|
|
|
drawable.FillMode = FillMode.Fill;
|
|
|
|
|
|
|
|
return drawable;
|
|
|
|
}
|
2019-03-11 09:45:30 +00:00
|
|
|
|
|
|
|
private Drawable getDrawableForModel(BeatmapInfo model)
|
|
|
|
{
|
|
|
|
// prefer online cover where available.
|
|
|
|
if (model?.BeatmapSet?.OnlineInfo != null)
|
|
|
|
return new BeatmapSetCover(model.BeatmapSet, beatmapSetCoverType);
|
|
|
|
|
|
|
|
return model?.ID > 0
|
|
|
|
? new BeatmapBackgroundSprite(beatmaps.GetWorkingBeatmap(model))
|
|
|
|
: new BeatmapBackgroundSprite(beatmaps.DefaultBeatmap);
|
|
|
|
}
|
2018-12-25 08:59:28 +00:00
|
|
|
}
|
|
|
|
}
|