1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 09:07:25 +08:00

Merge pull request #15317 from peppy/beatmap-refactor/uncontested

Update `UpdateableBeatmapBackgroundSprite` to accept `IBeatmapInfo`
This commit is contained in:
Dan Balasescu 2021-10-28 17:24:49 +09:00 committed by GitHub
commit e5a7589859
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 37 additions and 25 deletions

View File

@ -25,7 +25,7 @@ namespace osu.Game.Tests.Visual.UserInterface
{
AddStep("setup cover", () => Child = new UpdateableOnlineBeatmapSetCover(coverType)
{
BeatmapSet = CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet,
OnlineInfo = CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet.OnlineInfo,
RelativeSizeAxes = Axes.Both,
Masking = true,
});
@ -68,7 +68,7 @@ namespace osu.Game.Tests.Visual.UserInterface
var cover = new UpdateableOnlineBeatmapSetCover(coverType)
{
BeatmapSet = setInfo,
OnlineInfo = setInfo.OnlineInfo,
Height = 100,
Masking = true,
};
@ -99,12 +99,12 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("setup cover", () => Child = updateableCover = new TestUpdateableOnlineBeatmapSetCover
{
BeatmapSet = CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet,
OnlineInfo = CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet.OnlineInfo,
RelativeSizeAxes = Axes.Both,
Masking = true,
});
AddStep("change model", () => updateableCover.BeatmapSet = null);
AddStep("change model", () => updateableCover.OnlineInfo = null);
AddWaitStep("wait some", 5);
AddAssert("no cover added", () => !updateableCover.ChildrenOfType<DelayedLoadUnloadWrapper>().Any());
}
@ -117,7 +117,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("setup cover", () => Child = updateableCover = new TestUpdateableOnlineBeatmapSetCover(0)
{
BeatmapSet = createBeatmapWithCover("https://assets.ppy.sh/beatmaps/1189904/covers/cover.jpg"),
OnlineInfo = createBeatmapWithCover("https://assets.ppy.sh/beatmaps/1189904/covers/cover.jpg").OnlineInfo,
RelativeSizeAxes = Axes.Both,
Masking = true,
Alpha = 0.4f
@ -128,7 +128,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddUntilStep("wait for fade complete", () => initialCover.Alpha == 1);
AddStep("switch beatmap",
() => updateableCover.BeatmapSet = createBeatmapWithCover("https://assets.ppy.sh/beatmaps/1079428/covers/cover.jpg"));
() => updateableCover.OnlineInfo = createBeatmapWithCover("https://assets.ppy.sh/beatmaps/1079428/covers/cover.jpg").OnlineInfo);
AddUntilStep("new cover loaded", () => updateableCover.ChildrenOfType<OnlineBeatmapSetCover>().Except(new[] { initialCover }).Any());
}

View File

