1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 13:47:38 +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) AddStep("setup cover", () => Child = new UpdateableOnlineBeatmapSetCover(coverType)
{ {
BeatmapSet = CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet, OnlineInfo = CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet.OnlineInfo,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Masking = true, Masking = true,
}); });
@ -68,7 +68,7 @@ namespace osu.Game.Tests.Visual.UserInterface
var cover = new UpdateableOnlineBeatmapSetCover(coverType) var cover = new UpdateableOnlineBeatmapSetCover(coverType)
{ {
BeatmapSet = setInfo, OnlineInfo = setInfo.OnlineInfo,
Height = 100, Height = 100,
Masking = true, Masking = true,
}; };
@ -99,12 +99,12 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("setup cover", () => Child = updateableCover = new TestUpdateableOnlineBeatmapSetCover AddStep("setup cover", () => Child = updateableCover = new TestUpdateableOnlineBeatmapSetCover
{ {
BeatmapSet = CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet, OnlineInfo = CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet.OnlineInfo,
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Masking = true, Masking = true,
}); });
AddStep("change model", () => updateableCover.BeatmapSet = null); AddStep("change model", () => updateableCover.OnlineInfo = null);
AddWaitStep("wait some", 5); AddWaitStep("wait some", 5);
AddAssert("no cover added", () => !updateableCover.ChildrenOfType<DelayedLoadUnloadWrapper>().Any()); 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) 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, RelativeSizeAxes = Axes.Both,
Masking = true, Masking = true,
Alpha = 0.4f Alpha = 0.4f
@ -128,7 +128,7 @@ namespace osu.Game.Tests.Visual.UserInterface
AddUntilStep("wait for fade complete", () => initialCover.Alpha == 1); AddUntilStep("wait for fade complete", () => initialCover.Alpha == 1);
AddStep("switch beatmap", 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()); 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, RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.5f), Colour = OsuColour.Gray(0.5f),
BeatmapSet = Beatmap.BeatmapSet, OnlineInfo = Beatmap.BeatmapSet,
}, },
new FillFlowContainer new FillFlowContainer
{ {

View File

@ -14,7 +14,7 @@ using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Beatmaps namespace osu.Game.Beatmaps
{ {
[ExcludeFromDynamicCompile] [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; } public int ID { get; set; }
@ -35,6 +35,7 @@ namespace osu.Game.Beatmaps
[NotNull] [NotNull]
public List<BeatmapSetFileInfo> Files { get; set; } = new List<BeatmapSetFileInfo>(); 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] [NotMapped]
public APIBeatmapSet OnlineInfo { get; set; } public APIBeatmapSet OnlineInfo { get; set; }

View File

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

View File

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

View File

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

View File

@ -227,7 +227,7 @@ namespace osu.Game.Overlays.BeatmapSet
BeatmapSet.BindValueChanged(setInfo => BeatmapSet.BindValueChanged(setInfo =>
{ {
Picker.BeatmapSet = rulesetSelector.BeatmapSet = author.BeatmapSet = beatmapAvailability.BeatmapSet = Details.BeatmapSet = setInfo.NewValue; 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) if (setInfo.NewValue == null)
{ {

View File

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

View File

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

View File

@ -333,13 +333,14 @@ namespace osu.Game.Screens.OnlinePlay
public PanelBackground() public PanelBackground()
{ {
UpdateableBeatmapBackgroundSprite backgroundSprite;
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
new UpdateableBeatmapBackgroundSprite backgroundSprite = new UpdateableBeatmapBackgroundSprite
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
FillMode = FillMode.Fill, FillMode = FillMode.Fill,
Beatmap = { BindTarget = Beatmap }
}, },
new FillFlowContainer 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);
} }
} }
} }