1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:20:04 +08:00

Add beatmap backgrounds.

This commit is contained in:
Dean Herbert 2016-11-05 20:00:14 +09:00
parent 060081fecc
commit a11d534067
10 changed files with 68 additions and 32 deletions

View File

@ -29,7 +29,7 @@ namespace osu.Desktop.Beatmaps.IO
beatmaps = Directory.GetFiles(basePath, @"*.osu").Select(f => Path.GetFileName(f)).ToArray();
if (beatmaps.Length == 0)
throw new FileNotFoundException(@"This directory contains no beatmaps");
using (var stream = new StreamReader(ReadFile(beatmaps[0])))
using (var stream = new StreamReader(GetStream(beatmaps[0])))
{
var decoder = BeatmapDecoder.GetDecoder(stream);
firstMap = decoder.Decode(stream);
@ -41,7 +41,7 @@ namespace osu.Desktop.Beatmaps.IO
return beatmaps;
}
public override Stream ReadFile(string name)
public override Stream GetStream(string name)
{
return File.OpenRead(Path.Combine(basePath, name));
}

View File

@ -70,7 +70,7 @@ namespace osu.Game.Tests.Beatmaps.IO
{
var reader = new OszArchiveReader(osz);
using (var stream = new StreamReader(
reader.ReadFile("Soleily - Renatus (Deif) [Platter].osu")))
reader.GetStream("Soleily - Renatus (Deif) [Platter].osu")))
{
Assert.AreEqual("osu file format v13", stream.ReadLine().Trim());
}

View File

