From 59727ce836b6ac76c8dc60a0b3482f3adffdf991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 10 Nov 2021 23:11:25 +0100 Subject: [PATCH] Add minimal implementation of gameplay testing from editor --- osu.Game/Screens/Edit/Editor.cs | 37 +++++++++++++++++-- osu.Game/Screens/Edit/EditorPlayer.cs | 22 +++++++++++ .../Edit/SaveBeforeGameplayTestDialog.cs | 32 ++++++++++++++++ 3 files changed, 88 insertions(+), 3 deletions(-) create mode 100644 osu.Game/Screens/Edit/EditorPlayer.cs create mode 100644 osu.Game/Screens/Edit/SaveBeforeGameplayTestDialog.cs diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index ef9cce4bf7..a67ef070f6 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -294,6 +294,7 @@ namespace osu.Game.Screens.Edit RelativeSizeAxes = Axes.Both, Padding = new MarginPadding { Left = 10 }, Size = new Vector2(1), + Action = testGameplay } }, } @@ -521,7 +522,21 @@ namespace osu.Game.Screens.Edit ApplyToBackground(b => b.FadeColour(Color4.White, 500)); resetTrack(); - // To update the game-wide beatmap with any changes, perform a re-fetch on exit. + refetchBeatmap(); + + return base.OnExiting(next); + } + + public override void OnSuspending(IScreen next) + { + refetchBeatmap(); + + base.OnSuspending(next); + } + + private void refetchBeatmap() + { + // To update the game-wide beatmap with any changes, perform a re-fetch on exit/suspend. // This is required as the editor makes its local changes via EditorBeatmap // (which are not propagated outwards to a potentially cached WorkingBeatmap). var refetchedBeatmap = beatmapManager.GetWorkingBeatmap(Beatmap.Value.BeatmapInfo); @@ -531,8 +546,6 @@ namespace osu.Game.Screens.Edit Logger.Log("Editor providing re-fetched beatmap post edit session"); Beatmap.Value = refetchedBeatmap; } - - return base.OnExiting(next); } private void confirmExitWithSave() @@ -763,6 +776,24 @@ namespace osu.Game.Screens.Edit loader?.CancelPendingDifficultySwitch(); } + private void testGameplay() + { + if (HasUnsavedChanges) + { + dialogOverlay.Push(new SaveBeforeGameplayTestDialog(() => + { + Save(); + pushEditorPlayer(); + })); + } + else + { + pushEditorPlayer(); + } + + void pushEditorPlayer() => this.Push(new PlayerLoader(() => new EditorPlayer())); + } + public double SnapTime(double time, double? referenceTime) => editorBeatmap.SnapTime(time, referenceTime); public double GetBeatLengthAtTime(double referenceTime) => editorBeatmap.GetBeatLengthAtTime(referenceTime); diff --git a/osu.Game/Screens/Edit/EditorPlayer.cs b/osu.Game/Screens/Edit/EditorPlayer.cs new file mode 100644 index 0000000000..f8dd75d94a --- /dev/null +++ b/osu.Game/Screens/Edit/EditorPlayer.cs @@ -0,0 +1,22 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Game.Screens.Play; + +namespace osu.Game.Screens.Edit +{ + public class EditorPlayer : Player + { + public EditorPlayer() + : base(new PlayerConfiguration { ShowResults = false }) + { + } + + protected override void PrepareReplay() + { + // don't record replays. + } + + protected override bool CheckModsAllowFailure() => false; // never fail. + } +} diff --git a/osu.Game/Screens/Edit/SaveBeforeGameplayTestDialog.cs b/osu.Game/Screens/Edit/SaveBeforeGameplayTestDialog.cs new file mode 100644 index 0000000000..7c03664c66 --- /dev/null +++ b/osu.Game/Screens/Edit/SaveBeforeGameplayTestDialog.cs @@ -0,0 +1,32 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using osu.Framework.Graphics.Sprites; +using osu.Game.Overlays.Dialog; + +namespace osu.Game.Screens.Edit +{ + public class SaveBeforeGameplayTestDialog : PopupDialog + { + public SaveBeforeGameplayTestDialog(Action saveAndPreview) + { + HeaderText = "The beatmap will be saved in order to test it."; + + Icon = FontAwesome.Regular.Save; + + Buttons = new PopupDialogButton[] + { + new PopupDialogOkButton + { + Text = "Sounds good, let's go!", + Action = saveAndPreview + }, + new PopupDialogCancelButton + { + Text = "Oops, continue editing", + }, + }; + } + } +}