From 0d3c032d2180c9560dc3cca9b7cf0cc57adb29c0 Mon Sep 17 00:00:00 2001 From: Maciej <3stylemylife@gmail.com> Date: Mon, 7 Nov 2016 03:11:47 +0100 Subject: [PATCH] Code fixes and Background Implementation --- .../Backgrounds/BackgroundModeCustom.cs | 9 ++++++++- osu.Game/GameModes/Play/PlaySongSelect.cs | 20 +++++++------------ osu.Game/GameModes/Play/Player.cs | 5 ++++- osu.Game/Graphics/Background/Background.cs | 11 +++++++++- 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/osu.Game/GameModes/Backgrounds/BackgroundModeCustom.cs b/osu.Game/GameModes/Backgrounds/BackgroundModeCustom.cs index a603b3904e..a04f50f139 100644 --- a/osu.Game/GameModes/Backgrounds/BackgroundModeCustom.cs +++ b/osu.Game/GameModes/Backgrounds/BackgroundModeCustom.cs @@ -2,6 +2,7 @@ //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework; +using osu.Framework.Graphics.Textures; using osu.Game.Graphics.Background; namespace osu.Game.GameModes.Backgrounds @@ -9,16 +10,22 @@ namespace osu.Game.GameModes.Backgrounds public class BackgroundModeCustom : BackgroundMode { private readonly string textureName; + private readonly Texture texture; public BackgroundModeCustom(string textureName) { this.textureName = textureName; } + public BackgroundModeCustom(Texture texture) + { + this.texture = texture; + } + protected override void Load(BaseGame game) { base.Load(game); - Add(new Background(textureName)); + Add((texture != null) ? new Background(texture) : new Background(textureName)); } public override bool Equals(BackgroundMode other) diff --git a/osu.Game/GameModes/Play/PlaySongSelect.cs b/osu.Game/GameModes/Play/PlaySongSelect.cs index fcd29384e9..72b9dddd42 100644 --- a/osu.Game/GameModes/Play/PlaySongSelect.cs +++ b/osu.Game/GameModes/Play/PlaySongSelect.cs @@ -21,7 +21,7 @@ using osu.Game.Beatmaps.Drawable; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Game.Beatmaps; using osu.Framework.GameModes; -using osu.Game.Graphics; +using osu.Game.Graphics.Background; namespace osu.Game.GameModes.Play { @@ -36,30 +36,25 @@ namespace osu.Game.GameModes.Play private FlowContainer beatmapSetFlow; private TrackManager trackManager; private Container wedgeContainer; - private Sprite background; + + private BackgroundMode background; + protected override BackgroundMode CreateBackground() => background; /// Optionally provide a database to use instead of the OsuGame one. public PlaySongSelect(BeatmapDatabase database = null) { this.database = database; + background = new BackgroundModeDefault(); + const float scrollWidth = 640; const float bottomToolHeight = 50; const float topToolHeight = 50; Children = new Drawable[] { - background = new Sprite { - RelativeSizeAxes = Axes.Both, - RelativePositionAxes = Axes.Both, - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Size = Vector2.One, - Alpha = 0.5f, - }, wedgeContainer = new Container { RelativeSizeAxes = Axes.Both, - Size = Vector2.One, Padding = new MarginPadding { Right = scrollWidth - 200, Bottom = bottomToolHeight, Top = topToolHeight }, Children = new[] { @@ -230,7 +225,6 @@ namespace osu.Game.GameModes.Play if (!beatmap.Equals(Beatmap?.BeatmapInfo)) { Beatmap = database.GetWorkingBeatmap(beatmap, Beatmap); - background.Texture = Beatmap.Background; } ensurePlayingSelected(); @@ -304,7 +298,7 @@ namespace osu.Game.GameModes.Play if (database.Query().Count() > 0) foreach (var beatmapSet in database.Query()) addBeatmapSet(beatmapSet); - else playButton.Dispose(); // not sure about this + else playButton.Hide(); } } } diff --git a/osu.Game/GameModes/Play/Player.cs b/osu.Game/GameModes/Play/Player.cs index d48e252fa5..4a412ced15 100644 --- a/osu.Game/GameModes/Play/Player.cs +++ b/osu.Game/GameModes/Play/Player.cs @@ -20,7 +20,8 @@ namespace osu.Game.GameModes.Play { const bool autoplay = false; - protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4"); + private BackgroundMode background; + protected override BackgroundMode CreateBackground() => background; public BeatmapInfo BeatmapInfo; @@ -49,6 +50,8 @@ namespace osu.Game.GameModes.Play AudioTrack track = Beatmap.Track; + background = new BackgroundModeCustom(Beatmap.Background); + if (track != null) { game.Audio.Track.SetExclusive(track); diff --git a/osu.Game/Graphics/Background/Background.cs b/osu.Game/Graphics/Background/Background.cs index 8d004dcf86..17a95f4eeb 100644 --- a/osu.Game/Graphics/Background/Background.cs +++ b/osu.Game/Graphics/Background/Background.cs @@ -10,6 +10,7 @@ using OpenTK.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework; using System.Threading.Tasks; +using osu.Framework.Graphics.Textures; namespace osu.Game.Graphics.Background { @@ -17,6 +18,7 @@ namespace osu.Game.Graphics.Background { protected Sprite BackgroundSprite; + Texture texture; string textureName; public Background(string textureName = @"Backgrounds/bg1") @@ -26,13 +28,20 @@ namespace osu.Game.Graphics.Background Depth = float.MinValue; } + public Background(Texture texture) + { + this.texture = texture; + RelativeSizeAxes = Axes.Both; + Depth = float.MinValue; + } + protected override void Load(BaseGame game) { base.Load(game); Add(BackgroundSprite = new Sprite { - Texture = game.Textures.Get(textureName), + Texture = texture != null ? texture : game.Textures.Get(textureName), Anchor = Anchor.Centre, Origin = Anchor.Centre, Colour = Color4.DarkGray