From bc959f74a56fc54cdf7ece90664e860181a120ed Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 19 Oct 2016 16:04:02 -0400 Subject: [PATCH] Add background textures to beatmap sets Needs osu-framework#189 --- osu.Game/Beatmaps/IO/BeatmapResourceStore.cs | 49 ++++++++++++++++++++ osu.Game/GameModes/Play/BeatmapGroup.cs | 40 +++++++++++++--- osu.Game/GameModes/Play/PlaySongSelect.cs | 19 +++++--- osu.Game/osu.Game.csproj | 1 + 4 files changed, 96 insertions(+), 13 deletions(-) create mode 100644 osu.Game/Beatmaps/IO/BeatmapResourceStore.cs diff --git a/osu.Game/Beatmaps/IO/BeatmapResourceStore.cs b/osu.Game/Beatmaps/IO/BeatmapResourceStore.cs new file mode 100644 index 0000000000..005f751aea --- /dev/null +++ b/osu.Game/Beatmaps/IO/BeatmapResourceStore.cs @@ -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, IDisposable + { + private Dictionary beatmaps = new Dictionary(); + 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); + } + } +} \ No newline at end of file diff --git a/osu.Game/GameModes/Play/BeatmapGroup.cs b/osu.Game/GameModes/Play/BeatmapGroup.cs index 955fa656ac..df0332e0a1 100644 --- a/osu.Game/GameModes/Play/BeatmapGroup.cs +++ b/osu.Game/GameModes/Play/BeatmapGroup.cs @@ -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 { diff --git a/osu.Game/GameModes/Play/PlaySongSelect.cs b/osu.Game/GameModes/Play/PlaySongSelect.cs index 8b8dbcab77..eda6a75b71 100644 --- a/osu.Game/GameModes/Play/PlaySongSelect.cs +++ b/osu.Game/GameModes/Play/PlaySongSelect.cs @@ -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; 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(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), }, } }, @@ -118,8 +121,10 @@ namespace osu.Game.GameModes.Play // Temporary: scrollContainer.Padding = new MarginPadding { Top = osu.Toolbar.Height }; } - + 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; diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 10e384ec01..0ee86c5237 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -190,6 +190,7 @@ +