2019-01-24 16:43:03 +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.
|
2018-12-25 16:59:28 +08:00
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Display a baetmap background from a local source, but fallback to online source if not available.
|
|
|
|
/// </summary>
|
|
|
|
public class UpdateableBeatmapBackgroundSprite : ModelBackedDrawable<BeatmapInfo>
|
|
|
|
{
|
|
|
|
public readonly IBindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private BeatmapManager beatmaps { get; set; }
|
|
|
|
|
|
|
|
public UpdateableBeatmapBackgroundSprite()
|
|
|
|
{
|
2018-12-26 20:18:55 +08:00
|
|
|
Beatmap.BindValueChanged(b => Model = b);
|
2018-12-25 16:59:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override Drawable CreateDrawable(BeatmapInfo model)
|
|
|
|
{
|
2018-12-28 12:28:07 +08:00
|
|
|
return new DelayedLoadUnloadWrapper(() => {
|
|
|
|
Drawable drawable;
|
2018-12-25 16:59:28 +08:00
|
|
|
|
2018-12-28 12:28:07 +08:00
|
|
|
var localBeatmap = beatmaps.GetWorkingBeatmap(model);
|
2018-12-25 16:59:28 +08:00
|
|
|
|
2018-12-28 12:28:07 +08:00
|
|
|
if (localBeatmap.BeatmapInfo.ID == 0 && model?.BeatmapSet?.OnlineInfo != null)
|
|
|
|
drawable = new BeatmapSetCover(model.BeatmapSet);
|
|
|
|
else
|
|
|
|
drawable = new BeatmapBackgroundSprite(localBeatmap);
|
2018-12-25 16:59:28 +08:00
|
|
|
|
2018-12-28 12:28:07 +08:00
|
|
|
drawable.RelativeSizeAxes = Axes.Both;
|
|
|
|
drawable.Anchor = Anchor.Centre;
|
|
|
|
drawable.Origin = Anchor.Centre;
|
|
|
|
drawable.FillMode = FillMode.Fill;
|
|
|
|
drawable.OnLoadComplete = d => d.FadeInFromZero(400);
|
2018-12-25 16:59:28 +08:00
|
|
|
|
2018-12-28 12:28:07 +08:00
|
|
|
return drawable;
|
|
|
|
}, 500, 10000);
|
2018-12-25 16:59:28 +08:00
|
|
|
}
|
|
|
|
|
2018-12-28 12:28:07 +08:00
|
|
|
protected override double FadeDuration => 0;
|
2018-12-25 16:59:28 +08:00
|
|
|
}
|
|
|
|
}
|