mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 09:07:25 +08:00
Add background textures to beatmap sets
Needs osu-framework#189
This commit is contained in:
parent
6da092ab30
commit
bc959f74a5
49
osu.Game/Beatmaps/IO/BeatmapResourceStore.cs
Normal file
49
osu.Game/Beatmaps/IO/BeatmapResourceStore.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using osu.Framework.IO.Stores;
|
||||
using osu.Game.Database;
|
||||
|
||||
namespace osu.Game.Beatmaps.IO
|
||||
{
|
||||
public class BeatmapResourceStore : IResourceStore<byte[]>, IDisposable
|
||||
{
|
||||
private Dictionary<int, ArchiveReader> beatmaps = new Dictionary<int, ArchiveReader>();
|
||||
private BeatmapDatabase database;
|
||||
|
||||
public BeatmapResourceStore(BeatmapDatabase database)
|
||||
{
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
public void AddBeatmap(BeatmapSetInfo setInfo)
|
||||
{
|
||||
beatmaps.Add(setInfo.BeatmapSetID, database.GetReader(setInfo));
|
||||
}
|
||||
|
||||
public void RemoveBeatmap(BeatmapSetInfo setInfo)
|
||||
{
|
||||
beatmaps[setInfo.BeatmapSetID].Dispose();
|
||||
beatmaps.Remove(setInfo.BeatmapSetID);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var b in beatmaps.Values)
|
||||
b.Dispose();
|
||||
}
|
||||
|
||||
public byte[] Get(string name)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Stream GetStream(string name)
|
||||
{
|
||||
string id = name.Remove(name.IndexOf(':'));
|
||||
string path = name.Substring(name.IndexOf(':') + 1);
|
||||
var reader = beatmaps[int.Parse(id)];
|
||||
return reader.ReadFile(path);
|
||||
}
|
||||
}
|
||||
}
|
@ -14,6 +14,8 @@ using System.Linq;
|
||||
using osu.Framework.Graphics.Transformations;
|
||||
using osu.Framework.Input;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Game.Beatmaps.IO;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
|
||||
namespace osu.Game.GameModes.Play
|
||||
{
|
||||
@ -57,7 +59,7 @@ namespace osu.Game.GameModes.Play
|
||||
}
|
||||
}
|
||||
|
||||
public BeatmapGroup(BeatmapSetInfo beatmapSet)
|
||||
public BeatmapGroup(BeatmapSetInfo beatmapSet, BeatmapResourceStore beatmapStore, TextureStore resources)
|
||||
{
|
||||
BeatmapSet = beatmapSet;
|
||||
Alpha = collapsedAlpha;
|
||||
@ -70,7 +72,7 @@ namespace osu.Game.GameModes.Play
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Size = new Vector2(1, 0),
|
||||
Direction = FlowDirection.VerticalOnly,
|
||||
Children = new[] { setBox = new BeatmapSetBox(beatmapSet) }
|
||||
Children = new[] { setBox = new BeatmapSetBox(beatmapSet, beatmapStore, resources) }
|
||||
}
|
||||
};
|
||||
difficulties = new FlowContainer // Deliberately not added to children
|
||||
@ -97,11 +99,11 @@ namespace osu.Game.GameModes.Play
|
||||
{
|
||||
private BeatmapSetInfo beatmapSet;
|
||||
|
||||
public BeatmapSetBox(BeatmapSetInfo beatmapSet)
|
||||
public BeatmapSetBox(BeatmapSetInfo beatmapSet, BeatmapResourceStore beatmapStore, TextureStore resources)
|
||||
{
|
||||
this.beatmapSet = beatmapSet;
|
||||
RelativeSizeAxes = Axes.X;
|
||||
Size = new Vector2(1, 0);
|
||||
Size = new Vector2(1, -1);
|
||||
Masking = true;
|
||||
CornerRadius = 5;
|
||||
BorderThickness = 2;
|
||||
@ -110,9 +112,35 @@ namespace osu.Game.GameModes.Play
|
||||
{
|
||||
new Box
|
||||
{
|
||||
Colour = new Color4(85, 85, 85, 255), // TODO: Gradient, and beatmap texture
|
||||
Colour = new Color4(85, 85, 85, 255),
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Size = new Vector2(1),
|
||||
Size = Vector2.One,
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Size = Vector2.One,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new DeferredSprite
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Size = new Vector2(1, 0),
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
ResolveTexture = () =>
|
||||
{
|
||||
beatmapStore.AddBeatmap(beatmapSet);
|
||||
return resources.Get($@"{beatmapSet.BeatmapSetID}:{beatmapSet.Metadata.BackgroundFile}");
|
||||
},
|
||||
},
|
||||
new Box // TODO: Gradient
|
||||
{
|
||||
Colour = new Color4(0, 0, 0, 100),
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Size = Vector2.One,
|
||||
}
|
||||
}
|
||||
},
|
||||
new FlowContainer
|
||||
{
|
||||
|
@ -8,6 +8,7 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.IO;
|
||||
using osu.Game.GameModes.Backgrounds;
|
||||
using osu.Framework;
|
||||
using osu.Game.Database;
|
||||
@ -15,6 +16,7 @@ using osu.Framework.Graphics.Primitives;
|
||||
using System.Linq;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
|
||||
namespace osu.Game.GameModes.Play
|
||||
{
|
||||
@ -23,6 +25,8 @@ namespace osu.Game.GameModes.Play
|
||||
private Bindable<PlayMode> playMode;
|
||||
private BeatmapDatabase beatmaps;
|
||||
private BeatmapSetInfo selectedBeatmapSet;
|
||||
private BeatmapResourceStore beatmapResources;
|
||||
private TextureStore beatmapTextureResources;
|
||||
|
||||
// TODO: use currently selected track as bg
|
||||
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
|
||||
@ -43,7 +47,7 @@ namespace osu.Game.GameModes.Play
|
||||
private void addBeatmapSet(BeatmapSetInfo beatmapSet)
|
||||
{
|
||||
beatmapSet = beatmaps.GetWithChildren<BeatmapSetInfo>(beatmapSet.BeatmapSetID);
|
||||
var group = new BeatmapGroup(beatmapSet);
|
||||
var group = new BeatmapGroup(beatmapSet, beatmapResources, beatmapTextureResources);
|
||||
group.SetSelected += (selectedSet) => selectBeatmapSet(selectedSet);
|
||||
setList.Add(group);
|
||||
}
|
||||
@ -76,12 +80,11 @@ namespace osu.Game.GameModes.Play
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
RelativePositionAxes = Axes.Both,
|
||||
Size = new Vector2(1, 0.5f),
|
||||
Position = new Vector2(0, 0.5f),
|
||||
RelativePositionAxes = Axes.Y,
|
||||
Size = new Vector2(1, -0.5f),
|
||||
Position = new Vector2(0, 1),
|
||||
Colour = new Color4(0, 0, 0, 0.5f),
|
||||
// TODO: Figure out the inverse shear problem
|
||||
//Shear = new Vector2(-0.15f, 0),
|
||||
Shear = new Vector2(-0.15f, 0),
|
||||
},
|
||||
}
|
||||
},
|
||||
@ -120,6 +123,8 @@ namespace osu.Game.GameModes.Play
|
||||
}
|
||||
|
||||
beatmaps = (game as OsuGameBase).Beatmaps;
|
||||
beatmapTextureResources = new TextureStore(
|
||||
new RawTextureLoaderStore(beatmapResources = new BeatmapResourceStore(beatmaps)));
|
||||
beatmaps.BeatmapSetAdded += bset => Scheduler.Add(() => addBeatmapSet(bset));
|
||||
addBeatmapSets();
|
||||
var first = setList.Children.FirstOrDefault() as BeatmapGroup;
|
||||
|
@ -190,6 +190,7 @@
|
||||
<Compile Include="Database\BeatmapMetadata.cs" />
|
||||
<Compile Include="Database\BeatmapInfo.cs" />
|
||||
<Compile Include="Database\BaseDifficulty.cs" />
|
||||
<Compile Include="Beatmaps\IO\BeatmapResourceStore.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj">
|
||||
|
Loading…
Reference in New Issue
Block a user