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

Async load of panel backgrounds (failing for on-screen panels).

This commit is contained in:
Dean Herbert 2016-11-22 19:48:03 +09:00
parent 2ba365657e
commit 0109c79cae

View File

@ -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<bool> 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<bool>(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<bool>(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);
}
}
}
}
}