From a5ba3bd012c95a6ab39ffcf3274a0ac74590efa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 12 Nov 2021 12:07:38 +0100 Subject: [PATCH 1/4] Move gameplay test pieces to own namespace --- osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs | 1 + osu.Game/Screens/Edit/Editor.cs | 1 + osu.Game/Screens/Edit/{ => GameplayTest}/EditorPlayer.cs | 2 +- .../Edit/{ => GameplayTest}/SaveBeforeGameplayTestDialog.cs | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) rename osu.Game/Screens/Edit/{ => GameplayTest}/EditorPlayer.cs (96%) rename osu.Game/Screens/Edit/{ => GameplayTest}/SaveBeforeGameplayTestDialog.cs (95%) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs b/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs index db42667033..e311c7a7ec 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs @@ -12,6 +12,7 @@ using osu.Game.Rulesets; using osu.Game.Rulesets.Osu; using osu.Game.Screens.Edit; using osu.Game.Screens.Edit.Components.Timelines.Summary; +using osu.Game.Screens.Edit.GameplayTest; using osu.Game.Tests.Beatmaps.IO; using osuTK.Input; diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 738f607cc8..0c54e39a35 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -31,6 +31,7 @@ using osu.Game.Screens.Edit.Components.Menus; using osu.Game.Screens.Edit.Components.Timelines.Summary; using osu.Game.Screens.Edit.Compose; using osu.Game.Screens.Edit.Design; +using osu.Game.Screens.Edit.GameplayTest; using osu.Game.Screens.Edit.Setup; using osu.Game.Screens.Edit.Timing; using osu.Game.Screens.Edit.Verify; diff --git a/osu.Game/Screens/Edit/EditorPlayer.cs b/osu.Game/Screens/Edit/GameplayTest/EditorPlayer.cs similarity index 96% rename from osu.Game/Screens/Edit/EditorPlayer.cs rename to osu.Game/Screens/Edit/GameplayTest/EditorPlayer.cs index b2fab3fefc..9856ad62bb 100644 --- a/osu.Game/Screens/Edit/EditorPlayer.cs +++ b/osu.Game/Screens/Edit/GameplayTest/EditorPlayer.cs @@ -6,7 +6,7 @@ using osu.Framework.Screens; using osu.Game.Overlays; using osu.Game.Screens.Play; -namespace osu.Game.Screens.Edit +namespace osu.Game.Screens.Edit.GameplayTest { public class EditorPlayer : Player { diff --git a/osu.Game/Screens/Edit/SaveBeforeGameplayTestDialog.cs b/osu.Game/Screens/Edit/GameplayTest/SaveBeforeGameplayTestDialog.cs similarity index 95% rename from osu.Game/Screens/Edit/SaveBeforeGameplayTestDialog.cs rename to osu.Game/Screens/Edit/GameplayTest/SaveBeforeGameplayTestDialog.cs index 7c03664c66..9334c74706 100644 --- a/osu.Game/Screens/Edit/SaveBeforeGameplayTestDialog.cs +++ b/osu.Game/Screens/Edit/GameplayTest/SaveBeforeGameplayTestDialog.cs @@ -5,7 +5,7 @@ using System; using osu.Framework.Graphics.Sprites; using osu.Game.Overlays.Dialog; -namespace osu.Game.Screens.Edit +namespace osu.Game.Screens.Edit.GameplayTest { public class SaveBeforeGameplayTestDialog : PopupDialog { From b47c0b63f4305fe3de7bcaf0d142825ddf3b3ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 12 Nov 2021 12:30:40 +0100 Subject: [PATCH 2/4] Tweak loader transition when testing gameplay in editor --- osu.Game/Screens/Edit/Editor.cs | 2 +- .../Edit/GameplayTest/EditorPlayerLoader.cs | 44 +++++++++++++++++++ osu.Game/Screens/Play/PlayerLoader.cs | 26 ++++++----- 3 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 osu.Game/Screens/Edit/GameplayTest/EditorPlayerLoader.cs diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 0c54e39a35..2c758eaf41 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -798,7 +798,7 @@ namespace osu.Game.Screens.Edit pushEditorPlayer(); } - void pushEditorPlayer() => this.Push(new PlayerLoader(() => new EditorPlayer())); + void pushEditorPlayer() => this.Push(new EditorPlayerLoader()); } public double SnapTime(double time, double? referenceTime) => editorBeatmap.SnapTime(time, referenceTime); diff --git a/osu.Game/Screens/Edit/GameplayTest/EditorPlayerLoader.cs b/osu.Game/Screens/Edit/GameplayTest/EditorPlayerLoader.cs new file mode 100644 index 0000000000..610fff70f2 --- /dev/null +++ b/osu.Game/Screens/Edit/GameplayTest/EditorPlayerLoader.cs @@ -0,0 +1,44 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Screens; +using osu.Game.Screens.Menu; +using osu.Game.Screens.Play; + +namespace osu.Game.Screens.Edit.GameplayTest +{ + public class EditorPlayerLoader : PlayerLoader + { + [Resolved] + private OsuLogo osuLogo { get; set; } + + public EditorPlayerLoader() + : base(() => new EditorPlayer()) + { + } + + public override void OnEntering(IScreen last) + { + base.OnEntering(last); + + MetadataInfo.FinishTransforms(true); + } + + protected override void LogoArriving(OsuLogo logo, bool resuming) + { + // call base with resuming forcefully set to true to reduce logo movements. + base.LogoArriving(logo, true); + logo.FinishTransforms(true, nameof(Scale)); + } + + protected override void ContentOut() + { + base.ContentOut(); + osuLogo.FadeOut(CONTENT_OUT_DURATION, Easing.OutQuint); + } + + protected override double PlayerPushDelay => 0; + } +} diff --git a/osu.Game/Screens/Play/PlayerLoader.cs b/osu.Game/Screens/Play/PlayerLoader.cs index ba34df0e59..57db411571 100644 --- a/osu.Game/Screens/Play/PlayerLoader.cs +++ b/osu.Game/Screens/Play/PlayerLoader.cs @@ -36,7 +36,9 @@ namespace osu.Game.Screens.Play { protected const float BACKGROUND_BLUR = 15; - private const double content_out_duration = 300; + protected const double CONTENT_OUT_DURATION = 300; + + protected virtual double PlayerPushDelay => 1800; public override bool HideOverlaysOnEnter => hideOverlays; @@ -213,7 +215,7 @@ namespace osu.Game.Screens.Play // after an initial delay, start the debounced load check. // this will continue to execute even after resuming back on restart. - Scheduler.Add(new ScheduledDelegate(pushWhenLoaded, Clock.CurrentTime + 1800, 0)); + Scheduler.Add(new ScheduledDelegate(pushWhenLoaded, Clock.CurrentTime + PlayerPushDelay, 0)); showMuteWarningIfNeeded(); showBatteryWarningIfNeeded(); @@ -248,13 +250,13 @@ namespace osu.Game.Screens.Play public override bool OnExiting(IScreen next) { cancelLoad(); - contentOut(); + ContentOut(); // If the load sequence was interrupted, the epilepsy warning may already be displayed (or in the process of being displayed). epilepsyWarning?.Hide(); // Ensure the screen doesn't expire until all the outwards fade operations have completed. - this.Delay(content_out_duration).FadeOut(); + this.Delay(CONTENT_OUT_DURATION).FadeOut(); ApplyToBackground(b => b.IgnoreUserSettings.Value = true); @@ -361,15 +363,15 @@ namespace osu.Game.Screens.Play ApplyToBackground(b => b?.FadeColour(Color4.White, 800, Easing.OutQuint)); } - private void contentOut() + protected virtual void ContentOut() { // Ensure the logo is no longer tracking before we scale the content content.StopTracking(); - content.ScaleTo(0.7f, content_out_duration * 2, Easing.OutQuint); - content.FadeOut(content_out_duration, Easing.OutQuint); - lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF, content_out_duration); - highPassFilter.CutoffTo(0, content_out_duration); + content.ScaleTo(0.7f, CONTENT_OUT_DURATION * 2, Easing.OutQuint); + content.FadeOut(CONTENT_OUT_DURATION, Easing.OutQuint); + lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF, CONTENT_OUT_DURATION); + highPassFilter.CutoffTo(0, CONTENT_OUT_DURATION); } private void pushWhenLoaded() @@ -394,9 +396,9 @@ namespace osu.Game.Screens.Play // ensure that once we have reached this "point of no return", readyForPush will be false for all future checks (until a new player instance is prepared). var consumedPlayer = consumePlayer(); - contentOut(); + ContentOut(); - TransformSequence pushSequence = this.Delay(content_out_duration); + TransformSequence pushSequence = this.Delay(CONTENT_OUT_DURATION); // only show if the warning was created (i.e. the beatmap needs it) // and this is not a restart of the map (the warning expires after first load). @@ -418,7 +420,7 @@ namespace osu.Game.Screens.Play else { // This goes hand-in-hand with the restoration of low pass filter in contentOut(). - this.TransformBindableTo(volumeAdjustment, 0, content_out_duration, Easing.OutCubic); + this.TransformBindableTo(volumeAdjustment, 0, CONTENT_OUT_DURATION, Easing.OutCubic); } pushSequence.Schedule(() => From eb8c5292d5db823f1f99947ca936d3e8d3e722f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 13 Nov 2021 13:50:57 +0100 Subject: [PATCH 3/4] Ensure editor background is dimmed after return from gameplay test --- .../Visual/Editing/TestSceneEditorTestGameplay.cs | 7 +++++++ osu.Game/Screens/Edit/Editor.cs | 13 +++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs b/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs index e311c7a7ec..f52a764708 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs @@ -10,10 +10,12 @@ using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Rulesets; using osu.Game.Rulesets.Osu; +using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Edit; using osu.Game.Screens.Edit.Components.Timelines.Summary; using osu.Game.Screens.Edit.GameplayTest; using osu.Game.Tests.Beatmaps.IO; +using osuTK.Graphics; using osuTK.Input; namespace osu.Game.Tests.Visual.Editing @@ -59,6 +61,11 @@ namespace osu.Game.Tests.Visual.Editing AddUntilStep("player pushed", () => (editorPlayer = Stack.CurrentScreen as EditorPlayer) != null); AddStep("exit player", () => editorPlayer.Exit()); AddUntilStep("current screen is editor", () => Stack.CurrentScreen is Editor); + AddUntilStep("background has correct params", () => + { + var background = this.ChildrenOfType().Single(); + return background.Colour == Color4.DarkGray && background.BlurAmount.Value == 0; + }); } [Test] diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 2c758eaf41..d97838e86d 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -487,7 +487,18 @@ namespace osu.Game.Screens.Edit public override void OnEntering(IScreen last) { base.OnEntering(last); + dimBackground(); + resetTrack(true); + } + public override void OnResuming(IScreen last) + { + base.OnResuming(last); + dimBackground(); + } + + private void dimBackground() + { ApplyToBackground(b => { // todo: temporary. we want to be applying dim using the UserDimContainer eventually. @@ -496,8 +507,6 @@ namespace osu.Game.Screens.Edit b.IgnoreUserSettings.Value = true; b.BlurAmount.Value = 0; }); - - resetTrack(true); } public override bool OnExiting(IScreen next) From 5f2a789a6d58b564d79b03aa48475a3c6b686450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 13 Nov 2021 14:01:00 +0100 Subject: [PATCH 4/4] Ensure editor clock is stopped before testing gameplay --- .../Editing/TestSceneEditorTestGameplay.cs | 31 +++++++++++++++++++ osu.Game/Screens/Edit/Editor.cs | 4 +-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs b/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs index f52a764708..1d572772eb 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneEditorTestGameplay.cs @@ -68,6 +68,37 @@ namespace osu.Game.Tests.Visual.Editing }); } + [Test] + public void TestGameplayTestWhenTrackRunning() + { + AddStep("start track", () => EditorClock.Start()); + AddAssert("sample playback enabled", () => !Editor.SamplePlaybackDisabled.Value); + + AddStep("click test gameplay button", () => + { + var button = Editor.ChildrenOfType().Single(); + + InputManager.MoveMouseTo(button); + InputManager.Click(MouseButton.Left); + }); + + EditorPlayer editorPlayer = null; + AddUntilStep("player pushed", () => (editorPlayer = Stack.CurrentScreen as EditorPlayer) != null); + AddAssert("editor track stopped", () => !EditorClock.IsRunning); + AddAssert("sample playback disabled", () => Editor.SamplePlaybackDisabled.Value); + + AddStep("exit player", () => editorPlayer.Exit()); + AddUntilStep("current screen is editor", () => Stack.CurrentScreen is Editor); + AddUntilStep("background has correct params", () => + { + var background = this.ChildrenOfType().Single(); + return background.Colour == Color4.DarkGray && background.BlurAmount.Value == 0; + }); + + AddStep("start track", () => EditorClock.Start()); + AddAssert("sample playback re-enabled", () => !Editor.SamplePlaybackDisabled.Value); + } + [Test] public void TestCancelGameplayTestWithUnsavedChanges() { diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index d97838e86d..ab24391bb4 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -545,9 +545,9 @@ namespace osu.Game.Screens.Edit public override void OnSuspending(IScreen next) { - refetchBeatmap(); - base.OnSuspending(next); + clock.Stop(); + refetchBeatmap(); } private void refetchBeatmap()