mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 13:37:25 +08:00
Merge pull request #313 from default0/default0/beatmap-import
Implement Beatmap Import via drag&drop
This commit is contained in:
commit
65471364a7
@ -1 +1 @@
|
||||
Subproject commit f9627494e444d8b35eb20d418539ada15f258c4d
|
||||
Subproject commit a642501e72bb0c062835e75151eac45df1ad481d
|
55
osu.Desktop/OsuGameDesktop.cs
Normal file
55
osu.Desktop/OsuGameDesktop.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using osu.Game;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Framework.Desktop.Platform;
|
||||
using osu.Game.Database;
|
||||
|
||||
namespace osu.Desktop
|
||||
{
|
||||
class OsuGameDesktop : OsuGame
|
||||
{
|
||||
public OsuGameDesktop(string[] args = null)
|
||||
: base(args)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void SetHost(BasicGameHost host)
|
||||
{
|
||||
base.SetHost(host);
|
||||
var desktopWindow = host.Window as DesktopGameWindow;
|
||||
if (desktopWindow != null)
|
||||
{
|
||||
desktopWindow.DragEnter += dragEnter;
|
||||
desktopWindow.DragDrop += dragDrop;
|
||||
}
|
||||
}
|
||||
|
||||
private void dragDrop(DragEventArgs e)
|
||||
{
|
||||
// this method will only be executed if e.Effect in dragEnter gets set to something other that None.
|
||||
var dropData = e.Data.GetData(DataFormats.FileDrop) as object[];
|
||||
var filePaths = dropData.Select(f => f.ToString()).ToArray();
|
||||
ImportBeatmaps(filePaths);
|
||||
}
|
||||
|
||||
private void dragEnter(DragEventArgs e)
|
||||
{
|
||||
// dragDrop will only be executed if e.Effect gets set to something other that None in this method.
|
||||
bool isFile = e.Data.GetDataPresent(DataFormats.FileDrop);
|
||||
if (isFile)
|
||||
{
|
||||
var paths = (e.Data.GetData(DataFormats.FileDrop) as object[]).Select(f => f.ToString()).ToArray();
|
||||
if (paths.Any(p => !p.EndsWith(".osz")))
|
||||
e.Effect = DragDropEffects.None;
|
||||
else
|
||||
e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -51,7 +51,7 @@ namespace osu.Desktop
|
||||
Ruleset.Register(new ManiaRuleset());
|
||||
Ruleset.Register(new CatchRuleset());
|
||||
|
||||
BaseGame osu = new OsuGame(args);
|
||||
BaseGame osu = new OsuGameDesktop(args);
|
||||
host.Add(osu);
|
||||
host.Run();
|
||||
}
|
||||
|
@ -81,7 +81,9 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="OpenTK, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\osu.licenseheader">
|
||||
@ -152,6 +154,7 @@
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="OsuGameDesktop.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Beatmaps\IO\LegacyFilesystemReader.cs" />
|
||||
</ItemGroup>
|
||||
|
@ -22,6 +22,7 @@ using osu.Game.Overlays.Toolbar;
|
||||
using osu.Game.Screens;
|
||||
using osu.Game.Screens.Menu;
|
||||
using OpenTK;
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game
|
||||
{
|
||||
@ -63,13 +64,18 @@ namespace osu.Game
|
||||
}
|
||||
|
||||
if (args?.Length > 0)
|
||||
Schedule(delegate { Dependencies.Get<BeatmapDatabase>().Import(args); });
|
||||
ImportBeatmaps(args);
|
||||
|
||||
Dependencies.Cache(this);
|
||||
|
||||
PlayMode = LocalConfig.GetBindable<PlayMode>(OsuConfig.PlayMode);
|
||||
}
|
||||
|
||||
public void ImportBeatmaps(params string[] paths)
|
||||
{
|
||||
Schedule(delegate { Dependencies.Get<BeatmapDatabase>().Import(paths); });
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
Loading…
Reference in New Issue
Block a user