@ -52,7 +52,7 @@ namespace osu.Game.Beatmaps.Drawable
header.State = PanelSelectedState.Selected;
break;
case BeatmapGroupState.Collapsed:
FadeTo(0.5f, 250);
FadeTo(0.8f, 250);
header.State = PanelSelectedState.NotSelected;
difficulties.Hide();
@ -61,7 +61,7 @@ namespace osu.Game.Beatmaps.Drawable
}
}
public BeatmapGroup(BeatmapSetInfo beatmapSet)
public BeatmapGroup(BeatmapSetInfo beatmapSet, WorkingBeatmap working)
{
this.beatmapSet = beatmapSet;
@ -78,7 +78,7 @@ namespace osu.Game.Beatmaps.Drawable
Direction = FlowDirection.VerticalOnly,
Children = new Framework.Graphics.Drawable[]
{
header = new BeatmapSetHeader(beatmapSet)
header = new BeatmapSetHeader(beatmapSet, working)
{
GainedSelection = headerGainedSelection,
RelativeSizeAxes = Axes.X,

View File

@ -31,27 +31,18 @@ namespace osu.Game.Beatmaps.Drawable
Width = 0.8f;
}
public BeatmapSetHeader(BeatmapSetInfo beatmapSet)
public BeatmapSetHeader(BeatmapSetInfo beatmapSet, WorkingBeatmap working)
{
Children = new Framework.Graphics.Drawable[]
{
new Box
working.Background == null ? new Box{ RelativeSizeAxes = Axes.Both, Colour = new Color4(20, 20, 20, 255) } : new Sprite
{
Colour = new Color4(85, 85, 85, 255),
RelativeSizeAxes = Axes.Both,
},
new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Framework.Graphics.Drawable[]
{
new Box // TODO: Gradient
{
Colour = new Color4(0, 0, 0, 100),
RelativeSizeAxes = Axes.Both,
}
}
},
Texture = working.Background,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(0.5f),
Colour = new Color4(200, 200, 200, 255),
},
new FlowContainer
{
Direction = FlowDirection.VerticalOnly,

View File

@ -10,6 +10,7 @@ using osu.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Beatmaps.Drawable
@ -69,7 +70,13 @@ namespace osu.Game.Beatmaps.Drawable
BorderColour = new Color4(BorderColour.R, BorderColour.G, BorderColour.B, 0);
BorderThickness = 0;
EdgeEffect = new EdgeEffect { Type = EdgeEffectType.None };
EdgeEffect = new EdgeEffect
{
Type = EdgeEffectType.Shadow,
Offset = new Vector2(1),
Radius = 10,
Colour = new Color4(0, 0, 0, 100),
};
}
protected override bool OnClick(InputState state)

View File

@ -1,12 +1,13 @@
using System;
using System.Collections.Generic;
using System.IO;
using osu.Framework.IO.Stores;
using osu.Framework.Platform;
using osu.Game.Database;
namespace osu.Game.Beatmaps.IO
{
public abstract class ArchiveReader : IDisposable
public abstract class ArchiveReader : IDisposable, IResourceStore<byte[]>
{
private class Reader
{
@ -42,8 +43,23 @@ namespace osu.Game.Beatmaps.IO
/// <summary>
/// Opens a stream for reading a specific file from this archive.
/// </summary>
public abstract Stream ReadFile(string name);
public abstract Stream GetStream(string name);
public abstract void Dispose();
public virtual byte[] Get(string name)
{
using (Stream input = GetStream(name))
{
if (input == null)
return null;
using (MemoryStream ms = new MemoryStream())
{
input.CopyTo(ms);
return ms.ToArray();
}
}
}
}
}

View File

@ -33,7 +33,7 @@ namespace osu.Game.Beatmaps.IO
.Select(e => e.FileName).ToArray();
if (beatmaps.Length == 0)
throw new FileNotFoundException(@"This directory contains no beatmaps");
using (var stream = new StreamReader(ReadFile(beatmaps[0])))
using (var stream = new StreamReader(GetStream(beatmaps[0])))
{
var decoder = BeatmapDecoder.GetDecoder(stream);
firstMap = decoder.Decode(stream);
@ -45,7 +45,7 @@ namespace osu.Game.Beatmaps.IO
return beatmaps;
}
public override Stream ReadFile(string name)
public override Stream GetStream(string name)
{
ZipEntry entry = archive.Entries.SingleOrDefault(e => e.FileName == name);
if (entry == null)

View File

@ -4,6 +4,7 @@
using System;
using System.IO;
using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Textures;
using osu.Game.Beatmaps.Formats;
using osu.Game.Beatmaps.IO;
using osu.Game.Database;
@ -19,6 +20,24 @@ namespace osu.Game.Beatmaps
private ArchiveReader reader => database.GetReader(BeatmapSetInfo);
private Texture background;
public Texture Background
{
get
{
if (background != null) return background;
try
{
background = new TextureStore(new RawTextureLoaderStore(reader)).Get(BeatmapInfo.Metadata.BackgroundFile);
}
catch { }
return background;
}
set { background = value; }
}
private Beatmap beatmap;
public Beatmap Beatmap
{
@ -28,7 +47,7 @@ namespace osu.Game.Beatmaps
try
{
using (var stream = new StreamReader(reader.ReadFile(BeatmapInfo.Path)))
using (var stream = new StreamReader(reader.GetStream(BeatmapInfo.Path)))
beatmap = BeatmapDecoder.GetDecoder(stream)?.Decode(stream);
}
catch { }
@ -47,7 +66,7 @@ namespace osu.Game.Beatmaps
try
{
var trackData = reader.ReadFile(BeatmapInfo.Metadata.AudioFile);
var trackData = reader.GetStream(BeatmapInfo.Metadata.AudioFile);
if (trackData != null)
track = new AudioTrackBass(trackData);
}

View File

@ -95,7 +95,7 @@ namespace osu.Game.Database
string[] mapNames = reader.ReadBeatmaps();
foreach (var name in mapNames)
{
using (var stream = new StreamReader(reader.ReadFile(name)))
using (var stream = new StreamReader(reader.GetStream(name)))
{
var decoder = BeatmapDecoder.GetDecoder(stream);
Beatmap beatmap = decoder.Decode(stream);

View File

@ -240,7 +240,10 @@ namespace osu.Game.GameModes.Play
beatmapSet = database.GetWithChildren<BeatmapSetInfo>(beatmapSet.BeatmapSetID);
beatmapSet.Beatmaps.ForEach(b => database.GetChildren(b));
beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.BaseDifficulty.OverallDifficulty).ToList();
var group = new BeatmapGroup(beatmapSet) { SelectionChanged = selectionChanged };
var working = database.GetWorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault());
var group = new BeatmapGroup(beatmapSet, working) { SelectionChanged = selectionChanged };
group.Preload(Game, g =>
{