2021-09-05 22:59:28 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2021-12-10 17:57:43 +08:00
|
|
|
using System;
|
2021-09-05 23:26:09 +08:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
using osu.Framework.Allocation;
|
2022-02-15 03:56:05 +08:00
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2021-09-07 13:34:54 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-01-24 02:42:07 +08:00
|
|
|
using osu.Framework.Logging;
|
2021-09-05 22:59:28 +08:00
|
|
|
using osu.Framework.Screens;
|
2021-09-06 01:11:46 +08:00
|
|
|
using osu.Framework.Threading;
|
2021-09-05 23:26:09 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2021-09-07 13:34:47 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-02-15 03:56:05 +08:00
|
|
|
using osu.Game.Rulesets;
|
2021-12-10 17:57:43 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2021-09-06 02:24:07 +08:00
|
|
|
using osu.Game.Screens.Menu;
|
2021-09-07 13:34:54 +08:00
|
|
|
using osu.Game.Screens.Play;
|
2021-09-05 22:59:28 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Transition screen for the editor.
|
|
|
|
/// Used to avoid backing out to main menu/song select when switching difficulties from within the editor.
|
|
|
|
/// </summary>
|
2021-09-07 13:34:54 +08:00
|
|
|
public class EditorLoader : ScreenWithBeatmapBackground
|
2021-09-05 22:59:28 +08:00
|
|
|
{
|
2021-09-12 00:36:57 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The stored state from the last editor opened.
|
|
|
|
/// This will be read by the next editor instance to be opened to restore any relevant previous state.
|
|
|
|
/// </summary>
|
|
|
|
[CanBeNull]
|
2021-09-14 22:26:02 +08:00
|
|
|
private EditorState state;
|
2021-09-12 00:36:57 +08:00
|
|
|
|
2021-09-06 02:24:07 +08:00
|
|
|
public override float BackgroundParallaxAmount => 0.1f;
|
|
|
|
|
|
|
|
public override bool AllowBackButton => false;
|
|
|
|
|
|
|
|
public override bool HideOverlaysOnEnter => true;
|
|
|
|
|
|
|
|
public override bool DisallowExternalBeatmapRulesetChanges => true;
|
|
|
|
|
2021-09-05 23:26:09 +08:00
|
|
|
[Resolved]
|
|
|
|
private BeatmapManager beatmapManager { get; set; }
|
|
|
|
|
2021-09-06 01:11:46 +08:00
|
|
|
[CanBeNull]
|
|
|
|
private ScheduledDelegate scheduledDifficultySwitch;
|
|
|
|
|
2021-09-12 02:43:17 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
AddRangeInternal(new Drawable[]
|
|
|
|
{
|
|
|
|
new LoadingSpinner(true)
|
|
|
|
{
|
|
|
|
State = { Value = Visibility.Visible },
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-10 17:57:43 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
// will be restored via lease, see `DisallowExternalBeatmapRulesetChanges`.
|
2021-12-11 18:33:37 +08:00
|
|
|
Mods.Value = Array.Empty<Mod>();
|
2021-12-10 17:57:43 +08:00
|
|
|
}
|
|
|
|
|
2021-09-12 02:43:17 +08:00
|
|
|
protected virtual Editor CreateEditor() => new Editor(this);
|
|
|
|
|
2021-09-06 02:24:07 +08:00
|
|
|
protected override void LogoArriving(OsuLogo logo, bool resuming)
|
2021-09-05 22:59:28 +08:00
|
|
|
{
|
2021-09-06 02:24:07 +08:00
|
|
|
base.LogoArriving(logo, resuming);
|
2021-09-07 03:31:59 +08:00
|
|
|
|
2021-09-07 13:34:18 +08:00
|
|
|
if (!resuming)
|
|
|
|
{
|
|
|
|
// the push cannot happen in OnEntering() or similar (even if scheduled), because the transition from main menu will look bad.
|
|
|
|
// that is because this screen pushing the editor makes it no longer current, and OsuScreen checks if the screen is current
|
|
|
|
// before enqueueing this screen's LogoArriving onto the logo animation sequence.
|
|
|
|
pushEditor();
|
|
|
|
}
|
2021-09-05 22:59:28 +08:00
|
|
|
}
|
|
|
|
|
2022-02-15 03:56:05 +08:00
|
|
|
public void ScheduleSwitchToNewDifficulty(BeatmapInfo referenceBeatmapInfo, RulesetInfo rulesetInfo, bool createCopy, EditorState editorState)
|
2022-01-24 02:42:07 +08:00
|
|
|
=> scheduleDifficultySwitch(() =>
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2022-02-15 03:56:05 +08:00
|
|
|
// fetch a fresh detached reference from database to avoid polluting model instances attached to cached working beatmaps.
|
|
|
|
var targetBeatmapSet = beatmapManager.QueryBeatmap(b => b.ID == referenceBeatmapInfo.ID).AsNonNull().BeatmapSet.AsNonNull();
|
|
|
|
var referenceWorkingBeatmap = beatmapManager.GetWorkingBeatmap(referenceBeatmapInfo);
|
|
|
|
|
|
|
|
return createCopy
|
|
|
|
? beatmapManager.CopyExistingDifficulty(targetBeatmapSet, referenceWorkingBeatmap)
|
|
|
|
: beatmapManager.CreateNewDifficulty(targetBeatmapSet, referenceWorkingBeatmap, rulesetInfo);
|
2022-01-24 02:42:07 +08:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
// if the beatmap creation fails (e.g. due to duplicated difficulty names),
|
|
|
|
// bring the user back to the previous beatmap as a best-effort.
|
|
|
|
Logger.Error(ex, ex.Message);
|
|
|
|
return Beatmap.Value;
|
|
|
|
}
|
2022-02-15 03:56:05 +08:00
|
|
|
}, editorState);
|
2022-01-24 00:49:17 +08:00
|
|
|
|
|
|
|
public void ScheduleSwitchToExistingDifficulty(BeatmapInfo beatmapInfo, EditorState editorState)
|
|
|
|
=> scheduleDifficultySwitch(() => beatmapManager.GetWorkingBeatmap(beatmapInfo), editorState);
|
|
|
|
|
|
|
|
private void scheduleDifficultySwitch(Func<WorkingBeatmap> nextBeatmap, EditorState editorState)
|
2021-09-06 01:11:46 +08:00
|
|
|
{
|
2021-09-07 03:30:50 +08:00
|
|
|
scheduledDifficultySwitch?.Cancel();
|
|
|
|
ValidForResume = true;
|
|
|
|
|
|
|
|
this.MakeCurrent();
|
2021-09-07 13:34:54 +08:00
|
|
|
|
2021-09-06 01:11:46 +08:00
|
|
|
scheduledDifficultySwitch = Schedule(() =>
|
|
|
|
{
|
2022-01-24 00:49:17 +08:00
|
|
|
Beatmap.Value = nextBeatmap.Invoke();
|
2021-09-14 22:26:02 +08:00
|
|
|
state = editorState;
|
2021-09-07 13:34:54 +08:00
|
|
|
|
|
|
|
// This screen is a weird exception to the rule that nothing after song select changes the global beatmap.
|
|
|
|
// Because of this, we need to update the background stack's beatmap to match.
|
|
|
|
// If we don't do this, the editor will see a discrepancy and create a new background, along with an unnecessary transition.
|
|
|
|
ApplyToBackground(b => b.Beatmap = Beatmap.Value);
|
|
|
|
|
2021-09-06 01:11:46 +08:00
|
|
|
pushEditor();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-09-07 13:34:47 +08:00
|
|
|
private void pushEditor()
|
|
|
|
{
|
2021-09-14 22:36:17 +08:00
|
|
|
var editor = CreateEditor();
|
|
|
|
|
|
|
|
this.Push(editor);
|
|
|
|
|
|
|
|
if (state != null)
|
|
|
|
editor.RestoreState(state);
|
|
|
|
|
2021-09-07 13:34:47 +08:00
|
|
|
ValidForResume = false;
|
|
|
|
}
|
|
|
|
|
2021-09-07 03:30:50 +08:00
|
|
|
public void CancelPendingDifficultySwitch()
|
|
|
|
{
|
|
|
|
scheduledDifficultySwitch?.Cancel();
|
|
|
|
ValidForResume = false;
|
|
|
|
}
|
2021-09-05 22:59:28 +08:00
|
|
|
}
|
|
|
|
}
|