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

Merge pull request #179 from Tom94/beatmap-backgrounds

Update the background according to the currently selected beatmap and…
This commit is contained in:
Dean Herbert 2016-11-21 11:57:17 +09:00 committed by GitHub
commit 0e27d2ba2f
7 changed files with 114 additions and 11 deletions

@ -1 +1 @@
Subproject commit 3163342d5b00f7cd125fdca71f8cc1590a6237cf
Subproject commit 37d53e32e58104c8e743efad855019c39edeb6b2

View File

@ -15,19 +15,19 @@ using osu.Framework.Allocation;
namespace osu.Game.Graphics.Background
{
class Background : Container
public class Background : BufferedContainer
{
protected Sprite BackgroundSprite;
public Sprite Sprite;
string textureName;
public Background(string textureName = @"Backgrounds/bg1")
public Background(string textureName = @"")
{
this.textureName = textureName;
RelativeSizeAxes = Axes.Both;
Depth = float.MinValue;
Add(BackgroundSprite = new Sprite
Add(Sprite = new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
@ -38,13 +38,14 @@ namespace osu.Game.Graphics.Background
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
BackgroundSprite.Texture = textures.Get(textureName);
if (!string.IsNullOrEmpty(textureName))
Sprite.Texture = textures.Get(textureName);
}
protected override void Update()
{
base.Update();
BackgroundSprite.Scale = new Vector2(Math.Max(DrawSize.X / BackgroundSprite.DrawSize.X, DrawSize.Y / BackgroundSprite.DrawSize.Y));
Sprite.Scale = new Vector2(Math.Max(DrawSize.X / Sprite.DrawSize.X, DrawSize.Y / Sprite.DrawSize.Y));
}
}
}

View File

@ -0,0 +1,76 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Transformations;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Background;
namespace osu.Game.Screens.Backgrounds
{
public class BackgroundModeBeatmap : BackgroundMode
{
private Background background;
private WorkingBeatmap beatmap;
public WorkingBeatmap Beatmap
{
get
{
return beatmap;
}
set
{
if (beatmap == value)
return;
beatmap = value;
Background oldBackground = background;
addBackground(background = new Background());
background.Sprite.Texture = beatmap.Background;
if (oldBackground != null)
{
oldBackground.Depth = 1;
oldBackground.Flush();
oldBackground.FadeOut(500);
oldBackground.Expire();
background.BlurSigma = oldBackground.BlurSigma;
}
}
}
public BackgroundModeBeatmap(WorkingBeatmap beatmap)
{
Beatmap = beatmap;
}
private void addBackground(Background background)
{
background.CacheDrawnFrameBuffer = true;
Add(background);
}
public void BlurTo(Vector2 sigma, double duration)
{
background?.BlurTo(sigma, duration, EasingTypes.OutExpo);
}
protected override void Update()
{
base.Update();
}
public override bool Equals(BackgroundMode other)
{
return base.Equals(other) && beatmap == ((BackgroundModeBeatmap)other).Beatmap;
}
}
}

View File

@ -12,7 +12,7 @@ namespace osu.Game.Screens.Backgrounds
[BackgroundDependencyLoader]
private void load(BaseGame game)
{
Add(new Background());
Add(new Background(@"Backgrounds/bg1"));
}
}
}

View File

@ -30,13 +30,16 @@ namespace osu.Game.Screens.Play
private BeatmapDatabase database;
private BeatmapGroup selectedBeatmapGroup;
private BeatmapInfo selectedBeatmapInfo;
// TODO: use currently selected track as bg
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
protected override BackgroundMode CreateBackground() => new BackgroundModeBeatmap(Beatmap);
private ScrollContainer scrollContainer;
private FlowContainer beatmapSetFlow;
private TrackManager trackManager;
private Container wedgeContainer;
private static readonly Vector2 BACKGROUND_BLUR = new Vector2(20);
/// <param name="database">Optionally provide a database to use instead of the OsuGame one.</param>
public PlaySongSelect(BeatmapDatabase database = null)
{
@ -150,10 +153,14 @@ namespace osu.Game.Screens.Play
base.OnEntering(last);
ensurePlayingSelected();
wedgeContainer.FadeInFromZero(250);
(Background as BackgroundModeBeatmap)?.BlurTo(BACKGROUND_BLUR, 1000);
}
protected override void OnResuming(GameMode last)
{
(Background as BackgroundModeBeatmap)?.BlurTo(BACKGROUND_BLUR, 1000);
ensurePlayingSelected();
base.OnResuming(last);
}
@ -175,6 +182,15 @@ namespace osu.Game.Screens.Play
protected override void OnBeatmapChanged(WorkingBeatmap beatmap)
{
base.OnBeatmapChanged(beatmap);
var backgroundModeBeatmap = Background as BackgroundModeBeatmap;
if (backgroundModeBeatmap != null)
{
backgroundModeBeatmap.Beatmap = beatmap;
// TODO: Remove this once we have non-nullable Beatmap
(Background as BackgroundModeBeatmap)?.BlurTo(BACKGROUND_BLUR, 1000);
}
selectBeatmap(beatmap.BeatmapInfo);
}

View File

@ -16,6 +16,8 @@ using osu.Game.Modes.Objects.Drawables;
using osu.Game.Screens.Backgrounds;
using OpenTK.Input;
using MouseState = osu.Framework.Input.MouseState;
using OpenTK;
using osu.Framework.GameModes;
namespace osu.Game.Screens.Play
{
@ -23,7 +25,7 @@ namespace osu.Game.Screens.Play
{
public bool Autoplay;
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
protected override BackgroundMode CreateBackground() => null;
internal override bool ShowOverlays => false;
@ -106,6 +108,13 @@ namespace osu.Game.Screens.Play
};
}
protected override void OnEntering(GameMode last)
{
base.OnEntering(last);
(Background as BackgroundModeBeatmap)?.BlurTo(Vector2.Zero, 1000);
}
protected override void Update()
{
base.Update();

View File

@ -86,6 +86,7 @@
<Compile Include="Beatmaps\Timing\TimingChange.cs" />
<Compile Include="Configuration\OsuConfigManager.cs" />
<Compile Include="Screens\BackgroundMode.cs" />
<Compile Include="Screens\Backgrounds\BackgroundModeBeatmap.cs" />
<Compile Include="Screens\Backgrounds\BackgroundModeCustom.cs" />
<Compile Include="Screens\Backgrounds\BackgroundModeDefault.cs" />
<Compile Include="Screens\Backgrounds\BackgroundModeEmpty.cs" />