mirror of
https://github.com/ppy/osu
synced 2025-01-18 12:00:58 +00:00
Merge pull request #111 from peppy/general-fixes
Local BeatmapDatabases and much more
This commit is contained in:
commit
62d4af9798
@ -1 +1 @@
|
||||
Subproject commit ded26d83913e11b0c5d91977f94cac8a9457643f
|
||||
Subproject commit 13af08782cfb4de054b2fb11a2cf8311ff895949
|
@ -17,7 +17,6 @@ namespace osu.Desktop.Platform
|
||||
|
||||
public override SQLiteConnection GetDatabase(string name)
|
||||
{
|
||||
Directory.CreateDirectory(BasePath);
|
||||
ISQLitePlatform platform;
|
||||
if (RuntimeInfo.IsWindows)
|
||||
platform = new SQLitePlatformWin32();
|
||||
|
@ -1,31 +1,96 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK;
|
||||
using osu.Framework.GameModes.Testing;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Online.Chat.Display;
|
||||
using osu.Framework;
|
||||
using osu.Desktop.Platform;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.GameModes.Play;
|
||||
using SQLiteNetExtensions.Extensions;
|
||||
using osu.Framework;
|
||||
using osu.Game;
|
||||
|
||||
namespace osu.Desktop.Tests
|
||||
{
|
||||
class TestCasePlaySongSelect : TestCase
|
||||
{
|
||||
private BeatmapDatabase db;
|
||||
private TestStorage storage;
|
||||
|
||||
public override string Name => @"Song Select";
|
||||
public override string Description => @"Testing song selection UI";
|
||||
|
||||
public override string Description => @"with fake data";
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
base.Reset();
|
||||
Add(new PlaySongSelect());
|
||||
base.Reset();
|
||||
|
||||
if (db == null)
|
||||
{
|
||||
storage = new TestStorage(@"TestCasePlaySongSelect");
|
||||
db = new BeatmapDatabase(storage);
|
||||
|
||||
var sets = new List<BeatmapSetInfo>();
|
||||
|
||||
for (int i = 0; i < 100; i += 10)
|
||||
sets.Add(createTestBeatmapSet(i));
|
||||
|
||||
db.Import(sets);
|
||||
}
|
||||
|
||||
Add(new PlaySongSelect(db));
|
||||
}
|
||||
|
||||
private BeatmapSetInfo createTestBeatmapSet(int i)
|
||||
{
|
||||
return new BeatmapSetInfo
|
||||
{
|
||||
BeatmapSetID = 1234 + i,
|
||||
Hash = "d8e8fca2dc0f896fd7cb4cb0031ba249",
|
||||
Path = string.Empty,
|
||||
Metadata = new BeatmapMetadata
|
||||
{
|
||||
BeatmapSetID = 1234 + i,
|
||||
Artist = "MONACA",
|
||||
Title = "Black Song",
|
||||
Author = "Some Guy",
|
||||
},
|
||||
Beatmaps = new List<BeatmapInfo>(new[]
|
||||
{
|
||||
new BeatmapInfo
|
||||
{
|
||||
BeatmapID = 1234 + i,
|
||||
Mode = PlayMode.Osu,
|
||||
Path = "normal.osu",
|
||||
Version = "Normal",
|
||||
BaseDifficulty = new BaseDifficulty
|
||||
{
|
||||
OverallDifficulty = 3.5f,
|
||||
}
|
||||
},
|
||||
new BeatmapInfo
|
||||
{
|
||||
BeatmapID = 1235 + i,
|
||||
Mode = PlayMode.Osu,
|
||||
Path = "hard.osu",
|
||||
Version = "Hard",
|
||||
BaseDifficulty = new BaseDifficulty
|
||||
{
|
||||
OverallDifficulty = 5,
|
||||
}
|
||||
},
|
||||
new BeatmapInfo
|
||||
{
|
||||
BeatmapID = 1236 + i,
|
||||
Mode = PlayMode.Osu,
|
||||
Path = "insane.osu",
|
||||
Version = "Insane",
|
||||
BaseDifficulty = new BaseDifficulty
|
||||
{
|
||||
OverallDifficulty = 7,
|
||||
}
|
||||
},
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,66 +18,9 @@ namespace osu.Desktop.VisualTests
|
||||
{
|
||||
class VisualTestGame : OsuGameBase
|
||||
{
|
||||
private void InsertTestMap(int i)
|
||||
{
|
||||
var beatmapSet = new BeatmapSetInfo
|
||||
{
|
||||
BeatmapSetID = 1234 + i,
|
||||
Hash = "d8e8fca2dc0f896fd7cb4cb0031ba249",
|
||||
Path = "/foo/bar/baz",
|
||||
Metadata = new BeatmapMetadata
|
||||
{
|
||||
BeatmapSetID = 1234 + i,
|
||||
Artist = "MONACA",
|
||||
Title = "Black Song",
|
||||
Author = "Some Guy",
|
||||
},
|
||||
Beatmaps = new List<BeatmapInfo>(new[]
|
||||
{
|
||||
new BeatmapInfo
|
||||
{
|
||||
BeatmapID = 1234 + i,
|
||||
Mode = PlayMode.Osu,
|
||||
Path = "normal.osu",
|
||||
Version = "Normal",
|
||||
BaseDifficulty = new BaseDifficulty
|
||||
{
|
||||
OverallDifficulty = 3.5f,
|
||||
}
|
||||
},
|
||||
new BeatmapInfo
|
||||
{
|
||||
BeatmapID = 1235 + i,
|
||||
Mode = PlayMode.Osu,
|
||||
Path = "hard.osu",
|
||||
Version = "Hard",
|
||||
BaseDifficulty = new BaseDifficulty
|
||||
{
|
||||
OverallDifficulty = 5,
|
||||
}
|
||||
},
|
||||
new BeatmapInfo
|
||||
{
|
||||
BeatmapID = 1236 + i,
|
||||
Mode = PlayMode.Osu,
|
||||
Path = "insane.osu",
|
||||
Version = "Insane",
|
||||
BaseDifficulty = new BaseDifficulty
|
||||
{
|
||||
OverallDifficulty = 7,
|
||||
}
|
||||
},
|
||||
}),
|
||||
};
|
||||
BeatmapDatabase.Connection.InsertWithChildren(beatmapSet, true);
|
||||
}
|
||||
|
||||
public override void Load(BaseGame game)
|
||||
{
|
||||
Host.Storage = new TestStorage(@"visual-tests");
|
||||
base.Load(game);
|
||||
for (int i = 0; i < 100; i += 10)
|
||||
InsertTestMap(i);
|
||||
Add(new TestBrowser());
|
||||
}
|
||||
}
|
||||
|
@ -7,19 +7,14 @@ using osu.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Database;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Beatmaps.Drawable
|
||||
{
|
||||
class BeatmapGroup : Container, IStateful<BeatmapGroupState>
|
||||
{
|
||||
private const float collapsedAlpha = 0.5f;
|
||||
private const float collapsedWidth = 0.8f;
|
||||
|
||||
private BeatmapPanel selectedPanel;
|
||||
public BeatmapPanel SelectedPanel;
|
||||
|
||||
/// <summary>
|
||||
/// Fires when one of our difficulties was selected. Will fire on first expand.
|
||||
@ -44,23 +39,16 @@ namespace osu.Game.Beatmaps.Drawable
|
||||
FadeTo(1, 250);
|
||||
difficulties.Show();
|
||||
|
||||
//todo: header should probably have a state, with this logic moved inside it.
|
||||
header.Width = 1;
|
||||
header.GlowRadius = 5;
|
||||
header.BorderColour = new Color4(header.BorderColour.R, header.BorderColour.G, header.BorderColour.B, 255);
|
||||
header.State = PanelSelectedState.Selected;
|
||||
|
||||
if (selectedPanel == null)
|
||||
(difficulties.Children.FirstOrDefault() as BeatmapPanel).Selected = true;
|
||||
SelectionChanged?.Invoke(this, selectedPanel?.Beatmap);
|
||||
if (SelectedPanel == null)
|
||||
((BeatmapPanel)difficulties.Children.FirstOrDefault()).State = PanelSelectedState.Selected;
|
||||
break;
|
||||
case BeatmapGroupState.Collapsed:
|
||||
FadeTo(collapsedAlpha, 250);
|
||||
difficulties.Hide();
|
||||
FadeTo(0.5f, 250);
|
||||
|
||||
//todo: header should probably have a state, with this logic moved inside it.
|
||||
header.Width = collapsedWidth;
|
||||
header.GlowRadius = 0;
|
||||
header.BorderColour = new Color4(header.BorderColour.R, header.BorderColour.G, header.BorderColour.B, 0);
|
||||
header.State = PanelSelectedState.NotSelected;
|
||||
difficulties.Hide();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -68,10 +56,12 @@ namespace osu.Game.Beatmaps.Drawable
|
||||
|
||||
public BeatmapGroup(BeatmapSetInfo beatmapSet)
|
||||
{
|
||||
this.beatmapSet = beatmapSet;
|
||||
this.beatmapSet = beatmapSet;
|
||||
|
||||
Alpha = 0;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
RelativeSizeAxes = Axes.X;
|
||||
RelativeSizeAxes = Axes.X;
|
||||
|
||||
Children = new[]
|
||||
{
|
||||
new FlowContainer
|
||||
@ -83,8 +73,8 @@ namespace osu.Game.Beatmaps.Drawable
|
||||
{
|
||||
header = new BeatmapSetHeader(beatmapSet)
|
||||
{
|
||||
GainedSelection = headerGainedSelection,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Width = collapsedWidth,
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
},
|
||||
@ -118,18 +108,21 @@ namespace osu.Game.Beatmaps.Drawable
|
||||
State = BeatmapGroupState.Collapsed;
|
||||
}
|
||||
|
||||
private void panelGainedSelection(BeatmapPanel panel)
|
||||
private void headerGainedSelection(BeatmapSetHeader panel)
|
||||
{
|
||||
if (selectedPanel != null) selectedPanel.Selected = false;
|
||||
selectedPanel = panel;
|
||||
|
||||
SelectionChanged?.Invoke(this, panel.Beatmap);
|
||||
State = BeatmapGroupState.Expanded;
|
||||
|
||||
SelectionChanged?.Invoke(this, SelectedPanel.Beatmap);
|
||||
}
|
||||
|
||||
protected override bool OnClick(InputState state)
|
||||
private void panelGainedSelection(BeatmapPanel panel)
|
||||
{
|
||||
State = BeatmapGroupState.Expanded;
|
||||
return true;
|
||||
|
||||
if (SelectedPanel != null) SelectedPanel.State = PanelSelectedState.NotSelected;
|
||||
SelectedPanel = panel;
|
||||
|
||||
SelectionChanged?.Invoke(this, panel.Beatmap);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
@ -15,42 +14,23 @@ using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Beatmaps.Drawable
|
||||
{
|
||||
class BeatmapPanel : Container
|
||||
class BeatmapPanel : Panel
|
||||
{
|
||||
public BeatmapInfo Beatmap;
|
||||
|
||||
public Action<BeatmapPanel> GainedSelection;
|
||||
|
||||
private bool selected;
|
||||
|
||||
public bool Selected
|
||||
{
|
||||
get { return selected; }
|
||||
set
|
||||
{
|
||||
if (selected == value)
|
||||
return;
|
||||
selected = value;
|
||||
BorderColour = new Color4(
|
||||
BorderColour.R,
|
||||
BorderColour.G,
|
||||
BorderColour.B,
|
||||
selected ? 255 : 0);
|
||||
GlowRadius = selected ? 3 : 0;
|
||||
|
||||
if (selected) GainedSelection?.Invoke(this);
|
||||
}
|
||||
public Action<BeatmapPanel> GainedSelection;
|
||||
|
||||
protected override void Selected()
|
||||
{
|
||||
base.Selected();
|
||||
GainedSelection?.Invoke(this);
|
||||
}
|
||||
|
||||
public BeatmapPanel(BeatmapSetInfo set, BeatmapInfo beatmap)
|
||||
{
|
||||
Beatmap = beatmap;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
Masking = true;
|
||||
CornerRadius = 5;
|
||||
BorderThickness = 2;
|
||||
BorderColour = new Color4(221, 255, 255, 0);
|
||||
GlowColour = new Color4(166, 221, 251, 0.75f); // TODO: Get actual color for this
|
||||
{
|
||||
Beatmap = beatmap;
|
||||
Height *= 0.75f;
|
||||
|
||||
Children = new Framework.Graphics.Drawable[]
|
||||
{
|
||||
new Box
|
||||
@ -87,8 +67,7 @@ namespace osu.Game.Beatmaps.Drawable
|
||||
},
|
||||
new SpriteText
|
||||
{
|
||||
Text = string.Format(" mapped by {0}",
|
||||
(beatmap.Metadata ?? set.Metadata).Author),
|
||||
Text = $" mapped by {(beatmap.Metadata ?? set.Metadata).Author}",
|
||||
TextSize = 16,
|
||||
},
|
||||
}
|
||||
@ -99,12 +78,6 @@ namespace osu.Game.Beatmaps.Drawable
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected override bool OnClick(InputState state)
|
||||
{
|
||||
Selected = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Primitives;
|
||||
@ -12,35 +13,42 @@ using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Beatmaps.Drawable
|
||||
{
|
||||
class BeatmapSetHeader : Container
|
||||
class BeatmapSetHeader : Panel
|
||||
{
|
||||
public Action<BeatmapSetHeader> GainedSelection;
|
||||
|
||||
protected override void Selected()
|
||||
{
|
||||
base.Selected();
|
||||
|
||||
Width = 1;
|
||||
GainedSelection?.Invoke(this);
|
||||
}
|
||||
|
||||
protected override void Deselected()
|
||||
{
|
||||
base.Deselected();
|
||||
Width = 0.8f;
|
||||
}
|
||||
|
||||
public BeatmapSetHeader(BeatmapSetInfo beatmapSet)
|
||||
{
|
||||
AutoSizeAxes = Axes.Y;
|
||||
Masking = true;
|
||||
CornerRadius = 5;
|
||||
BorderThickness = 2;
|
||||
BorderColour = new Color4(221, 255, 255, 0);
|
||||
GlowColour = new Color4(166, 221, 251, 0.5f); // TODO: Get actual color for this
|
||||
Children = new Framework.Graphics.Drawable[]
|
||||
{
|
||||
new Box
|
||||
{
|
||||
Colour = new Color4(85, 85, 85, 255),
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Size = Vector2.One,
|
||||
},
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Size = Vector2.One,
|
||||
Children = new Framework.Graphics.Drawable[]
|
||||
{
|
||||
new Box // TODO: Gradient
|
||||
{
|
||||
Colour = new Color4(0, 0, 0, 100),
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Size = Vector2.One,
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -48,7 +56,7 @@ namespace osu.Game.Beatmaps.Drawable
|
||||
{
|
||||
Direction = FlowDirection.VerticalOnly,
|
||||
Spacing = new Vector2(0, 2),
|
||||
Padding = new MarginPadding { Top = 3, Left = 20, Right = 20, Bottom = 3 },
|
||||
Padding = new MarginPadding { Top = 10, Left = 15, Right = 10, Bottom = 10 },
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Children = new[]
|
||||
{
|
||||
@ -75,6 +83,8 @@ namespace osu.Game.Beatmaps.Drawable
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Deselected();
|
||||
}
|
||||
}
|
||||
}
|
81
osu.Game/Beatmaps/Drawable/Panel.cs
Normal file
81
osu.Game/Beatmaps/Drawable/Panel.cs
Normal file
@ -0,0 +1,81 @@
|
||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Beatmaps.Drawable
|
||||
{
|
||||
class Panel : Container, IStateful<PanelSelectedState>
|
||||
{
|
||||
public Panel()
|
||||
{
|
||||
Height = 80;
|
||||
|
||||
Masking = true;
|
||||
CornerRadius = 10;
|
||||
BorderColour = new Color4(221, 255, 255, 0);
|
||||
GlowColour = new Color4(102, 204, 255, 100);
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
}
|
||||
|
||||
private PanelSelectedState state;
|
||||
|
||||
public PanelSelectedState State
|
||||
{
|
||||
get { return state; }
|
||||
|
||||
set
|
||||
{
|
||||
if (state == value) return;
|
||||
|
||||
state = value;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case PanelSelectedState.NotSelected:
|
||||
Deselected();
|
||||
break;
|
||||
case PanelSelectedState.Selected:
|
||||
Selected();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void Selected()
|
||||
{
|
||||
BorderColour = new Color4(BorderColour.R, BorderColour.G, BorderColour.B, 255);
|
||||
GlowRadius = 10;
|
||||
BorderThickness = 2.5f;
|
||||
}
|
||||
|
||||
protected virtual void Deselected()
|
||||
{
|
||||
BorderColour = new Color4(BorderColour.R, BorderColour.G, BorderColour.B, 0);
|
||||
GlowRadius = 0;
|
||||
BorderThickness = 0;
|
||||
}
|
||||
|
||||
protected override bool OnClick(InputState state)
|
||||
{
|
||||
State = PanelSelectedState.Selected;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
enum PanelSelectedState
|
||||
{
|
||||
NotSelected,
|
||||
Selected
|
||||
}
|
||||
}
|
@ -17,37 +17,41 @@ namespace osu.Game.Database
|
||||
{
|
||||
public class BeatmapDatabase
|
||||
{
|
||||
public static SQLiteConnection Connection { get; set; }
|
||||
private SQLiteConnection connection { get; set; }
|
||||
private BasicStorage storage;
|
||||
public event Action<BeatmapSetInfo> BeatmapSetAdded;
|
||||
|
||||
private BeatmapImporter ipc;
|
||||
|
||||
public BeatmapDatabase(BasicGameHost host)
|
||||
public BeatmapDatabase(BasicStorage storage, BasicGameHost importHost = null)
|
||||
{
|
||||
this.storage = host.Storage;
|
||||
this.storage = storage;
|
||||
|
||||
ipc = new BeatmapImporter(host, this);
|
||||
if (importHost != null)
|
||||
ipc = new BeatmapImporter(importHost, this);
|
||||
|
||||
if (Connection == null)
|
||||
if (connection == null)
|
||||
{
|
||||
Connection = storage.GetDatabase(@"beatmaps");
|
||||
Connection.CreateTable<BeatmapMetadata>();
|
||||
Connection.CreateTable<BaseDifficulty>();
|
||||
Connection.CreateTable<BeatmapSetInfo>();
|
||||
Connection.CreateTable<BeatmapInfo>();
|
||||
connection = storage.GetDatabase(@"beatmaps");
|
||||
connection.CreateTable<BeatmapMetadata>();
|
||||
connection.CreateTable<BaseDifficulty>();
|
||||
connection.CreateTable<BeatmapSetInfo>();
|
||||
connection.CreateTable<BeatmapInfo>();
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
foreach (var setInfo in Query<BeatmapSetInfo>())
|
||||
storage.Delete(setInfo.Path);
|
||||
{
|
||||
if (storage.Exists(setInfo.Path))
|
||||
storage.Delete(setInfo.Path);
|
||||
}
|
||||
|
||||
Connection.DeleteAll<BeatmapMetadata>();
|
||||
Connection.DeleteAll<BaseDifficulty>();
|
||||
Connection.DeleteAll<BeatmapSetInfo>();
|
||||
Connection.DeleteAll<BeatmapInfo>();
|
||||
connection.DeleteAll<BeatmapMetadata>();
|
||||
connection.DeleteAll<BaseDifficulty>();
|
||||
connection.DeleteAll<BeatmapSetInfo>();
|
||||
connection.DeleteAll<BeatmapInfo>();
|
||||
}
|
||||
|
||||
public void Import(params string[] paths)
|
||||
@ -62,7 +66,7 @@ namespace osu.Game.Database
|
||||
using (var reader = ArchiveReader.GetReader(storage, path))
|
||||
metadata = reader.ReadMetadata();
|
||||
|
||||
if (Connection.Table<BeatmapSetInfo>().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0)
|
||||
if (connection.Table<BeatmapSetInfo>().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0)
|
||||
return; // TODO: Update this beatmap instead
|
||||
|
||||
if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader
|
||||
@ -104,11 +108,24 @@ namespace osu.Game.Database
|
||||
}
|
||||
}
|
||||
}
|
||||
Connection.InsertWithChildren(beatmapSet, true);
|
||||
BeatmapSetAdded?.Invoke(beatmapSet);
|
||||
|
||||
Import(new[] { beatmapSet });
|
||||
}
|
||||
}
|
||||
|
||||
public void Import(IEnumerable<BeatmapSetInfo> beatmapSets)
|
||||
{
|
||||
connection.BeginTransaction();
|
||||
|
||||
foreach (var s in beatmapSets)
|
||||
{
|
||||
connection.InsertWithChildren(s, true);
|
||||
BeatmapSetAdded?.Invoke(s);
|
||||
}
|
||||
|
||||
connection.Commit();
|
||||
}
|
||||
|
||||
public ArchiveReader GetReader(BeatmapSetInfo beatmapSet)
|
||||
{
|
||||
return ArchiveReader.GetReader(storage, beatmapSet.Path);
|
||||
@ -136,25 +153,25 @@ namespace osu.Game.Database
|
||||
|
||||
public TableQuery<T> Query<T>() where T : class
|
||||
{
|
||||
return Connection.Table<T>();
|
||||
return connection.Table<T>();
|
||||
}
|
||||
|
||||
public T GetWithChildren<T>(object id) where T : class
|
||||
{
|
||||
return Connection.GetWithChildren<T>(id);
|
||||
return connection.GetWithChildren<T>(id);
|
||||
}
|
||||
|
||||
public List<T> GetAllWithChildren<T>(Expression<Func<T, bool>> filter = null,
|
||||
bool recursive = true) where T : class
|
||||
{
|
||||
return Connection.GetAllWithChildren<T>(filter, recursive);
|
||||
return connection.GetAllWithChildren<T>(filter, recursive);
|
||||
}
|
||||
|
||||
public T GetChildren<T>(T item, bool recursive = true)
|
||||
{
|
||||
if (item == null) return default(T);
|
||||
|
||||
Connection.GetChildren(item, recursive);
|
||||
connection.GetChildren(item, recursive);
|
||||
return item;
|
||||
}
|
||||
|
||||
@ -171,9 +188,9 @@ namespace osu.Game.Database
|
||||
if (!validTypes.Any(t => t == typeof(T)))
|
||||
throw new ArgumentException(nameof(T), "Must be a type managed by BeatmapDatabase");
|
||||
if (cascade)
|
||||
Connection.UpdateWithChildren(record);
|
||||
connection.UpdateWithChildren(record);
|
||||
else
|
||||
Connection.Update(record);
|
||||
connection.Update(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -16,22 +17,25 @@ using OpenTK.Graphics;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Game.Beatmaps.Drawable;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
|
||||
namespace osu.Game.GameModes.Play
|
||||
{
|
||||
public class PlaySongSelect : OsuGameMode
|
||||
{
|
||||
private Bindable<PlayMode> playMode;
|
||||
private BeatmapDatabase beatmaps;
|
||||
private BeatmapDatabase database;
|
||||
private BeatmapGroup selectedBeatmapGroup;
|
||||
private BeatmapInfo selectedBeatmap;
|
||||
// TODO: use currently selected track as bg
|
||||
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
|
||||
private ScrollContainer scrollContainer;
|
||||
private FlowContainer setList;
|
||||
|
||||
public PlaySongSelect()
|
||||
/// <param name="database">Optionally provide a database to use instead of the OsuGame one.</param>
|
||||
public PlaySongSelect(BeatmapDatabase database = null)
|
||||
{
|
||||
this.database = database;
|
||||
|
||||
const float scrollWidth = 640;
|
||||
const float bottomToolHeight = 50;
|
||||
Children = new Drawable[]
|
||||
@ -101,7 +105,10 @@ namespace osu.Game.GameModes.Play
|
||||
Width = 100,
|
||||
Text = "Play",
|
||||
Colour = new Color4(238, 51, 153, 255),
|
||||
Action = () => Push(new Player { Beatmap = beatmaps.GetBeatmap(selectedBeatmap) }),
|
||||
Action = () => Push(new Player {
|
||||
BeatmapInfo = selectedBeatmapGroup.SelectedPanel.Beatmap,
|
||||
PlayMode = playMode.Value
|
||||
}),
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -121,8 +128,11 @@ namespace osu.Game.GameModes.Play
|
||||
scrollContainer.Padding = new MarginPadding { Top = osuGame.Toolbar.Height };
|
||||
}
|
||||
|
||||
beatmaps = (game as OsuGameBase).Beatmaps;
|
||||
beatmaps.BeatmapSetAdded += bset => Scheduler.Add(() => addBeatmapSet(bset));
|
||||
if (database == null)
|
||||
database = (game as OsuGameBase).Beatmaps;
|
||||
|
||||
database.BeatmapSetAdded += s => Schedule(() => addBeatmapSet(s));
|
||||
|
||||
Task.Factory.StartNew(addBeatmapSets);
|
||||
}
|
||||
|
||||
@ -146,28 +156,25 @@ namespace osu.Game.GameModes.Play
|
||||
selectedBeatmapGroup.State = BeatmapGroupState.Collapsed;
|
||||
|
||||
selectedBeatmapGroup = group;
|
||||
selectedBeatmap = beatmap;
|
||||
}
|
||||
|
||||
private void addBeatmapSet(BeatmapSetInfo beatmapSet)
|
||||
{
|
||||
beatmapSet = beatmaps.GetWithChildren<BeatmapSetInfo>(beatmapSet.BeatmapSetID);
|
||||
beatmapSet.Beatmaps.ForEach(b => beatmaps.GetChildren(b));
|
||||
beatmapSet = database.GetWithChildren<BeatmapSetInfo>(beatmapSet.BeatmapSetID);
|
||||
beatmapSet.Beatmaps.ForEach(b => database.GetChildren(b));
|
||||
beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.BaseDifficulty.OverallDifficulty).ToList();
|
||||
Schedule(() =>
|
||||
{
|
||||
var group = new BeatmapGroup(beatmapSet) { SelectionChanged = selectBeatmap };
|
||||
setList.Add(group);
|
||||
if (setList.Children.Count() == 1)
|
||||
{
|
||||
group.State = BeatmapGroupState.Expanded;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addBeatmapSets()
|
||||
{
|
||||
foreach (var beatmapSet in beatmaps.Query<BeatmapSetInfo>())
|
||||
foreach (var beatmapSet in database.Query<BeatmapSetInfo>())
|
||||
addBeatmapSet(beatmapSet);
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ using osu.Game.GameModes.Play.Mania;
|
||||
using osu.Game.GameModes.Play.Osu;
|
||||
using osu.Game.GameModes.Play.Taiko;
|
||||
using osu.Framework;
|
||||
using osu.Game.Database;
|
||||
|
||||
namespace osu.Game.GameModes.Play
|
||||
{
|
||||
@ -18,6 +19,7 @@ namespace osu.Game.GameModes.Play
|
||||
{
|
||||
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
|
||||
|
||||
public BeatmapInfo BeatmapInfo;
|
||||
public Beatmap Beatmap;
|
||||
|
||||
public PlayMode PlayMode;
|
||||
@ -26,10 +28,17 @@ namespace osu.Game.GameModes.Play
|
||||
{
|
||||
base.Load(game);
|
||||
|
||||
Beatmap beatmap = new Beatmap
|
||||
try
|
||||
{
|
||||
HitObjects = Beatmap?.HitObjects ?? new List<HitObject>()
|
||||
};
|
||||
if (Beatmap == null)
|
||||
Beatmap = ((OsuGame)game).Beatmaps.GetBeatmap(BeatmapInfo);
|
||||
}
|
||||
catch
|
||||
{
|
||||
//couldn't load, hard abort!
|
||||
Exit();
|
||||
return;
|
||||
}
|
||||
|
||||
HitRenderer hitRenderer;
|
||||
ScoreOverlay scoreOverlay;
|
||||
@ -41,37 +50,37 @@ namespace osu.Game.GameModes.Play
|
||||
|
||||
hitRenderer = new OsuHitRenderer
|
||||
{
|
||||
Objects = beatmap.HitObjects,
|
||||
Objects = Beatmap.HitObjects,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre
|
||||
};
|
||||
break;
|
||||
case PlayMode.Taiko:
|
||||
scoreOverlay = null;
|
||||
scoreOverlay = new ScoreOverlayOsu();
|
||||
|
||||
hitRenderer = new TaikoHitRenderer
|
||||
{
|
||||
Objects = beatmap.HitObjects,
|
||||
Objects = Beatmap.HitObjects,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre
|
||||
};
|
||||
break;
|
||||
case PlayMode.Catch:
|
||||
scoreOverlay = null;
|
||||
scoreOverlay = new ScoreOverlayOsu();
|
||||
|
||||
hitRenderer = new CatchHitRenderer
|
||||
{
|
||||
Objects = beatmap.HitObjects,
|
||||
Objects = Beatmap.HitObjects,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre
|
||||
};
|
||||
break;
|
||||
case PlayMode.Mania:
|
||||
scoreOverlay = null;
|
||||
scoreOverlay = new ScoreOverlayOsu();
|
||||
|
||||
hitRenderer = new ManiaHitRenderer
|
||||
{
|
||||
Objects = beatmap.HitObjects,
|
||||
Objects = Beatmap.HitObjects,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre
|
||||
};
|
||||
|
@ -48,7 +48,7 @@ namespace osu.Game
|
||||
base.Load(game);
|
||||
|
||||
OszArchiveReader.Register();
|
||||
Beatmaps = new BeatmapDatabase(Host);
|
||||
Beatmaps = new BeatmapDatabase(Host.Storage, Host);
|
||||
|
||||
//this completely overrides the framework default. will need to change once we make a proper FontStore.
|
||||
Fonts = new TextureStore() { ScaleAdjust = 0.01f };
|
||||
|
@ -66,6 +66,7 @@
|
||||
<Compile Include="Beatmaps\Beatmap.cs" />
|
||||
<Compile Include="Beatmaps\Drawable\BeatmapSetHeader.cs" />
|
||||
<Compile Include="Beatmaps\Drawable\DifficultyIcon.cs" />
|
||||
<Compile Include="Beatmaps\Drawable\Panel.cs" />
|
||||
<Compile Include="Beatmaps\Objects\Catch\CatchConverter.cs" />
|
||||
<Compile Include="Beatmaps\Objects\Catch\Drawable\DrawableFruit.cs" />
|
||||
<Compile Include="Beatmaps\Objects\DrawableHitObject.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user