mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 20:53:04 +08:00
Add beatmap backgrounds.
This commit is contained in:
parent
060081fecc
commit
a11d534067
@ -29,7 +29,7 @@ namespace osu.Desktop.Beatmaps.IO
|
|||||||
beatmaps = Directory.GetFiles(basePath, @"*.osu").Select(f => Path.GetFileName(f)).ToArray();
|
beatmaps = Directory.GetFiles(basePath, @"*.osu").Select(f => Path.GetFileName(f)).ToArray();
|
||||||
if (beatmaps.Length == 0)
|
if (beatmaps.Length == 0)
|
||||||
throw new FileNotFoundException(@"This directory contains no beatmaps");
|
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);
|
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||||
firstMap = decoder.Decode(stream);
|
firstMap = decoder.Decode(stream);
|
||||||
@ -41,7 +41,7 @@ namespace osu.Desktop.Beatmaps.IO
|
|||||||
return beatmaps;
|
return beatmaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Stream ReadFile(string name)
|
public override Stream GetStream(string name)
|
||||||
{
|
{
|
||||||
return File.OpenRead(Path.Combine(basePath, name));
|
return File.OpenRead(Path.Combine(basePath, name));
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ namespace osu.Game.Tests.Beatmaps.IO
|
|||||||
{
|
{
|
||||||
var reader = new OszArchiveReader(osz);
|
var reader = new OszArchiveReader(osz);
|
||||||
using (var stream = new StreamReader(
|
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());
|
Assert.AreEqual("osu file format v13", stream.ReadLine().Trim());
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ namespace osu.Game.Beatmaps.Drawable
|
|||||||
header.State = PanelSelectedState.Selected;
|
header.State = PanelSelectedState.Selected;
|
||||||
break;
|
break;
|
||||||
case BeatmapGroupState.Collapsed:
|
case BeatmapGroupState.Collapsed:
|
||||||
FadeTo(0.5f, 250);
|
FadeTo(0.8f, 250);
|
||||||
|
|
||||||
header.State = PanelSelectedState.NotSelected;
|
header.State = PanelSelectedState.NotSelected;
|
||||||
difficulties.Hide();
|
difficulties.Hide();
|
||||||
@ -61,7 +61,7 @@ namespace osu.Game.Beatmaps.Drawable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public BeatmapGroup(BeatmapSetInfo beatmapSet)
|
public BeatmapGroup(BeatmapSetInfo beatmapSet, WorkingBeatmap working)
|
||||||
{
|
{
|
||||||
this.beatmapSet = beatmapSet;
|
this.beatmapSet = beatmapSet;
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ namespace osu.Game.Beatmaps.Drawable
|
|||||||
Direction = FlowDirection.VerticalOnly,
|
Direction = FlowDirection.VerticalOnly,
|
||||||
Children = new Framework.Graphics.Drawable[]
|
Children = new Framework.Graphics.Drawable[]
|
||||||
{
|
{
|
||||||
header = new BeatmapSetHeader(beatmapSet)
|
header = new BeatmapSetHeader(beatmapSet, working)
|
||||||
{
|
{
|
||||||
GainedSelection = headerGainedSelection,
|
GainedSelection = headerGainedSelection,
|
||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
|
@ -31,27 +31,18 @@ namespace osu.Game.Beatmaps.Drawable
|
|||||||
Width = 0.8f;
|
Width = 0.8f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BeatmapSetHeader(BeatmapSetInfo beatmapSet)
|
public BeatmapSetHeader(BeatmapSetInfo beatmapSet, WorkingBeatmap working)
|
||||||
{
|
{
|
||||||
Children = new Framework.Graphics.Drawable[]
|
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),
|
Texture = working.Background,
|
||||||
RelativeSizeAxes = Axes.Both,
|
Anchor = Anchor.Centre,
|
||||||
},
|
Origin = Anchor.Centre,
|
||||||
new Container
|
Scale = new Vector2(0.5f),
|
||||||
{
|
Colour = new Color4(200, 200, 200, 255),
|
||||||
RelativeSizeAxes = Axes.Both,
|
},
|
||||||
Children = new Framework.Graphics.Drawable[]
|
|
||||||
{
|
|
||||||
new Box // TODO: Gradient
|
|
||||||
{
|
|
||||||
Colour = new Color4(0, 0, 0, 100),
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new FlowContainer
|
new FlowContainer
|
||||||
{
|
{
|
||||||
Direction = FlowDirection.VerticalOnly,
|
Direction = FlowDirection.VerticalOnly,
|
||||||
|
@ -10,6 +10,7 @@ using osu.Framework;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps.Drawable
|
namespace osu.Game.Beatmaps.Drawable
|
||||||
@ -69,7 +70,13 @@ namespace osu.Game.Beatmaps.Drawable
|
|||||||
BorderColour = new Color4(BorderColour.R, BorderColour.G, BorderColour.B, 0);
|
BorderColour = new Color4(BorderColour.R, BorderColour.G, BorderColour.B, 0);
|
||||||
BorderThickness = 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)
|
protected override bool OnClick(InputState state)
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using osu.Framework.IO.Stores;
|
||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps.IO
|
namespace osu.Game.Beatmaps.IO
|
||||||
{
|
{
|
||||||
public abstract class ArchiveReader : IDisposable
|
public abstract class ArchiveReader : IDisposable, IResourceStore<byte[]>
|
||||||
{
|
{
|
||||||
private class Reader
|
private class Reader
|
||||||
{
|
{
|
||||||
@ -42,8 +43,23 @@ namespace osu.Game.Beatmaps.IO
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Opens a stream for reading a specific file from this archive.
|
/// Opens a stream for reading a specific file from this archive.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract Stream ReadFile(string name);
|
public abstract Stream GetStream(string name);
|
||||||
|
|
||||||
public abstract void Dispose();
|
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 @@ namespace osu.Game.Beatmaps.IO
|
|||||||
.Select(e => e.FileName).ToArray();
|
.Select(e => e.FileName).ToArray();
|
||||||
if (beatmaps.Length == 0)
|
if (beatmaps.Length == 0)
|
||||||
throw new FileNotFoundException(@"This directory contains no beatmaps");
|
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);
|
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||||
firstMap = decoder.Decode(stream);
|
firstMap = decoder.Decode(stream);
|
||||||
@ -45,7 +45,7 @@ namespace osu.Game.Beatmaps.IO
|
|||||||
return beatmaps;
|
return beatmaps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Stream ReadFile(string name)
|
public override Stream GetStream(string name)
|
||||||
{
|
{
|
||||||
ZipEntry entry = archive.Entries.SingleOrDefault(e => e.FileName == name);
|
ZipEntry entry = archive.Entries.SingleOrDefault(e => e.FileName == name);
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using osu.Framework.Audio.Track;
|
using osu.Framework.Audio.Track;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Game.Beatmaps.Formats;
|
using osu.Game.Beatmaps.Formats;
|
||||||
using osu.Game.Beatmaps.IO;
|
using osu.Game.Beatmaps.IO;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
@ -19,6 +20,24 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
private ArchiveReader reader => database.GetReader(BeatmapSetInfo);
|
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;
|
private Beatmap beatmap;
|
||||||
public Beatmap Beatmap
|
public Beatmap Beatmap
|
||||||
{
|
{
|
||||||
@ -28,7 +47,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
try
|
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);
|
beatmap = BeatmapDecoder.GetDecoder(stream)?.Decode(stream);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
@ -47,7 +66,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var trackData = reader.ReadFile(BeatmapInfo.Metadata.AudioFile);
|
var trackData = reader.GetStream(BeatmapInfo.Metadata.AudioFile);
|
||||||
if (trackData != null)
|
if (trackData != null)
|
||||||
track = new AudioTrackBass(trackData);
|
track = new AudioTrackBass(trackData);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ namespace osu.Game.Database
|
|||||||
string[] mapNames = reader.ReadBeatmaps();
|
string[] mapNames = reader.ReadBeatmaps();
|
||||||
foreach (var name in mapNames)
|
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);
|
var decoder = BeatmapDecoder.GetDecoder(stream);
|
||||||
Beatmap beatmap = decoder.Decode(stream);
|
Beatmap beatmap = decoder.Decode(stream);
|
||||||
|
@ -240,7 +240,10 @@ namespace osu.Game.GameModes.Play
|
|||||||
beatmapSet = database.GetWithChildren<BeatmapSetInfo>(beatmapSet.BeatmapSetID);
|
beatmapSet = database.GetWithChildren<BeatmapSetInfo>(beatmapSet.BeatmapSetID);
|
||||||
beatmapSet.Beatmaps.ForEach(b => database.GetChildren(b));
|
beatmapSet.Beatmaps.ForEach(b => database.GetChildren(b));
|
||||||
beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.BaseDifficulty.OverallDifficulty).ToList();
|
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 =>
|
group.Preload(Game, g =>
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user