1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-14 21:23:19 +08:00

Code fixes and Background Implementation

This commit is contained in:
Maciej 2016-11-07 03:11:47 +01:00
parent e33ca05b6c
commit 0d3c032d21
4 changed files with 29 additions and 16 deletions

View File

@ -2,6 +2,7 @@
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework; using osu.Framework;
using osu.Framework.Graphics.Textures;
using osu.Game.Graphics.Background; using osu.Game.Graphics.Background;
namespace osu.Game.GameModes.Backgrounds namespace osu.Game.GameModes.Backgrounds
@ -9,16 +10,22 @@ namespace osu.Game.GameModes.Backgrounds
public class BackgroundModeCustom : BackgroundMode public class BackgroundModeCustom : BackgroundMode
{ {
private readonly string textureName; private readonly string textureName;
private readonly Texture texture;
public BackgroundModeCustom(string textureName) public BackgroundModeCustom(string textureName)
{ {
this.textureName = textureName; this.textureName = textureName;
} }
public BackgroundModeCustom(Texture texture)
{
this.texture = texture;
}
protected override void Load(BaseGame game) protected override void Load(BaseGame game)
{ {
base.Load(game); base.Load(game);
Add(new Background(textureName)); Add((texture != null) ? new Background(texture) : new Background(textureName));
} }
public override bool Equals(BackgroundMode other) public override bool Equals(BackgroundMode other)

View File

@ -21,7 +21,7 @@ using osu.Game.Beatmaps.Drawable;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Framework.GameModes; using osu.Framework.GameModes;
using osu.Game.Graphics; using osu.Game.Graphics.Background;
namespace osu.Game.GameModes.Play namespace osu.Game.GameModes.Play
{ {
@ -36,30 +36,25 @@ namespace osu.Game.GameModes.Play
private FlowContainer beatmapSetFlow; private FlowContainer beatmapSetFlow;
private TrackManager trackManager; private TrackManager trackManager;
private Container wedgeContainer; private Container wedgeContainer;
private Sprite background;
private BackgroundMode background;
protected override BackgroundMode CreateBackground() => background;
/// <param name="database">Optionally provide a database to use instead of the OsuGame one.</param> /// <param name="database">Optionally provide a database to use instead of the OsuGame one.</param>
public PlaySongSelect(BeatmapDatabase database = null) public PlaySongSelect(BeatmapDatabase database = null)
{ {
this.database = database; this.database = database;
background = new BackgroundModeDefault();
const float scrollWidth = 640; const float scrollWidth = 640;
const float bottomToolHeight = 50; const float bottomToolHeight = 50;
const float topToolHeight = 50; const float topToolHeight = 50;
Children = new Drawable[] 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 wedgeContainer = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Size = Vector2.One,
Padding = new MarginPadding { Right = scrollWidth - 200, Bottom = bottomToolHeight, Top = topToolHeight }, Padding = new MarginPadding { Right = scrollWidth - 200, Bottom = bottomToolHeight, Top = topToolHeight },
Children = new[] Children = new[]
{ {
@ -230,7 +225,6 @@ namespace osu.Game.GameModes.Play
if (!beatmap.Equals(Beatmap?.BeatmapInfo)) if (!beatmap.Equals(Beatmap?.BeatmapInfo))
{ {
Beatmap = database.GetWorkingBeatmap(beatmap, Beatmap); Beatmap = database.GetWorkingBeatmap(beatmap, Beatmap);
background.Texture = Beatmap.Background;
} }
ensurePlayingSelected(); ensurePlayingSelected();
@ -304,7 +298,7 @@ namespace osu.Game.GameModes.Play
if (database.Query<BeatmapSetInfo>().Count() > 0) if (database.Query<BeatmapSetInfo>().Count() > 0)
foreach (var beatmapSet in database.Query<BeatmapSetInfo>()) foreach (var beatmapSet in database.Query<BeatmapSetInfo>())
addBeatmapSet(beatmapSet); addBeatmapSet(beatmapSet);
else playButton.Dispose(); // not sure about this else playButton.Hide();
} }
} }
} }

View File

@ -20,7 +20,8 @@ namespace osu.Game.GameModes.Play
{ {
const bool autoplay = false; const bool autoplay = false;
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4"); private BackgroundMode background;
protected override BackgroundMode CreateBackground() => background;
public BeatmapInfo BeatmapInfo; public BeatmapInfo BeatmapInfo;
@ -49,6 +50,8 @@ namespace osu.Game.GameModes.Play
AudioTrack track = Beatmap.Track; AudioTrack track = Beatmap.Track;
background = new BackgroundModeCustom(Beatmap.Background);
if (track != null) if (track != null)
{ {
game.Audio.Track.SetExclusive(track); game.Audio.Track.SetExclusive(track);

View File

@ -10,6 +10,7 @@ using OpenTK.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework; using osu.Framework;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Graphics.Textures;
namespace osu.Game.Graphics.Background namespace osu.Game.Graphics.Background
{ {
@ -17,6 +18,7 @@ namespace osu.Game.Graphics.Background
{ {
protected Sprite BackgroundSprite; protected Sprite BackgroundSprite;
Texture texture;
string textureName; string textureName;
public Background(string textureName = @"Backgrounds/bg1") public Background(string textureName = @"Backgrounds/bg1")
@ -26,13 +28,20 @@ namespace osu.Game.Graphics.Background
Depth = float.MinValue; Depth = float.MinValue;
} }
public Background(Texture texture)
{
this.texture = texture;
RelativeSizeAxes = Axes.Both;
Depth = float.MinValue;
}
protected override void Load(BaseGame game) protected override void Load(BaseGame game)
{ {
base.Load(game); base.Load(game);
Add(BackgroundSprite = new Sprite Add(BackgroundSprite = new Sprite
{ {
Texture = game.Textures.Get(textureName), Texture = texture != null ? texture : game.Textures.Get(textureName),
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Colour = Color4.DarkGray Colour = Color4.DarkGray