1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Merge pull request #14743 from AbstractQbit/inheritable-allow-track-adjust

Make `IOsuScreen.AllowTrackAdjustments` nullable
This commit is contained in:
Dean Herbert 2021-09-16 16:55:25 +09:00 committed by GitHub
commit d3767ec4e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 101 additions and 25 deletions

View File

@ -5,8 +5,8 @@ using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
using osu.Game.Screens; using osu.Game.Screens;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osuTK.Graphics; using osuTK.Graphics;
@ -18,10 +18,18 @@ namespace osu.Game.Tests.Visual
{ {
private TestOsuScreenStack stack; private TestOsuScreenStack stack;
[SetUpSteps] [Cached]
public void SetUpSteps() private MusicController musicController = new MusicController();
[BackgroundDependencyLoader]
private void load()
{ {
AddStep("Create new screen stack", () => { Child = stack = new TestOsuScreenStack { RelativeSizeAxes = Axes.Both }; }); stack = new TestOsuScreenStack { RelativeSizeAxes = Axes.Both };
Add(musicController);
Add(stack);
LoadComponent(stack);
} }
[Test] [Test]
@ -42,6 +50,44 @@ namespace osu.Game.Tests.Visual
AddAssert("Parallax is off", () => stack.ParallaxAmount == 0); AddAssert("Parallax is off", () => stack.ParallaxAmount == 0);
} }
[Test]
public void AllowTrackAdjustmentsTest()
{
AddStep("push allowing screen", () => stack.Push(loadNewScreen<AllowScreen>()));
AddAssert("allows adjustments 1", () => musicController.AllowTrackAdjustments);
AddStep("push inheriting screen", () => stack.Push(loadNewScreen<InheritScreen>()));
AddAssert("allows adjustments 2", () => musicController.AllowTrackAdjustments);
AddStep("push disallowing screen", () => stack.Push(loadNewScreen<DisallowScreen>()));
AddAssert("disallows adjustments 3", () => !musicController.AllowTrackAdjustments);
AddStep("push inheriting screen", () => stack.Push(loadNewScreen<InheritScreen>()));
AddAssert("disallows adjustments 4", () => !musicController.AllowTrackAdjustments);
AddStep("push inheriting screen", () => stack.Push(loadNewScreen<InheritScreen>()));
AddAssert("disallows adjustments 5", () => !musicController.AllowTrackAdjustments);
AddStep("push allowing screen", () => stack.Push(loadNewScreen<AllowScreen>()));
AddAssert("allows adjustments 6", () => musicController.AllowTrackAdjustments);
// Now start exiting from screens
AddStep("exit screen", () => stack.Exit());
AddAssert("disallows adjustments 7", () => !musicController.AllowTrackAdjustments);
AddStep("exit screen", () => stack.Exit());
AddAssert("disallows adjustments 8", () => !musicController.AllowTrackAdjustments);
AddStep("exit screen", () => stack.Exit());
AddAssert("disallows adjustments 9", () => !musicController.AllowTrackAdjustments);
AddStep("exit screen", () => stack.Exit());
AddAssert("allows adjustments 10", () => musicController.AllowTrackAdjustments);
AddStep("exit screen", () => stack.Exit());
AddAssert("allows adjustments 11", () => musicController.AllowTrackAdjustments);
}
public class TestScreen : ScreenWithBeatmapBackground public class TestScreen : ScreenWithBeatmapBackground
{ {
private readonly string screenText; private readonly string screenText;
@ -78,5 +124,26 @@ namespace osu.Game.Tests.Visual
{ {
public new float ParallaxAmount => base.ParallaxAmount; public new float ParallaxAmount => base.ParallaxAmount;
} }
private class AllowScreen : OsuScreen
{
public override bool? AllowTrackAdjustments => true;
}
public class DisallowScreen : OsuScreen
{
public override bool? AllowTrackAdjustments => false;
}
private class InheritScreen : OsuScreen
{
}
private OsuScreen loadNewScreen<T>() where T : OsuScreen, new()
{
OsuScreen screen = new T();
LoadComponent(screen);
return screen;
}
} }
} }

View File

