1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 05:27:23 +08:00
osu-lazer/osu.Desktop/OsuGameDesktop.cs

77 lines
2.6 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game;
2017-02-05 05:03:39 +08:00
using System.Linq;
using System.Windows.Forms;
using osu.Framework.Platform;
using osu.Framework.Desktop.Platform;
using osu.Desktop.Overlays;
2017-02-12 14:03:36 +08:00
using System.Reflection;
using System.Drawing;
2017-02-18 13:16:46 +08:00
using osu.Game.Screens.Menu;
2017-02-05 05:03:39 +08:00
namespace osu.Desktop
{
class OsuGameDesktop : OsuGame
{
private VersionManager versionManager;
public override bool IsDeployedBuild => versionManager.IsDeployedBuild;
2017-02-05 05:03:39 +08:00
public OsuGameDesktop(string[] args = null)
: base(args)
{
2017-02-18 13:16:46 +08:00
versionManager = new VersionManager { Depth = int.MinValue };
2017-02-05 05:03:39 +08:00
}
protected override void LoadComplete()
{
base.LoadComplete();
versionManager.LoadAsync(this);
2017-02-18 13:16:46 +08:00
ModeChanged += m =>
{
if (!versionManager.IsAlive && m is Intro)
Add(versionManager);
};
}
2017-02-23 14:38:17 +08:00
public override void SetHost(GameHost host)
2017-02-05 05:03:39 +08:00
{
base.SetHost(host);
var desktopWindow = host.Window as DesktopGameWindow;
if (desktopWindow != null)
{
2017-02-12 14:03:36 +08:00
desktopWindow.Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location);
desktopWindow.Title = @"osu!lazer";
2017-02-05 05:03:39 +08:00
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();
2017-02-24 17:10:37 +08:00
ImportBeatmapsAsync(filePaths);
2017-02-05 05:03:39 +08:00
}
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;
}
}
}
}