1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 07:53:38 +08:00
osu-lazer/osu.Game/Beatmaps/Drawables/UpdateableBeatmapBackgroundSprite.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
2.4 KiB
C#
Raw Normal View History

// 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
2022-06-17 15:37:17 +08:00
#nullable disable
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>
/// 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>
public class UpdateableBeatmapBackgroundSprite : ModelBackedDrawable<IBeatmapInfo>
2018-12-25 16:59:28 +08:00
{
public readonly Bindable<IBeatmapInfo> Beatmap = new Bindable<IBeatmapInfo>();
2018-12-25 16:59:28 +08:00
protected override double LoadDelay => 500;
2018-12-25 16:59:28 +08:00
[Resolved]
private BeatmapManager beatmaps { get; set; }
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
{
Beatmap.BindValueChanged(b => Model = b.NewValue);
this.beatmapSetCoverType = beatmapSetCoverType;
2018-12-25 16:59:28 +08:00
}
/// <summary>
/// Delay before the background is unloaded while off-screen.
/// </summary>
protected virtual double UnloadDelay => 10000;
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;
protected override Drawable CreateDrawable(IBeatmapInfo model)
{
2019-07-06 17:10:30 +08:00
var drawable = getDrawableForModel(model);
drawable.RelativeSizeAxes = Axes.Both;
drawable.Anchor = Anchor.Centre;
drawable.Origin = Anchor.Centre;
drawable.FillMode = FillMode.Fill;
return drawable;
}
private Drawable getDrawableForModel(IBeatmapInfo model)
{
// prefer online cover where available.
if (model?.BeatmapSet is IBeatmapSetOnlineInfo online)
return new OnlineBeatmapSetCover(online, beatmapSetCoverType);
if (model is BeatmapInfo localModel)
return new BeatmapBackgroundSprite(beatmaps.GetWorkingBeatmap(localModel));
return new BeatmapBackgroundSprite(beatmaps.DefaultBeatmap);
}
2018-12-25 16:59:28 +08:00
}
}