diff --git a/osu-framework b/osu-framework index 3163342d5b..2a835c818c 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 3163342d5b00f7cd125fdca71f8cc1590a6237cf +Subproject commit 2a835c818ca17e725cc719360e01dbda0d95326a diff --git a/osu.Game/Graphics/Background/Background.cs b/osu.Game/Graphics/Background/Background.cs index e04c2dc2d2..4698557c96 100644 --- a/osu.Game/Graphics/Background/Background.cs +++ b/osu.Game/Graphics/Background/Background.cs @@ -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)); } } } diff --git a/osu.Game/Screens/Backgrounds/BackgroundModeBeatmap.cs b/osu.Game/Screens/Backgrounds/BackgroundModeBeatmap.cs new file mode 100644 index 0000000000..e1a2445245 --- /dev/null +++ b/osu.Game/Screens/Backgrounds/BackgroundModeBeatmap.cs @@ -0,0 +1,76 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//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; + } + } +} diff --git a/osu.Game/Screens/Backgrounds/BackgroundModeDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundModeDefault.cs index aec43212f5..8a7be3e03a 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundModeDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundModeDefault.cs @@ -12,7 +12,7 @@ namespace osu.Game.Screens.Backgrounds [BackgroundDependencyLoader] private void load(BaseGame game) { - Add(new Background()); + Add(new Background(@"Backgrounds/bg1")); } } } \ No newline at end of file diff --git a/osu.Game/Screens/Play/PlaySongSelect.cs b/osu.Game/Screens/Play/PlaySongSelect.cs index 4c4c188e04..9a95e1eb55 100644 --- a/osu.Game/Screens/Play/PlaySongSelect.cs +++ b/osu.Game/Screens/Play/PlaySongSelect.cs @@ -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); + /// Optionally provide a database to use instead of the OsuGame one. 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); } diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index d0aea37bed..c4641b9b6a 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -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(); diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index bdf3ed139b..8df8917e06 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -86,6 +86,7 @@ +