1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 07:22:55 +08:00

Refactor BeatmapInfoWedge to be async.

This commit is contained in:
Dean Herbert 2016-11-24 13:48:48 +09:00
parent 1eb04ff11e
commit ece3bc0e01
5 changed files with 56 additions and 39 deletions

View File

@ -0,0 +1,24 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Graphics.Sprites;
namespace osu.Game.Beatmaps.Drawables
{
class BeatmapBackgroundSprite : Sprite
{
private readonly WorkingBeatmap working;
public BeatmapBackgroundSprite(WorkingBeatmap working)
{
this.working = working;
}
[BackgroundDependencyLoader]
private void load(OsuGameBase game)
{
Texture = working.Background;
}
}
}

View File

@ -156,38 +156,17 @@ namespace osu.Game.Beatmaps.Drawables
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuGameBase game) private void load(OsuGameBase game)
{ {
new BeatmapBackground(working) new BeatmapBackgroundSprite(working)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
FillMode = FillMode.Fill,
}.Preload(game, (bg) => }.Preload(game, (bg) =>
{ {
Add(bg); Add(bg);
ForceRedraw(); ForceRedraw();
}); });
} }
class BeatmapBackground : Sprite
{
private readonly WorkingBeatmap working;
public BeatmapBackground(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);
}
}
} }
} }
} }

View File

@ -1,4 +1,6 @@
using System; using System;
using osu.Framework;
using osu.Framework.Allocation;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -8,31 +10,37 @@ using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Database; using osu.Game.Database;
using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Colour;
using osu.Game.Beatmaps.Drawables;
namespace osu.Game.Screens.Select namespace osu.Game.Screens.Select
{ {
class BeatmapInfoOverlay : Container class BeatmapInfoWedge : Container
{ {
private Container beatmapInfoContainer; private Container beatmapInfoContainer;
private BaseGame game;
[BackgroundDependencyLoader]
private void load(BaseGame game)
{
this.game = game;
}
public void UpdateBeatmap(WorkingBeatmap beatmap) public void UpdateBeatmap(WorkingBeatmap beatmap)
{ {
if (beatmap == null) if (beatmap == null)
return; return;
float newDepth = 0; var lastContainer = beatmapInfoContainer;
if (beatmapInfoContainer != null)
{ float newDepth = lastContainer?.Depth - 1 ?? 0;
newDepth = beatmapInfoContainer.Depth - 1;
beatmapInfoContainer.FadeOut(250);
beatmapInfoContainer.Expire();
}
FadeIn(250); FadeIn(250);
BeatmapSetInfo beatmapSetInfo = beatmap.BeatmapSetInfo; BeatmapSetInfo beatmapSetInfo = beatmap.BeatmapSetInfo;
BeatmapInfo beatmapInfo = beatmap.BeatmapInfo; BeatmapInfo beatmapInfo = beatmap.BeatmapInfo;
Add(beatmapInfoContainer = new BufferedContainer
(beatmapInfoContainer = new BufferedContainer
{ {
Depth = newDepth, Depth = newDepth,
PixelSnapping = true, PixelSnapping = true,
@ -51,18 +59,17 @@ namespace osu.Game.Screens.Select
}, },
// We use a container, such that we can set the colour gradient to go across the // We use a container, such that we can set the colour gradient to go across the
// vertices of the masked container instead of the vertices of the (larger) sprite. // vertices of the masked container instead of the vertices of the (larger) sprite.
beatmap.Background == null ? new Container() : new Container new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
ColourInfo = ColourInfo.GradientVertical(Color4.White, new Color4(1f, 1f, 1f, 0.3f)), ColourInfo = ColourInfo.GradientVertical(Color4.White, new Color4(1f, 1f, 1f, 0.3f)),
Children = new [] Children = new []
{ {
// Zoomed-in and cropped beatmap background // Zoomed-in and cropped beatmap background
new Sprite new BeatmapBackgroundSprite(beatmap)
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Texture = beatmap.Background,
FillMode = FillMode.Fill, FillMode = FillMode.Fill,
}, },
}, },
@ -117,6 +124,12 @@ namespace osu.Game.Screens.Select
} }
} }
} }
}).Preload(game, delegate(Drawable d)
{
lastContainer?.FadeOut(250);
lastContainer?.Expire();
Add(d);
}); });
} }
} }

View File

@ -40,7 +40,7 @@ namespace osu.Game.Screens.Select
private static readonly Vector2 wedged_container_size = new Vector2(0.5f, 225); private static readonly Vector2 wedged_container_size = new Vector2(0.5f, 225);
private static readonly Vector2 wedged_container_shear = new Vector2(0.15f, 0); private static readonly Vector2 wedged_container_shear = new Vector2(0.15f, 0);
private static readonly Vector2 wedged_container_start_position = new Vector2(0, 50); private static readonly Vector2 wedged_container_start_position = new Vector2(0, 50);
private BeatmapInfoWedge wedgedBeatmapInfoWedge; private BeatmapInfoWedge beatmapInfoWedge;
private static readonly Vector2 BACKGROUND_BLUR = new Vector2(20); private static readonly Vector2 BACKGROUND_BLUR = new Vector2(20);
private CancellationTokenSource initialAddSetsTask; private CancellationTokenSource initialAddSetsTask;
@ -102,7 +102,7 @@ namespace osu.Game.Screens.Select
Anchor = Anchor.CentreRight, Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight, Origin = Anchor.CentreRight,
}, },
wedgedBeatmapInfoWedge = new BeatmapInfoWedge beatmapInfoWedge = new BeatmapInfoWedge
{ {
Alpha = 0, Alpha = 0,
Position = wedged_container_start_position, Position = wedged_container_start_position,
@ -239,7 +239,7 @@ namespace osu.Game.Screens.Select
(Background as BackgroundModeBeatmap)?.BlurTo(BACKGROUND_BLUR, 1000); (Background as BackgroundModeBeatmap)?.BlurTo(BACKGROUND_BLUR, 1000);
} }
wedgedBeatmapInfoWedge.UpdateBeatmap(beatmap); beatmapInfoWedge.UpdateBeatmap(beatmap);
} }
/// <summary> /// <summary>

View File

@ -63,6 +63,7 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Beatmaps\Drawables\BeatmapBackgroundSprite.cs" />
<Compile Include="Modes\HitJudgementResolver.cs" /> <Compile Include="Modes\HitJudgementResolver.cs" />
<Compile Include="Modes\Objects\HitObjectParser.cs" /> <Compile Include="Modes\Objects\HitObjectParser.cs" />
<Compile Include="Overlays\DragBar.cs" /> <Compile Include="Overlays\DragBar.cs" />
@ -159,7 +160,7 @@
<Compile Include="Overlays\ToolbarModeButton.cs" /> <Compile Include="Overlays\ToolbarModeButton.cs" />
<Compile Include="Overlays\ToolbarModeSelector.cs" /> <Compile Include="Overlays\ToolbarModeSelector.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Screens\Select\BeatmapInfoOverlay.cs" /> <Compile Include="Screens\Select\BeatmapInfoWedge.cs" />
<Compile Include="Users\User.cs" /> <Compile Include="Users\User.cs" />
<Compile Include="Graphics\UserInterface\Volume\VolumeControl.cs" /> <Compile Include="Graphics\UserInterface\Volume\VolumeControl.cs" />
<Compile Include="Database\BeatmapDatabase.cs" /> <Compile Include="Database\BeatmapDatabase.cs" />