1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 19:22:54 +08:00

Async medal sprite loading.

This commit is contained in:
DrabWeb 2017-07-11 22:12:49 -03:00
parent 2ee0f3f5f6
commit 16bb96e6aa
2 changed files with 34 additions and 10 deletions

View File

@ -56,6 +56,7 @@ namespace osu.Game.Overlays
{
RelativeSizeAxes = Axes.Both;
Alpha = 0f;
AlwaysPresent = true;
Children = new Drawable[]
{
@ -120,6 +121,7 @@ namespace osu.Game.Overlays
Origin = Anchor.Centre,
Alpha = 0f,
Masking = true,
AlwaysPresent = true,
BorderColour = Color4.White,
BorderThickness = border_width,
Size = new Vector2(DISC_SIZE),
@ -151,6 +153,8 @@ namespace osu.Game.Overlays
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.X,
AlwaysPresent = true,
OnSpriteLoadComplete = drawable => Show(),
},
},
},
@ -171,12 +175,6 @@ namespace osu.Game.Overlays
};
}
protected override void LoadComplete()
{
base.LoadComplete();
Show();
}
protected override void Update()
{
base.Update();
@ -247,6 +245,7 @@ namespace osu.Game.Overlays
{
if (drawableMedal.Transforms.Count != 0) return;
Hide();
Expire();
}
private class BackgroundStrip : Container

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic;
using OpenTK;
using osu.Framework.Allocation;
@ -21,16 +22,19 @@ namespace osu.Game.Overlays.MedalSplash
private readonly Medal medal;
private readonly Container medalContainer;
private readonly Sprite medalGlow, medalSprite;
private readonly Sprite medalGlow;
private readonly OsuSpriteText unlocked, name;
private readonly TextFlowContainer description;
private readonly FillFlowContainer infoFlow;
private readonly IEnumerable<SpriteText> descriptionSprites;
public Action<Drawable> OnSpriteLoadComplete;
public DrawableMedal(Medal medal)
{
this.medal = medal;
Position = new Vector2(0f, MedalOverlay.DISC_SIZE / 2);
AlwaysPresent = true;
Children = new Drawable[]
{
@ -40,12 +44,17 @@ namespace osu.Game.Overlays.MedalSplash
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Alpha = 0f,
Children = new[]
AlwaysPresent = true,
Children = new Drawable[]
{
medalSprite = new Sprite
new AsyncLoadWrapper(new MedalSprite(medal)
{
OnLoadComplete = drawable => OnSpriteLoadComplete?.Invoke(drawable),
})
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Both,
Scale = new Vector2(0.81f),
},
medalGlow = new Sprite
@ -110,7 +119,6 @@ namespace osu.Game.Overlays.MedalSplash
[BackgroundDependencyLoader]
private void load(OsuColour colours, TextureStore textures)
{
medalSprite.Texture = textures.Get(medal.ImageUrl);
medalGlow.Texture = textures.Get(@"MedalSplash/medal-glow");
foreach (var s in descriptionSprites)
@ -149,5 +157,22 @@ namespace osu.Game.Overlays.MedalSplash
MedalUnlocked,
Full,
}
private class MedalSprite : Sprite
{
private readonly Medal medal;
public MedalSprite(Medal medal)
{
this.medal = medal;
}
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
if (medal?.InternalName != null)
Texture = textures.Get(medal.ImageUrl);
}
}
}
}