@ -1075,8 +1075,6 @@ namespace osu.Game
OverlayActivationMode.BindTo(newOsuScreen.OverlayActivationMode); OverlayActivationMode.BindTo(newOsuScreen.OverlayActivationMode);
API.Activity.BindTo(newOsuScreen.Activity); API.Activity.BindTo(newOsuScreen.Activity);
MusicController.AllowTrackAdjustments = newOsuScreen.AllowTrackAdjustments;
if (newOsuScreen.HideOverlaysOnEnter) if (newOsuScreen.HideOverlaysOnEnter)
CloseAllOverlays(); CloseAllOverlays();
else else

View File

@ -24,8 +24,6 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
private OsuDirectorySelector directorySelector; private OsuDirectorySelector directorySelector;
public override bool AllowTrackAdjustments => false;
/// <summary> /// <summary>
/// Text to display in the header to inform the user of what they are selecting. /// Text to display in the header to inform the user of what they are selecting.
/// </summary> /// </summary>

View File

@ -56,7 +56,7 @@ namespace osu.Game.Screens.Edit
public override bool DisallowExternalBeatmapRulesetChanges => true; public override bool DisallowExternalBeatmapRulesetChanges => true;
public override bool AllowTrackAdjustments => false; public override bool? AllowTrackAdjustments => false;
protected bool HasUnsavedChanges => lastSavedHash != changeHandler.CurrentStateHash; protected bool HasUnsavedChanges => lastSavedHash != changeHandler.CurrentStateHash;

View File

@ -59,9 +59,10 @@ namespace osu.Game.Screens
Bindable<RulesetInfo> Ruleset { get; } Bindable<RulesetInfo> Ruleset { get; }
/// <summary> /// <summary>
/// Whether mod track adjustments are allowed to be applied. /// Whether mod track adjustments should be applied on entering this screen.
/// A <see langword="null"/> value means that the parent screen's value of this setting will be used.
/// </summary> /// </summary>
bool AllowTrackAdjustments { get; } bool? AllowTrackAdjustments { get; }
/// <summary> /// <summary>
/// Invoked when the back button has been pressed to close any overlays before exiting this <see cref="IOsuScreen"/>. /// Invoked when the back button has been pressed to close any overlays before exiting this <see cref="IOsuScreen"/>.

View File

