1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

Add Updateable beatmap sprite

This commit is contained in:
Dean Herbert 2018-12-25 17:59:28 +09:00
parent 9368054d47
commit 9542e3e24a
2 changed files with 48 additions and 1 deletions

View File

@ -59,7 +59,7 @@ namespace osu.Game.Beatmaps
/// <summary>
/// A default representation of a WorkingBeatmap to use when no beatmap is available.
/// </summary>
public WorkingBeatmap DefaultBeatmap { private get; set; }
public WorkingBeatmap DefaultBeatmap { get; set; }
public override string[] HandledExtensions => new[] { ".osz" };

View File

@ -0,0 +1,47 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// 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
{
/// <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()
{
Beatmap.BindValueChanged(b => Schedule(() => Model = b));
}
protected override Drawable CreateDrawable(BeatmapInfo model)
{
Drawable drawable;
var localBeatmap = beatmaps.GetWorkingBeatmap(model);
if (localBeatmap == beatmaps.DefaultBeatmap && 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;
}
}