@ -63,7 +63,7 @@ namespace osu.Game.Tournament.Components
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.5f),
BeatmapSet = Beatmap.BeatmapSet,
OnlineInfo = Beatmap.BeatmapSet,
},
new FillFlowContainer
{

View File

@ -14,7 +14,7 @@ using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Beatmaps
{
[ExcludeFromDynamicCompile]
public class BeatmapSetInfo : IHasPrimaryKey, IHasFiles<BeatmapSetFileInfo>, ISoftDelete, IEquatable<BeatmapSetInfo>, IBeatmapSetInfo, IBeatmapSetOnlineInfo
public class BeatmapSetInfo : IHasPrimaryKey, IHasFiles<BeatmapSetFileInfo>, ISoftDelete, IEquatable<BeatmapSetInfo>, IBeatmapSetInfo
{
public int ID { get; set; }
@ -35,6 +35,7 @@ namespace osu.Game.Beatmaps
[NotNull]
public List<BeatmapSetFileInfo> Files { get; set; } = new List<BeatmapSetFileInfo>();
// This field is temporary and only used by `APIBeatmapSet.ToBeatmapSet` (soon to be removed) and tests (to be updated to provide APIBeatmapSet instead).
[NotMapped]
public APIBeatmapSet OnlineInfo { get; set; }

View File

@ -12,9 +12,9 @@ namespace osu.Game.Beatmaps.Drawables
/// <summary>
/// Display a beatmap background from a local source, but fallback to online source if not available.
/// </summary>
public class UpdateableBeatmapBackgroundSprite : ModelBackedDrawable<BeatmapInfo>
public class UpdateableBeatmapBackgroundSprite : ModelBackedDrawable<IBeatmapInfo>
{
public readonly Bindable<BeatmapInfo> Beatmap = new Bindable<BeatmapInfo>();
public readonly Bindable<IBeatmapInfo> Beatmap = new Bindable<IBeatmapInfo>();
protected override double LoadDelay => 500;
@ -39,7 +39,7 @@ namespace osu.Game.Beatmaps.Drawables
protected override double TransformDuration => 400;
protected override Drawable CreateDrawable(BeatmapInfo model)
protected override Drawable CreateDrawable(IBeatmapInfo model)
{
var drawable = getDrawableForModel(model);
drawable.RelativeSizeAxes = Axes.Both;
@ -50,15 +50,21 @@ namespace osu.Game.Beatmaps.Drawables
return drawable;
}
private Drawable getDrawableForModel(BeatmapInfo model)
private Drawable getDrawableForModel(IBeatmapInfo model)
{
// prefer online cover where available.
if (model?.BeatmapSet?.OnlineInfo != null)
return new OnlineBeatmapSetCover(model.BeatmapSet, beatmapSetCoverType);
if (model?.BeatmapSet is IBeatmapSetOnlineInfo online)
return new OnlineBeatmapSetCover(online, beatmapSetCoverType);
return model?.ID > 0
? new BeatmapBackgroundSprite(beatmaps.GetWorkingBeatmap(model))
: new BeatmapBackgroundSprite(beatmaps.DefaultBeatmap);
if (model is BeatmapInfo localModel)
{
if (localModel.BeatmapSet?.OnlineInfo != null)
return new OnlineBeatmapSetCover(localModel.BeatmapSet.OnlineInfo, beatmapSetCoverType);
return new BeatmapBackgroundSprite(beatmaps.GetWorkingBeatmap(localModel));
}
return new BeatmapBackgroundSprite(beatmaps.DefaultBeatmap);
}
}
}

View File

@ -13,7 +13,7 @@ namespace osu.Game.Beatmaps.Drawables
{
private readonly BeatmapSetCoverType coverType;
public IBeatmapSetOnlineInfo BeatmapSet
public IBeatmapSetOnlineInfo OnlineInfo
{
get => Model;
set => Model = value;

View File

@ -59,7 +59,7 @@ namespace osu.Game.Overlays.BeatmapListing
return;
}
beatmapCover.BeatmapSet = value;
beatmapCover.OnlineInfo = value.OnlineInfo;
beatmapCover.FadeTo(0.1f, 200, Easing.OutQuint);
}
}

View File

@ -163,7 +163,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels
protected Drawable CreateBackground() => new UpdateableOnlineBeatmapSetCover
{
RelativeSizeAxes = Axes.Both,
BeatmapSet = SetInfo,
OnlineInfo = SetInfo.OnlineInfo,
};
public class Statistic : FillFlowContainer

View File

@ -227,7 +227,7 @@ namespace osu.Game.Overlays.BeatmapSet
BeatmapSet.BindValueChanged(setInfo =>
{
Picker.BeatmapSet = rulesetSelector.BeatmapSet = author.BeatmapSet = beatmapAvailability.BeatmapSet = Details.BeatmapSet = setInfo.NewValue;
cover.BeatmapSet = setInfo.NewValue;
cover.OnlineInfo = setInfo.NewValue?.OnlineInfo;
if (setInfo.NewValue == null)
{

View File

@ -82,7 +82,7 @@ namespace osu.Game.Overlays.Dashboard.Home
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
BeatmapSet = SetInfo
OnlineInfo = SetInfo.OnlineInfo
}
},
new Container

View File

@ -46,7 +46,7 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
{
RelativeSizeAxes = Axes.Y,
Width = cover_width,
BeatmapSet = mostPlayed.BeatmapSet,
OnlineInfo = mostPlayed.BeatmapSet,
},
new Container
{

View File

@ -333,13 +333,14 @@ namespace osu.Game.Screens.OnlinePlay
public PanelBackground()
{
UpdateableBeatmapBackgroundSprite backgroundSprite;
InternalChildren = new Drawable[]
{
new UpdateableBeatmapBackgroundSprite
backgroundSprite = new UpdateableBeatmapBackgroundSprite
{
RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fill,
Beatmap = { BindTarget = Beatmap }
},
new FillFlowContainer
{
@ -374,6 +375,10 @@ namespace osu.Game.Screens.OnlinePlay
}
}
};
// manual binding required as playlists don't expose IBeatmapInfo currently.
// may be removed in the future if this changes.
Beatmap.BindValueChanged(beatmap => backgroundSprite.Beatmap.Value = beatmap.NewValue);
}
}
}