@ -23,8 +23,6 @@ namespace osu.Game.Screens.Import
{ {
public override bool HideOverlaysOnEnter => true; public override bool HideOverlaysOnEnter => true;
public override bool AllowTrackAdjustments => false;
private OsuFileSelector fileSelector; private OsuFileSelector fileSelector;
private Container contentContainer; private Container contentContainer;
private TextFlowContainer currentFileText; private TextFlowContainer currentFileText;

View File

@ -36,8 +36,6 @@ namespace osu.Game.Screens.Menu
public override bool AllowExternalScreenChange => true; public override bool AllowExternalScreenChange => true;
public override bool AllowTrackAdjustments => false;
private Screen songSelect; private Screen songSelect;
private MenuSideFlashes sideFlashes; private MenuSideFlashes sideFlashes;

View File

@ -26,7 +26,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate
public override bool DisallowExternalBeatmapRulesetChanges => true; public override bool DisallowExternalBeatmapRulesetChanges => true;
// We are managing our own adjustments. For now, this happens inside the Player instances themselves. // We are managing our own adjustments. For now, this happens inside the Player instances themselves.
public override bool AllowTrackAdjustments => false; public override bool? AllowTrackAdjustments => false;
/// <summary> /// <summary>
/// Whether all spectating players have finished loading. /// Whether all spectating players have finished loading.

View File

@ -24,8 +24,6 @@ namespace osu.Game.Screens.OnlinePlay
[Cached] [Cached]
protected readonly OverlayColourProvider ColourProvider = new OverlayColourProvider(OverlayColourScheme.Plum); protected readonly OverlayColourProvider ColourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);
public override bool AllowTrackAdjustments => false;
public override bool CursorVisible => (screenStack?.CurrentScreen as IOnlinePlaySubScreen)?.CursorVisible ?? true; public override bool CursorVisible => (screenStack?.CurrentScreen as IOnlinePlaySubScreen)?.CursorVisible ?? true;
// this is required due to PlayerLoader eventually being pushed to the main stack // this is required due to PlayerLoader eventually being pushed to the main stack

View File

@ -11,6 +11,8 @@ namespace osu.Game.Screens.OnlinePlay
{ {
public override bool DisallowExternalBeatmapRulesetChanges => false; public override bool DisallowExternalBeatmapRulesetChanges => false;
public override bool? AllowTrackAdjustments => true;
public virtual string ShortTitle => Title; public virtual string ShortTitle => Title;
[Resolved(CanBeNull = true)] [Resolved(CanBeNull = true)]

View File

@ -11,11 +11,11 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Screens.Menu;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Users; using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Menu;
using osu.Game.Users;
namespace osu.Game.Screens namespace osu.Game.Screens
{ {
@ -81,7 +81,10 @@ namespace osu.Game.Screens
public virtual float BackgroundParallaxAmount => 1; public virtual float BackgroundParallaxAmount => 1;
public virtual bool AllowTrackAdjustments => true; [Resolved]
private MusicController musicController { get; set; }
public virtual bool? AllowTrackAdjustments => null;
public Bindable<WorkingBeatmap> Beatmap { get; private set; } public Bindable<WorkingBeatmap> Beatmap { get; private set; }
@ -91,6 +94,8 @@ namespace osu.Game.Screens
private OsuScreenDependencies screenDependencies; private OsuScreenDependencies screenDependencies;
private bool? trackAdjustmentStateAtSuspend;
internal void CreateLeasedDependencies(IReadOnlyDependencyContainer dependencies) => createDependencies(dependencies); internal void CreateLeasedDependencies(IReadOnlyDependencyContainer dependencies) => createDependencies(dependencies);
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
@ -170,8 +175,14 @@ namespace osu.Game.Screens
{ {
if (PlayResumeSound) if (PlayResumeSound)
sampleExit?.Play(); sampleExit?.Play();
applyArrivingDefaults(true); applyArrivingDefaults(true);
// it's feasible to resume to a screen if the target screen never loaded successfully.
// in such a case there's no need to restore this value.
if (trackAdjustmentStateAtSuspend != null)
musicController.AllowTrackAdjustments = trackAdjustmentStateAtSuspend.Value;
base.OnResuming(last); base.OnResuming(last);
} }
@ -179,6 +190,8 @@ namespace osu.Game.Screens
{ {
base.OnSuspending(next); base.OnSuspending(next);
trackAdjustmentStateAtSuspend = musicController.AllowTrackAdjustments;
onSuspendingLogo(); onSuspendingLogo();
} }
@ -186,6 +199,9 @@ namespace osu.Game.Screens
{ {
applyArrivingDefaults(false); applyArrivingDefaults(false);
if (AllowTrackAdjustments != null)
musicController.AllowTrackAdjustments = AllowTrackAdjustments.Value;
if (backgroundStack?.Push(ownedBackground = CreateBackground()) != true) if (backgroundStack?.Push(ownedBackground = CreateBackground()) != true)
{ {
// If the constructed instance was not actually pushed to the background stack, we don't want to track it unnecessarily. // If the constructed instance was not actually pushed to the background stack, we don't want to track it unnecessarily.

View File

@ -56,7 +56,7 @@ namespace osu.Game.Screens.Play
protected override OverlayActivation InitialOverlayActivationMode => OverlayActivation.UserTriggered; protected override OverlayActivation InitialOverlayActivationMode => OverlayActivation.UserTriggered;
// We are managing our own adjustments (see OnEntering/OnExiting). // We are managing our own adjustments (see OnEntering/OnExiting).
public override bool AllowTrackAdjustments => false; public override bool? AllowTrackAdjustments => false;
private readonly IBindable<bool> gameActive = new Bindable<bool>(true); private readonly IBindable<bool> gameActive = new Bindable<bool>(true);

View File

@ -53,6 +53,8 @@ namespace osu.Game.Screens.Select
protected virtual bool DisplayStableImportPrompt => stableImportManager?.SupportsImportFromStable == true; protected virtual bool DisplayStableImportPrompt => stableImportManager?.SupportsImportFromStable == true;
public override bool? AllowTrackAdjustments => true;
/// <summary> /// <summary>
/// Can be null if <see cref="ShowFooter"/> is false. /// Can be null if <see cref="ShowFooter"/> is false.
/// </summary> /// </summary>

View File

@ -16,8 +16,6 @@ namespace osu.Game.Screens
public override bool CursorVisible => false; public override bool CursorVisible => false;
public override bool AllowTrackAdjustments => false;
protected override OverlayActivation InitialOverlayActivationMode => OverlayActivation.Disabled; protected override OverlayActivation InitialOverlayActivationMode => OverlayActivation.Disabled;
} }
} }