mirror of
https://github.com/ppy/osu.git
synced 2025-02-08 07:55:38 +08:00
Add special handling for file import button on iOS
This commit is contained in:
parent
eeac8f530f
commit
2bae93d7ad
@ -2,7 +2,9 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
|
using osu.Framework.Platform;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
using osu.Game.Localisation;
|
using osu.Game.Localisation;
|
||||||
using osu.Game.Screens;
|
using osu.Game.Screens;
|
||||||
@ -15,22 +17,32 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
|||||||
{
|
{
|
||||||
protected override LocalisableString Header => CommonStrings.General;
|
protected override LocalisableString Header => CommonStrings.General;
|
||||||
|
|
||||||
|
private SystemFileImportComponent systemFileImport = null!;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(IPerformFromScreenRunner? performer)
|
private void load(OsuGame game, GameHost host, IPerformFromScreenRunner? performer)
|
||||||
{
|
{
|
||||||
Children = new[]
|
Add(systemFileImport = new SystemFileImportComponent(game, host));
|
||||||
|
|
||||||
|
AddRange(new Drawable[]
|
||||||
{
|
{
|
||||||
new SettingsButton
|
new SettingsButton
|
||||||
{
|
{
|
||||||
Text = DebugSettingsStrings.ImportFiles,
|
Text = DebugSettingsStrings.ImportFiles,
|
||||||
Action = () => performer?.PerformFromScreen(menu => menu.Push(new FileImportScreen()))
|
Action = () =>
|
||||||
|
{
|
||||||
|
if (systemFileImport.PresentIfAvailable())
|
||||||
|
return;
|
||||||
|
|
||||||
|
performer?.PerformFromScreen(menu => menu.Push(new FileImportScreen()));
|
||||||
|
},
|
||||||
},
|
},
|
||||||
new SettingsButton
|
new SettingsButton
|
||||||
{
|
{
|
||||||
Text = DebugSettingsStrings.RunLatencyCertifier,
|
Text = DebugSettingsStrings.RunLatencyCertifier,
|
||||||
Action = () => performer?.PerformFromScreen(menu => menu.Push(new LatencyCertifierScreen()))
|
Action = () => performer?.PerformFromScreen(menu => menu.Push(new LatencyCertifierScreen()))
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Platform;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Settings.Sections.Maintenance
|
||||||
|
{
|
||||||
|
public partial class SystemFileImportComponent : Component
|
||||||
|
{
|
||||||
|
private readonly OsuGame game;
|
||||||
|
private readonly GameHost host;
|
||||||
|
|
||||||
|
private ISystemFileSelector? selector;
|
||||||
|
|
||||||
|
public SystemFileImportComponent(OsuGame game, GameHost host)
|
||||||
|
{
|
||||||
|
this.game = game;
|
||||||
|
this.host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
selector = host.CreateSystemFileSelector(game.HandledExtensions.ToArray());
|
||||||
|
|
||||||
|
if (selector != null)
|
||||||
|
selector.Selected += f => Schedule(() => startImport(f.FullName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool PresentIfAvailable()
|
||||||
|
{
|
||||||
|
if (selector == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
selector.Present();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startImport(string path)
|
||||||
|
{
|
||||||
|
Task.Factory.StartNew(async () =>
|
||||||
|
{
|
||||||
|
await game.Import(path).ConfigureAwait(false);
|
||||||
|
}, TaskCreationOptions.LongRunning);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user