2024-07-09 19:57:29 +08:00
|
|
|
// 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.
|
|
|
|
|
2024-07-09 20:50:33 +08:00
|
|
|
using System;
|
2024-07-09 19:57:29 +08:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
2024-07-09 20:20:29 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2024-07-09 19:57:29 +08:00
|
|
|
using osu.Framework.Platform;
|
2024-07-09 20:50:33 +08:00
|
|
|
using osu.Framework.Screens;
|
|
|
|
using osu.Framework.Testing;
|
2024-07-09 19:57:29 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Database;
|
2024-07-09 20:20:29 +08:00
|
|
|
using osu.Game.Graphics;
|
2024-07-09 20:50:33 +08:00
|
|
|
using osu.Game.Graphics.Containers;
|
2024-07-09 20:20:29 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2024-07-09 20:50:33 +08:00
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
2024-07-09 20:20:29 +08:00
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Game.Screens.OnlinePlay.Match.Components;
|
|
|
|
using osuTK;
|
2024-07-09 19:57:29 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit
|
|
|
|
{
|
|
|
|
internal partial class ExternalEditScreen : OsuScreen
|
|
|
|
{
|
|
|
|
private readonly Task<ExternalEditOperation<BeatmapSetInfo>> fileMountOperation;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private GameHost gameHost { get; set; } = null!;
|
|
|
|
|
2024-07-09 20:20:29 +08:00
|
|
|
[Resolved]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
|
|
|
|
2024-07-09 20:50:33 +08:00
|
|
|
private readonly Editor editor;
|
2024-07-09 19:57:29 +08:00
|
|
|
|
2024-07-10 13:51:34 +08:00
|
|
|
public ExternalEditOperation<BeatmapSetInfo>? EditOperation;
|
2024-07-09 20:20:29 +08:00
|
|
|
|
2024-07-09 20:50:33 +08:00
|
|
|
private double timeLoaded;
|
|
|
|
|
|
|
|
private FillFlowContainer flow = null!;
|
|
|
|
|
2024-07-09 19:57:29 +08:00
|
|
|
public ExternalEditScreen(Task<ExternalEditOperation<BeatmapSetInfo>> fileMountOperation, Editor editor)
|
|
|
|
{
|
|
|
|
this.fileMountOperation = fileMountOperation;
|
|
|
|
this.editor = editor;
|
|
|
|
}
|
|
|
|
|
2024-07-09 20:20:29 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
InternalChild = new Container
|
|
|
|
{
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 20,
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
AutoSizeDuration = 500,
|
|
|
|
AutoSizeEasing = Easing.OutQuint,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Colour = colourProvider.Background5,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2024-07-09 20:50:33 +08:00
|
|
|
flow = new FillFlowContainer
|
2024-07-09 20:20:29 +08:00
|
|
|
{
|
|
|
|
Margin = new MarginPadding(20),
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Vertical,
|
2024-07-09 20:50:33 +08:00
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
2024-07-09 20:20:29 +08:00
|
|
|
Spacing = new Vector2(15),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2024-07-09 20:50:33 +08:00
|
|
|
|
|
|
|
showSpinner("Exporting for edit...");
|
2024-07-09 20:20:29 +08:00
|
|
|
}
|
|
|
|
|
2024-07-09 19:57:29 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2024-07-09 20:50:33 +08:00
|
|
|
timeLoaded = Time.Current;
|
|
|
|
|
2024-07-09 19:57:29 +08:00
|
|
|
fileMountOperation.ContinueWith(t =>
|
|
|
|
{
|
2024-07-10 13:51:34 +08:00
|
|
|
EditOperation = t.GetResultSafely();
|
2024-07-09 20:50:33 +08:00
|
|
|
|
|
|
|
Scheduler.AddDelayed(() =>
|
|
|
|
{
|
|
|
|
flow.Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = "Beatmap is mounted externally",
|
|
|
|
Font = OsuFont.Default.With(size: 30),
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
},
|
|
|
|
new OsuTextFlowContainer
|
|
|
|
{
|
|
|
|
Padding = new MarginPadding(5),
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Width = 350,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Text = "Any changes made to the exported folder will be imported to the game, including file additions, modifications and deletions.",
|
|
|
|
},
|
|
|
|
new PurpleRoundedButton
|
|
|
|
{
|
|
|
|
Text = "Open folder",
|
|
|
|
Width = 350,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Action = open,
|
|
|
|
Enabled = { Value = false }
|
|
|
|
},
|
|
|
|
new DangerousRoundedButton
|
|
|
|
{
|
|
|
|
Text = "Finish editing and import changes",
|
|
|
|
Width = 350,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Action = finish,
|
|
|
|
Enabled = { Value = false }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Scheduler.AddDelayed(() =>
|
|
|
|
{
|
|
|
|
foreach (var b in flow.ChildrenOfType<RoundedButton>())
|
|
|
|
b.Enabled.Value = true;
|
|
|
|
open();
|
|
|
|
}, 1000);
|
|
|
|
}, Math.Max(0, 1000 - (Time.Current - timeLoaded)));
|
2024-07-09 19:57:29 +08:00
|
|
|
});
|
2024-07-09 20:20:29 +08:00
|
|
|
}
|
2024-07-09 19:57:29 +08:00
|
|
|
|
2024-07-09 20:20:29 +08:00
|
|
|
private void open()
|
|
|
|
{
|
2024-07-10 13:51:34 +08:00
|
|
|
if (EditOperation == null)
|
2024-07-09 20:20:29 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Ensure the trailing separator is present in order to show the folder contents.
|
2024-07-10 13:51:34 +08:00
|
|
|
gameHost.OpenFileExternally(EditOperation.MountedPath.TrimDirectorySeparator() + Path.DirectorySeparatorChar);
|
2024-07-09 19:57:29 +08:00
|
|
|
}
|
|
|
|
|
2024-07-09 20:50:33 +08:00
|
|
|
public override bool OnExiting(ScreenExitEvent e)
|
|
|
|
{
|
|
|
|
if (!fileMountOperation.IsCompleted)
|
|
|
|
return false;
|
|
|
|
|
2024-07-10 13:51:34 +08:00
|
|
|
if (EditOperation != null)
|
2024-07-09 20:50:33 +08:00
|
|
|
{
|
|
|
|
finish();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return base.OnExiting(e);
|
|
|
|
}
|
|
|
|
|
2024-07-09 19:57:29 +08:00
|
|
|
private void finish()
|
|
|
|
{
|
2024-07-09 20:53:57 +08:00
|
|
|
string originalDifficulty = editor.Beatmap.Value.Beatmap.BeatmapInfo.DifficultyName;
|
|
|
|
|
2024-07-09 20:50:33 +08:00
|
|
|
showSpinner("Cleaning up...");
|
|
|
|
|
|
|
|
EditOperation!.Finish().ContinueWith(t =>
|
2024-07-09 19:57:29 +08:00
|
|
|
{
|
|
|
|
Schedule(() =>
|
|
|
|
{
|
2024-07-09 20:50:33 +08:00
|
|
|
// Setting to null will allow exit to succeed.
|
2024-07-10 13:51:34 +08:00
|
|
|
EditOperation = null;
|
2024-07-09 20:50:33 +08:00
|
|
|
|
2024-07-09 20:53:57 +08:00
|
|
|
Live<BeatmapSetInfo>? beatmap = t.GetResultSafely();
|
2024-07-09 20:50:33 +08:00
|
|
|
|
|
|
|
if (beatmap == null)
|
|
|
|
this.Exit();
|
|
|
|
else
|
2024-07-09 20:53:57 +08:00
|
|
|
{
|
|
|
|
var closestMatchingBeatmap =
|
|
|
|
beatmap.Value.Beatmaps.FirstOrDefault(b => b.DifficultyName == originalDifficulty)
|
|
|
|
?? beatmap.Value.Beatmaps.First();
|
|
|
|
|
|
|
|
editor.SwitchToDifficulty(closestMatchingBeatmap);
|
|
|
|
}
|
2024-07-09 19:57:29 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2024-07-09 20:50:33 +08:00
|
|
|
|
|
|
|
private void showSpinner(string text)
|
|
|
|
{
|
|
|
|
foreach (var b in flow.ChildrenOfType<RoundedButton>())
|
|
|
|
b.Enabled.Value = false;
|
|
|
|
|
|
|
|
flow.Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new OsuSpriteText
|
|
|
|
{
|
|
|
|
Text = text,
|
|
|
|
Font = OsuFont.Default.With(size: 30),
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
},
|
|
|
|
new LoadingSpinner
|
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
State = { Value = Visibility.Visible }
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
2024-07-09 19:57:29 +08:00
|
|
|
}
|
|
|
|
}
|