From 61a7ccaece26176fdcc45fc3be3d89f1793029a4 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 20 Oct 2016 13:55:04 -0400 Subject: [PATCH] Remove dependency on DeferredSprite --- osu.Game/GameModes/Play/BeatmapGroup.cs | 51 ++++++++++++++++++----- osu.Game/GameModes/Play/PlaySongSelect.cs | 2 + 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/osu.Game/GameModes/Play/BeatmapGroup.cs b/osu.Game/GameModes/Play/BeatmapGroup.cs index 648977dc1c..2a6c9a382f 100644 --- a/osu.Game/GameModes/Play/BeatmapGroup.cs +++ b/osu.Game/GameModes/Play/BeatmapGroup.cs @@ -16,12 +16,14 @@ using osu.Framework.Input; using OpenTK.Graphics; using osu.Game.Beatmaps.IO; using osu.Framework.Graphics.Textures; - +using System.Threading.Tasks; + namespace osu.Game.GameModes.Play { class BeatmapGroup : AutoSizeContainer { private const float collapsedAlpha = 0.5f; + private const float collapsedWidth = 0.8f; private BeatmapInfo selectedBeatmap; public BeatmapInfo SelectedBeatmap @@ -58,9 +60,15 @@ namespace osu.Game.GameModes.Play EndTime = Time + 250, }); if (collapsed) - topContainer.Remove(difficulties, false); + { + topContainer.Remove(difficulties); + setBox.Size = new Vector2(collapsedWidth, -1); + } else + { topContainer.Add(difficulties); + setBox.Size = new Vector2(1, -1); + } setBox.BorderColour = new Color4( setBox.BorderColour.R, setBox.BorderColour.G, @@ -84,7 +92,16 @@ namespace osu.Game.GameModes.Play RelativeSizeAxes = Axes.X, Size = new Vector2(1, -1), 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 @@ -111,12 +128,15 @@ namespace osu.Game.GameModes.Play class BeatmapSetBox : AutoSizeContainer { private BeatmapSetInfo beatmapSet; + private BeatmapResourceStore beatmapStore; + private TextureStore resources; + private Sprite backgroundImage; public BeatmapSetBox(BeatmapSetInfo beatmapSet, BeatmapResourceStore beatmapStore, TextureStore resources) { this.beatmapSet = beatmapSet; - RelativeSizeAxes = Axes.X; - Size = new Vector2(1, -1); + this.beatmapStore = beatmapStore; + this.resources = resources; Masking = true; CornerRadius = 5; BorderThickness = 2; @@ -136,17 +156,12 @@ namespace osu.Game.GameModes.Play Size = Vector2.One, Children = new Drawable[] { - new DeferredSprite + backgroundImage = new Sprite { RelativeSizeAxes = Axes.X, Size = new Vector2(1, 0), Anchor = Anchor.Centre, Origin = Anchor.Centre, - ResolveTexture = () => - { - beatmapStore.AddBeatmap(beatmapSet); - return resources.Get($@"{beatmapSet.BeatmapSetID}:{beatmapSet.Metadata.BackgroundFile}"); - }, }, 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 diff --git a/osu.Game/GameModes/Play/PlaySongSelect.cs b/osu.Game/GameModes/Play/PlaySongSelect.cs index 20c17c3bbe..ce29496d40 100644 --- a/osu.Game/GameModes/Play/PlaySongSelect.cs +++ b/osu.Game/GameModes/Play/PlaySongSelect.cs @@ -154,6 +154,8 @@ namespace osu.Game.GameModes.Play base.Dispose(isDisposing); if (playMode != null) playMode.ValueChanged -= PlayMode_ValueChanged; + if (beatmapResources != null) + beatmapResources.Dispose(); } private void PlayMode_ValueChanged(object sender, EventArgs e)