// Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; namespace osu.Game.Beatmaps.Drawables { /// /// Display a baetmap background from a local source, but fallback to online source if not available. /// public class UpdateableBeatmapBackgroundSprite : ModelBackedDrawable { public readonly IBindable Beatmap = new Bindable(); [Resolved] private BeatmapManager beatmaps { get; set; } public UpdateableBeatmapBackgroundSprite() { Beatmap.BindValueChanged(b => Schedule(() => Model = b)); } protected override Drawable CreateDrawable(BeatmapInfo model) { Drawable drawable; var localBeatmap = beatmaps.GetWorkingBeatmap(model); if (localBeatmap.BeatmapInfo.ID == 0 && model?.BeatmapSet?.OnlineInfo != null) drawable = new BeatmapSetCover(model.BeatmapSet); else drawable = new BeatmapBackgroundSprite(localBeatmap); drawable.RelativeSizeAxes = Axes.Both; drawable.Anchor = Anchor.Centre; drawable.Origin = Anchor.Centre; drawable.FillMode = FillMode.Fill; return drawable; } protected override double FadeDuration => 400; } }