mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 18:52:55 +08:00
Async load of panel backgrounds (failing for on-screen panels).
This commit is contained in:
parent
2ba365657e
commit
0109c79cae
@ -14,6 +14,7 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Framework.Graphics.Colour;
|
using osu.Framework.Graphics.Colour;
|
||||||
|
using osu.Framework;
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps.Drawable
|
namespace osu.Game.Beatmaps.Drawable
|
||||||
{
|
{
|
||||||
@ -25,40 +26,6 @@ namespace osu.Game.Beatmaps.Drawable
|
|||||||
private OsuConfigManager config;
|
private OsuConfigManager config;
|
||||||
private Bindable<bool> preferUnicode;
|
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)
|
public BeatmapSetHeader(BeatmapSetInfo beatmapSet, WorkingBeatmap working)
|
||||||
{
|
{
|
||||||
this.beatmapSet = beatmapSet;
|
this.beatmapSet = beatmapSet;
|
||||||
@ -70,12 +37,9 @@ namespace osu.Game.Beatmaps.Drawable
|
|||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Children = new Framework.Graphics.Drawable[]
|
Children = new Framework.Graphics.Drawable[]
|
||||||
{
|
{
|
||||||
working.Background == null ? new Box{ RelativeSizeAxes = Axes.Both, Colour = new Color4(200, 200, 200, 255) } : new Sprite
|
new PanelBackground(working)
|
||||||
{
|
{
|
||||||
Texture = working.Background,
|
RelativeSizeAxes = Axes.Both
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
Scale = new Vector2(1366 / working.Background.Width * 0.6f),
|
|
||||||
},
|
},
|
||||||
new FlowContainer
|
new FlowContainer
|
||||||
{
|
{
|
||||||
@ -152,5 +116,85 @@ 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user