1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 20:53:00 +08:00

Remove dependency on DeferredSprite

This commit is contained in:
Drew DeVault 2016-10-20 13:55:04 -04:00
parent 33fc60716d
commit 61a7ccaece
2 changed files with 42 additions and 11 deletions

View File

@ -16,12 +16,14 @@ using osu.Framework.Input;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Game.Beatmaps.IO; using osu.Game.Beatmaps.IO;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using System.Threading.Tasks;
namespace osu.Game.GameModes.Play namespace osu.Game.GameModes.Play
{ {
class BeatmapGroup : AutoSizeContainer class BeatmapGroup : AutoSizeContainer
{ {
private const float collapsedAlpha = 0.5f; private const float collapsedAlpha = 0.5f;
private const float collapsedWidth = 0.8f;
private BeatmapInfo selectedBeatmap; private BeatmapInfo selectedBeatmap;
public BeatmapInfo SelectedBeatmap public BeatmapInfo SelectedBeatmap
@ -58,9 +60,15 @@ namespace osu.Game.GameModes.Play
EndTime = Time + 250, EndTime = Time + 250,
}); });
if (collapsed) if (collapsed)
topContainer.Remove(difficulties, false); {
topContainer.Remove(difficulties);
setBox.Size = new Vector2(collapsedWidth, -1);
}
else else
{
topContainer.Add(difficulties); topContainer.Add(difficulties);
setBox.Size = new Vector2(1, -1);
}
setBox.BorderColour = new Color4( setBox.BorderColour = new Color4(
setBox.BorderColour.R, setBox.BorderColour.R,
setBox.BorderColour.G, setBox.BorderColour.G,
@ -84,7 +92,16 @@ namespace osu.Game.GameModes.Play
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Size = new Vector2(1, -1), Size = new Vector2(1, -1),
Direction = FlowDirection.VerticalOnly, Direction = FlowDirection.VerticalOnly,
Children = new[] { setBox = new BeatmapSetBox(beatmapSet, beatmapStore, resources) } Children = new[]
{
setBox = new BeatmapSetBox(beatmapSet, beatmapStore, resources)
{
RelativeSizeAxes = Axes.X,
Size = new Vector2(collapsedWidth, -1),
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
}
}
} }
}; };
difficulties = new FlowContainer // Deliberately not added to children difficulties = new FlowContainer // Deliberately not added to children
@ -111,12 +128,15 @@ namespace osu.Game.GameModes.Play
class BeatmapSetBox : AutoSizeContainer class BeatmapSetBox : AutoSizeContainer
{ {
private BeatmapSetInfo beatmapSet; private BeatmapSetInfo beatmapSet;
private BeatmapResourceStore beatmapStore;
private TextureStore resources;
private Sprite backgroundImage;
public BeatmapSetBox(BeatmapSetInfo beatmapSet, BeatmapResourceStore beatmapStore, TextureStore resources) public BeatmapSetBox(BeatmapSetInfo beatmapSet, BeatmapResourceStore beatmapStore, TextureStore resources)
{ {
this.beatmapSet = beatmapSet; this.beatmapSet = beatmapSet;
RelativeSizeAxes = Axes.X; this.beatmapStore = beatmapStore;
Size = new Vector2(1, -1); this.resources = resources;
Masking = true; Masking = true;
CornerRadius = 5; CornerRadius = 5;
BorderThickness = 2; BorderThickness = 2;
@ -136,17 +156,12 @@ namespace osu.Game.GameModes.Play
Size = Vector2.One, Size = Vector2.One,
Children = new Drawable[] Children = new Drawable[]
{ {
new DeferredSprite backgroundImage = new Sprite
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Size = new Vector2(1, 0), Size = new Vector2(1, 0),
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
ResolveTexture = () =>
{
beatmapStore.AddBeatmap(beatmapSet);
return resources.Get($@"{beatmapSet.BeatmapSetID}:{beatmapSet.Metadata.BackgroundFile}");
},
}, },
new Box // TODO: Gradient new Box // TODO: Gradient
{ {
@ -186,6 +201,20 @@ namespace osu.Game.GameModes.Play
} }
}; };
} }
public override void Load(Framework.BaseGame game)
{
base.Load(game);
if (beatmapSet.Metadata.BackgroundFile != null)
{
Task.Factory.StartNew(() =>
{
beatmapStore.AddBeatmap(beatmapSet);
var texture = resources.Get($@"{beatmapSet.BeatmapSetID}:{beatmapSet.Metadata.BackgroundFile}");
Scheduler.Add(() => backgroundImage.Texture = texture);
});
}
}
} }
class DifficultyIcon : Container class DifficultyIcon : Container

View File

@ -154,6 +154,8 @@ namespace osu.Game.GameModes.Play
base.Dispose(isDisposing); base.Dispose(isDisposing);
if (playMode != null) if (playMode != null)
playMode.ValueChanged -= PlayMode_ValueChanged; playMode.ValueChanged -= PlayMode_ValueChanged;
if (beatmapResources != null)
beatmapResources.Dispose();
} }
private void PlayMode_ValueChanged(object sender, EventArgs e) private void PlayMode_ValueChanged(object sender, EventArgs e)