mirror of https://github.com/ppy/osu
Add beatmap backgrounds.
This commit is contained in:
parent
060081fecc
commit
a11d534067
|
@ -29,7 +29,7 @@ public LegacyFilesystemReader(string path)
|
|||
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 @@ public override string[] ReadBeatmaps()
|
|||
return beatmaps;
|
||||
}
|
||||
|
||||
public override Stream ReadFile(string name)
|
||||
public override Stream GetStream(string name)
|
||||
{
|
||||
return File.OpenRead(Path.Combine(basePath, name));
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public void TestReadFile()
|
|||
{
|
||||
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());
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public BeatmapGroupState State
|
|||
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 @@ public BeatmapGroupState State
|
|||
}
|
||||
}
|
||||
|
||||
public BeatmapGroup(BeatmapSetInfo beatmapSet)
|
||||
public BeatmapGroup(BeatmapSetInfo beatmapSet, WorkingBeatmap working)
|
||||
{
|
||||
this.beatmapSet = beatmapSet;
|
||||
|
||||
|
@ -78,7 +78,7 @@ public BeatmapGroup(BeatmapSetInfo beatmapSet)
|
|||
Direction = FlowDirection.VerticalOnly,
|
||||
Children = new Framework.Graphics.Drawable[]
|
||||
{
|
||||
header = new BeatmapSetHeader(beatmapSet)
|
||||
header = new BeatmapSetHeader(beatmapSet, working)
|
||||
{
|
||||
GainedSelection = headerGainedSelection,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
|
|
|
@ -31,27 +31,18 @@ protected override void Deselected()
|
|||
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,
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
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 @@ protected virtual void Deselected()
|
|||
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)
|
||||
|
|
|
@ -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 @@ protected static void AddReader<T>(Func<BasicStorage, string, bool> test) where
|
|||
/// <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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ public OszArchiveReader(Stream archiveStream)
|
|||
.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 @@ public override string[] ReadBeatmaps()
|
|||
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)
|
||||
|
|
|
@ -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 @@ public class WorkingBeatmap : IDisposable
|
|||
|
||||
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 @@ public Beatmap Beatmap
|
|||
|
||||
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 @@ public AudioTrack Track
|
|||
|
||||
try
|
||||
{
|
||||
var trackData = reader.ReadFile(BeatmapInfo.Metadata.AudioFile);
|
||||
var trackData = reader.GetStream(BeatmapInfo.Metadata.AudioFile);
|
||||
if (trackData != null)
|
||||
track = new AudioTrackBass(trackData);
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ public void Import(params string[] paths)
|
|||
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);
|
||||
|
|
|
@ -240,7 +240,10 @@ private void addBeatmapSet(BeatmapSetInfo beatmapSet)
|
|||
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 =>
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue