From 0109c79caebae55d4e0cf65b8f064758614b4eed Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 22 Nov 2016 19:48:03 +0900 Subject: [PATCH] Async load of panel backgrounds (failing for on-screen panels). --- .../Beatmaps/Drawable/BeatmapSetHeader.cs | 124 ++++++++++++------ 1 file changed, 84 insertions(+), 40 deletions(-) diff --git a/osu.Game/Beatmaps/Drawable/BeatmapSetHeader.cs b/osu.Game/Beatmaps/Drawable/BeatmapSetHeader.cs index e42a6271c6..b97b955ec5 100644 --- a/osu.Game/Beatmaps/Drawable/BeatmapSetHeader.cs +++ b/osu.Game/Beatmaps/Drawable/BeatmapSetHeader.cs @@ -14,6 +14,7 @@ using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Game.Configuration; using osu.Framework.Graphics.Colour; +using osu.Framework; namespace osu.Game.Beatmaps.Drawable { @@ -25,40 +26,6 @@ namespace osu.Game.Beatmaps.Drawable private OsuConfigManager config; private Bindable preferUnicode; - protected override void Selected() - { - base.Selected(); - - GainedSelection?.Invoke(this); - } - - protected override void Deselected() - { - base.Deselected(); - } - - [BackgroundDependencyLoader] - private void load(OsuConfigManager config) - { - this.config = config; - - preferUnicode = config.GetBindable(OsuConfig.ShowUnicode); - preferUnicode.ValueChanged += preferUnicode_changed; - preferUnicode_changed(preferUnicode, null); - } - private void preferUnicode_changed(object sender, EventArgs e) - { - title.Text = config.GetUnicodeString(beatmapSet.Metadata.Title, beatmapSet.Metadata.TitleUnicode); - artist.Text = config.GetUnicodeString(beatmapSet.Metadata.Artist, beatmapSet.Metadata.ArtistUnicode); - } - - protected override void Dispose(bool isDisposing) - { - if (preferUnicode != null) - preferUnicode.ValueChanged -= preferUnicode_changed; - base.Dispose(isDisposing); - } - public BeatmapSetHeader(BeatmapSetInfo beatmapSet, WorkingBeatmap working) { this.beatmapSet = beatmapSet; @@ -70,12 +37,9 @@ namespace osu.Game.Beatmaps.Drawable RelativeSizeAxes = Axes.Both, Children = new Framework.Graphics.Drawable[] { - working.Background == null ? new Box{ RelativeSizeAxes = Axes.Both, Colour = new Color4(200, 200, 200, 255) } : new Sprite - { - Texture = working.Background, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Scale = new Vector2(1366 / working.Background.Width * 0.6f), + new PanelBackground(working) + { + RelativeSizeAxes = Axes.Both }, new FlowContainer { @@ -151,6 +115,86 @@ namespace osu.Game.Beatmaps.Drawable } } }; + } + + protected override void Selected() + { + base.Selected(); + GainedSelection?.Invoke(this); + } + + [BackgroundDependencyLoader] + private void load(OsuConfigManager config) + { + this.config = config; + + preferUnicode = config.GetBindable(OsuConfig.ShowUnicode); + preferUnicode.ValueChanged += preferUnicode_changed; + preferUnicode_changed(preferUnicode, null); + } + private void preferUnicode_changed(object sender, EventArgs e) + { + title.Text = config.GetUnicodeString(beatmapSet.Metadata.Title, beatmapSet.Metadata.TitleUnicode); + artist.Text = config.GetUnicodeString(beatmapSet.Metadata.Artist, beatmapSet.Metadata.ArtistUnicode); + } + + protected override void Dispose(bool isDisposing) + { + if (preferUnicode != null) + preferUnicode.ValueChanged -= preferUnicode_changed; + base.Dispose(isDisposing); + } + + class PanelBackground : Container + { + private readonly WorkingBeatmap working; + + private AsyncBackground backgroundSprite; + + public PanelBackground(WorkingBeatmap working) + { + this.working = working; + } + + [BackgroundDependencyLoader] + private void load(OsuGameBase game) + { + OnUpdate += () => + { + //todo: masking check + if (backgroundSprite == null) + { + //moving this to ctor fixes the issue. + (backgroundSprite = new AsyncBackground(working) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }).Preload(game, Add); + } + }; + } + + class AsyncBackground : Sprite + { + private readonly WorkingBeatmap working; + + public AsyncBackground(WorkingBeatmap working) + { + this.working = working; + } + + [BackgroundDependencyLoader] + private void load(OsuGameBase game) + { + Texture = working.Background; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + Scale = new Vector2(1366 / (Texture?.Width ?? 1) * 0.6f); + } + } } } } \ No newline at end of file