mirror of
https://github.com/osukey/osukey.git
synced 2025-05-29 01:17:35 +09: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]
|
[Test]
|
||||||
public void TestLocal([Values] BeatmapSetCoverType coverType)
|
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,
|
BeatmapSet = CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet,
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Masking = true,
|
Masking = true,
|
||||||
@ -64,9 +63,8 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
{
|
{
|
||||||
var coverType = coverTypes[i % coverTypes.Length];
|
var coverType = coverTypes[i % coverTypes.Length];
|
||||||
|
|
||||||
var cover = new UpdateableBeatmapSetCover
|
var cover = new UpdateableBeatmapSetCover(coverType)
|
||||||
{
|
{
|
||||||
CoverType = coverType,
|
|
||||||
BeatmapSet = setInfo,
|
BeatmapSet = setInfo,
|
||||||
Height = 100,
|
Height = 100,
|
||||||
Masking = true,
|
Masking = true,
|
||||||
@ -110,13 +108,25 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
|
|
||||||
private class TestUpdateableBeatmapSetCover : UpdateableBeatmapSetCover
|
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
|
private class TestBeatmapSetCover : BeatmapSetCover
|
||||||
{
|
{
|
||||||
public TestBeatmapSetCover(BeatmapSetInfo set, BeatmapSetCoverType type = BeatmapSetCoverType.Cover)
|
public TestBeatmapSetCover(BeatmapSetInfo set)
|
||||||
: base(set, type)
|
: base(set)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
@ -8,78 +9,50 @@ using osu.Game.Graphics;
|
|||||||
|
|
||||||
namespace osu.Game.Beatmaps.Drawables
|
namespace osu.Game.Beatmaps.Drawables
|
||||||
{
|
{
|
||||||
public class UpdateableBeatmapSetCover : Container
|
public class UpdateableBeatmapSetCover : ModelBackedDrawable<BeatmapSetInfo>
|
||||||
{
|
{
|
||||||
private Drawable displayedCover;
|
private readonly BeatmapSetCoverType coverType;
|
||||||
|
|
||||||
private BeatmapSetInfo beatmapSet;
|
|
||||||
|
|
||||||
public BeatmapSetInfo BeatmapSet
|
public BeatmapSetInfo BeatmapSet
|
||||||
{
|
{
|
||||||
get => beatmapSet;
|
get => Model;
|
||||||
set
|
set => Model = value;
|
||||||
{
|
|
||||||
if (value == beatmapSet) return;
|
|
||||||
|
|
||||||
beatmapSet = value;
|
|
||||||
|
|
||||||
if (IsLoaded)
|
|
||||||
updateCover();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private BeatmapSetCoverType coverType = BeatmapSetCoverType.Cover;
|
public new bool Masking
|
||||||
|
|
||||||
public BeatmapSetCoverType CoverType
|
|
||||||
{
|
{
|
||||||
get => coverType;
|
get => base.Masking;
|
||||||
set
|
set => base.Masking = value;
|
||||||
{
|
|
||||||
if (value == coverType) return;
|
|
||||||
|
|
||||||
coverType = value;
|
|
||||||
|
|
||||||
if (IsLoaded)
|
|
||||||
updateCover();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public UpdateableBeatmapSetCover()
|
public UpdateableBeatmapSetCover(BeatmapSetCoverType coverType = BeatmapSetCoverType.Cover)
|
||||||
{
|
{
|
||||||
Child = new Box
|
this.coverType = coverType;
|
||||||
|
|
||||||
|
InternalChild = new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Colour = OsuColour.Gray(0.2f),
|
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();
|
if (model == null)
|
||||||
updateCover();
|
return null;
|
||||||
}
|
|
||||||
|
|
||||||
protected virtual BeatmapSetCover CreateBeatmapSetCover(BeatmapSetInfo beatmapSet, BeatmapSetCoverType coverType) => new BeatmapSetCover(beatmapSet, coverType);
|
return new BeatmapSetCover(model, coverType)
|
||||||
|
|
||||||
private void updateCover()
|
|
||||||
{
|
|
||||||
displayedCover?.FadeOut(400);
|
|
||||||
displayedCover?.Expire();
|
|
||||||
displayedCover = null;
|
|
||||||
|
|
||||||
if (beatmapSet != null)
|
|
||||||
{
|
{
|
||||||
Add(displayedCover = new DelayedLoadUnloadWrapper(() =>
|
RelativeSizeAxes = Axes.Both,
|
||||||
{
|
Anchor = Anchor.Centre,
|
||||||
var cover = CreateBeatmapSetCover(beatmapSet, coverType);
|
Origin = Anchor.Centre,
|
||||||
cover.Anchor = Anchor.Centre;
|
FillMode = FillMode.Fill,
|
||||||
cover.Origin = Anchor.Centre;
|
};
|
||||||
cover.RelativeSizeAxes = Axes.Both;
|
|
||||||
cover.FillMode = FillMode.Fill;
|
|
||||||
cover.OnLoadComplete += d => d.FadeInFromZero(400, Easing.Out);
|
|
||||||
return cover;
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,12 +41,11 @@ namespace osu.Game.Overlays.Profile.Sections.Historical
|
|||||||
{
|
{
|
||||||
AddRangeInternal(new Drawable[]
|
AddRangeInternal(new Drawable[]
|
||||||
{
|
{
|
||||||
new UpdateableBeatmapSetCover
|
new UpdateableBeatmapSetCover(BeatmapSetCoverType.List)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Y,
|
RelativeSizeAxes = Axes.Y,
|
||||||
Width = cover_width,
|
Width = cover_width,
|
||||||
BeatmapSet = beatmap.BeatmapSet,
|
BeatmapSet = beatmap.BeatmapSet,
|
||||||
CoverType = BeatmapSetCoverType.List,
|
|
||||||
},
|
},
|
||||||
new Container
|
new Container
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user