mirror of
https://github.com/ppy/osu
synced 2025-01-31 18:32:14 +00:00
Refactor beatmap set covers into using ModelBackedDrawable<T>
This commit is contained in:
parent
d83abfa7d2
commit
acfb2d2980
@ -22,9 +22,8 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
[Test]
|
||||
public void TestLocal([Values] BeatmapSetCoverType coverType)
|
||||
{
|
||||
AddStep("setup cover", () => Child = new UpdateableBeatmapSetCover
|
||||
AddStep("setup cover", () => Child = new UpdateableBeatmapSetCover(coverType)
|
||||
{
|
||||
CoverType = coverType,
|
||||
BeatmapSet = CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Masking = true,
|
||||
@ -64,9 +63,8 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
var coverType = coverTypes[i % coverTypes.Length];
|
||||
|
||||
var cover = new UpdateableBeatmapSetCover
|
||||
var cover = new UpdateableBeatmapSetCover(coverType)
|
||||
{
|
||||
CoverType = coverType,
|
||||
BeatmapSet = setInfo,
|
||||
Height = 100,
|
||||
Masking = true,
|
||||
@ -110,13 +108,25 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
|
||||
private class TestUpdateableBeatmapSetCover : UpdateableBeatmapSetCover
|
||||
{
|
||||
protected override BeatmapSetCover CreateBeatmapSetCover(BeatmapSetInfo beatmapSet, BeatmapSetCoverType coverType) => new TestBeatmapSetCover(beatmapSet, coverType);
|
||||
protected override Drawable CreateDrawable(BeatmapSetInfo model)
|
||||
{
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
return new TestBeatmapSetCover(model)
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
FillMode = FillMode.Fill,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private class TestBeatmapSetCover : BeatmapSetCover
|
||||
{
|
||||
public TestBeatmapSetCover(BeatmapSetInfo set, BeatmapSetCoverType type = BeatmapSetCoverType.Cover)
|
||||
: base(set, type)
|
||||
public TestBeatmapSetCover(BeatmapSetInfo set)
|
||||
: base(set)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
@ -8,78 +9,50 @@ using osu.Game.Graphics;
|
||||
|
||||
namespace osu.Game.Beatmaps.Drawables
|
||||
{
|
||||
public class UpdateableBeatmapSetCover : Container
|
||||
public class UpdateableBeatmapSetCover : ModelBackedDrawable<BeatmapSetInfo>
|
||||
{
|
||||
private Drawable displayedCover;
|
||||
|
||||
private BeatmapSetInfo beatmapSet;
|
||||
private readonly BeatmapSetCoverType coverType;
|
||||
|
||||
public BeatmapSetInfo BeatmapSet
|
||||
{
|
||||
get => beatmapSet;
|
||||
set
|
||||
{
|
||||
if (value == beatmapSet) return;
|
||||
|
||||
beatmapSet = value;
|
||||
|
||||
if (IsLoaded)
|
||||
updateCover();
|
||||
}
|
||||
get => Model;
|
||||
set => Model = value;
|
||||
}
|
||||
|
||||
private BeatmapSetCoverType coverType = BeatmapSetCoverType.Cover;
|
||||
|
||||
public BeatmapSetCoverType CoverType
|
||||
public new bool Masking
|
||||
{
|
||||
get => coverType;
|
||||
set
|
||||
{
|
||||
if (value == coverType) return;
|
||||
|
||||
coverType = value;
|
||||
|
||||
if (IsLoaded)
|
||||
updateCover();
|
||||
}
|
||||
get => base.Masking;
|
||||
set => base.Masking = value;
|
||||
}
|
||||
|
||||
public UpdateableBeatmapSetCover()
|
||||
public UpdateableBeatmapSetCover(BeatmapSetCoverType coverType = BeatmapSetCoverType.Cover)
|
||||
{
|
||||
Child = new Box
|
||||
this.coverType = coverType;
|
||||
|
||||
InternalChild = new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = OsuColour.Gray(0.2f),
|
||||
};
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
protected override double TransformDuration => 400.0;
|
||||
|
||||
protected override DelayedLoadWrapper CreateDelayedLoadWrapper(Func<Drawable> createContentFunc, double timeBeforeLoad)
|
||||
=> new DelayedLoadUnloadWrapper(createContentFunc, timeBeforeLoad);
|
||||
|
||||
protected override Drawable CreateDrawable(BeatmapSetInfo model)
|
||||
{
|
||||
base.LoadComplete();
|
||||
updateCover();
|
||||
}
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
protected virtual BeatmapSetCover CreateBeatmapSetCover(BeatmapSetInfo beatmapSet, BeatmapSetCoverType coverType) => new BeatmapSetCover(beatmapSet, coverType);
|
||||
|
||||
private void updateCover()
|
||||
{
|
||||
displayedCover?.FadeOut(400);
|
||||
displayedCover?.Expire();
|
||||
displayedCover = null;
|
||||
|
||||
if (beatmapSet != null)
|
||||
return new BeatmapSetCover(model, coverType)
|
||||
{
|
||||
Add(displayedCover = new DelayedLoadUnloadWrapper(() =>
|
||||
{
|
||||
var cover = CreateBeatmapSetCover(beatmapSet, coverType);
|
||||
cover.Anchor = Anchor.Centre;
|
||||
cover.Origin = Anchor.Centre;
|
||||
cover.RelativeSizeAxes = Axes.Both;
|
||||
cover.FillMode = FillMode.Fill;
|
||||
cover.OnLoadComplete += d => d.FadeInFromZero(400, Easing.Out);
|
||||
return cover;
|
||||
}));
|
||||
}
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
FillMode = FillMode.Fill,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,12 +41,11 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
|
||||
{
|
||||
AddRangeInternal(new Drawable[]
|
||||
{
|
||||
new UpdateableBeatmapSetCover
|
||||
new UpdateableBeatmapSetCover(BeatmapSetCoverType.List)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Width = cover_width,
|
||||
BeatmapSet = beatmap.BeatmapSet,
|
||||
CoverType = BeatmapSetCoverType.List,
|
||||
},
|
||||
new Container
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user