1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-12 05:52:54 +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
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)

View File

@ -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;
/// <param name="database">Optionally provide a database to use instead of the OsuGame one.</param>
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<BeatmapSetInfo>().Count() > 0)
foreach (var beatmapSet in database.Query<BeatmapSetInfo>())
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;
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);

View File

@ -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