mirror of
https://github.com/osukey/osukey.git
synced 2025-06-23 12:18:03 +09: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.Graphics.Transformations;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
|
using osu.Game.Beatmaps.IO;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
|
|
||||||
namespace osu.Game.GameModes.Play
|
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;
|
BeatmapSet = beatmapSet;
|
||||||
Alpha = collapsedAlpha;
|
Alpha = collapsedAlpha;
|
||||||
@ -70,7 +72,7 @@ namespace osu.Game.GameModes.Play
|
|||||||
RelativeSizeAxes = Axes.X,
|
RelativeSizeAxes = Axes.X,
|
||||||
Size = new Vector2(1, 0),
|
Size = new Vector2(1, 0),
|
||||||
Direction = FlowDirection.VerticalOnly,
|
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
|
difficulties = new FlowContainer // Deliberately not added to children
|
||||||
@ -97,11 +99,11 @@ namespace osu.Game.GameModes.Play
|
|||||||
{
|
{
|
||||||
private BeatmapSetInfo beatmapSet;
|
private BeatmapSetInfo beatmapSet;
|
||||||
|
|
||||||
public BeatmapSetBox(BeatmapSetInfo beatmapSet)
|
public BeatmapSetBox(BeatmapSetInfo beatmapSet, BeatmapResourceStore beatmapStore, TextureStore resources)
|
||||||
{
|
{
|
||||||
this.beatmapSet = beatmapSet;
|
this.beatmapSet = beatmapSet;
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
Size = new Vector2(1, 0);
|
Size = new Vector2(1, -1);
|
||||||
Masking = true;
|
Masking = true;
|
||||||
CornerRadius = 5;
|
CornerRadius = 5;
|
||||||
BorderThickness = 2;
|
BorderThickness = 2;
|
||||||
@ -110,9 +112,35 @@ namespace osu.Game.GameModes.Play
|
|||||||
{
|
{
|
||||||
new Box
|
new Box
|
||||||
{
|
{
|
||||||
Colour = new Color4(85, 85, 85, 255), // TODO: Gradient, and beatmap texture
|
Colour = new Color4(85, 85, 85, 255),
|
||||||
RelativeSizeAxes = Axes.Both,
|
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
|
new FlowContainer
|
||||||
{
|
{
|
||||||
|
@ -8,6 +8,7 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Beatmaps.IO;
|
||||||
using osu.Game.GameModes.Backgrounds;
|
using osu.Game.GameModes.Backgrounds;
|
||||||
using osu.Framework;
|
using osu.Framework;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
@ -15,6 +16,7 @@ using osu.Framework.Graphics.Primitives;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
|
|
||||||
namespace osu.Game.GameModes.Play
|
namespace osu.Game.GameModes.Play
|
||||||
{
|
{
|
||||||
@ -23,6 +25,8 @@ namespace osu.Game.GameModes.Play
|
|||||||
private Bindable<PlayMode> playMode;
|
private Bindable<PlayMode> playMode;
|
||||||
private BeatmapDatabase beatmaps;
|
private BeatmapDatabase beatmaps;
|
||||||
private BeatmapSetInfo selectedBeatmapSet;
|
private BeatmapSetInfo selectedBeatmapSet;
|
||||||
|
private BeatmapResourceStore beatmapResources;
|
||||||
|
private TextureStore beatmapTextureResources;
|
||||||
|
|
||||||
// TODO: use currently selected track as bg
|
// TODO: use currently selected track as bg
|
||||||
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
|
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
|
||||||
@ -43,7 +47,7 @@ namespace osu.Game.GameModes.Play
|
|||||||
private void addBeatmapSet(BeatmapSetInfo beatmapSet)
|
private void addBeatmapSet(BeatmapSetInfo beatmapSet)
|
||||||
{
|
{
|
||||||
beatmapSet = beatmaps.GetWithChildren<BeatmapSetInfo>(beatmapSet.BeatmapSetID);
|
beatmapSet = beatmaps.GetWithChildren<BeatmapSetInfo>(beatmapSet.BeatmapSetID);
|
||||||
var group = new BeatmapGroup(beatmapSet);
|
var group = new BeatmapGroup(beatmapSet, beatmapResources, beatmapTextureResources);
|
||||||
group.SetSelected += (selectedSet) => selectBeatmapSet(selectedSet);
|
group.SetSelected += (selectedSet) => selectBeatmapSet(selectedSet);
|
||||||
setList.Add(group);
|
setList.Add(group);
|
||||||
}
|
}
|
||||||
@ -76,12 +80,11 @@ namespace osu.Game.GameModes.Play
|
|||||||
new Box
|
new Box
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
RelativePositionAxes = Axes.Both,
|
RelativePositionAxes = Axes.Y,
|
||||||
Size = new Vector2(1, 0.5f),
|
Size = new Vector2(1, -0.5f),
|
||||||
Position = new Vector2(0, 0.5f),
|
Position = new Vector2(0, 1),
|
||||||
Colour = new Color4(0, 0, 0, 0.5f),
|
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),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -118,8 +121,10 @@ namespace osu.Game.GameModes.Play
|
|||||||
// Temporary:
|
// Temporary:
|
||||||
scrollContainer.Padding = new MarginPadding { Top = osu.Toolbar.Height };
|
scrollContainer.Padding = new MarginPadding { Top = osu.Toolbar.Height };
|
||||||
}
|
}
|
||||||
|
|
||||||
beatmaps = (game as OsuGameBase).Beatmaps;
|
beatmaps = (game as OsuGameBase).Beatmaps;
|
||||||
|
beatmapTextureResources = new TextureStore(
|
||||||
|
new RawTextureLoaderStore(beatmapResources = new BeatmapResourceStore(beatmaps)));
|
||||||
beatmaps.BeatmapSetAdded += bset => Scheduler.Add(() => addBeatmapSet(bset));
|
beatmaps.BeatmapSetAdded += bset => Scheduler.Add(() => addBeatmapSet(bset));
|
||||||
addBeatmapSets();
|
addBeatmapSets();
|
||||||
var first = setList.Children.FirstOrDefault() as BeatmapGroup;
|
var first = setList.Children.FirstOrDefault() as BeatmapGroup;
|
||||||
|
@ -190,6 +190,7 @@
|
|||||||
<Compile Include="Database\BeatmapMetadata.cs" />
|
<Compile Include="Database\BeatmapMetadata.cs" />
|
||||||
<Compile Include="Database\BeatmapInfo.cs" />
|
<Compile Include="Database\BeatmapInfo.cs" />
|
||||||
<Compile Include="Database\BaseDifficulty.cs" />
|
<Compile Include="Database\BaseDifficulty.cs" />
|
||||||
|
<Compile Include="Beatmaps\IO\BeatmapResourceStore.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj">
|
<ProjectReference Include="$(SolutionDir)\osu-framework\osu.Framework\osu.Framework.csproj">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user