Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable nested input managers on edited screen when skin editor is open #27238

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions osu.Game.Tests/Visual/Navigation/TestSceneSkinEditorNavigation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using osu.Framework.Extensions;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Framework.Threading;
Expand Down Expand Up @@ -301,6 +302,25 @@ public void TestOpenSkinEditorGameplaySceneWhenDifferentRulesetActive(int rulese
switchToGameplayScene();
}

[Test]
public void TestRulesetInputDisabledWhenSkinEditorOpen()
{
advanceToSongSelect();
openSkinEditor();

AddStep("import beatmap", () => BeatmapImportHelper.LoadQuickOszIntoOsu(Game).WaitSafely());
AddUntilStep("wait for selected", () => !Game.Beatmap.IsDefault);

switchToGameplayScene();
AddUntilStep("nested input disabled", () => ((Player)Game.ScreenStack.CurrentScreen).ChildrenOfType<PassThroughInputManager>().All(manager => !manager.UseParentInput));

toggleSkinEditor();
AddUntilStep("nested input enabled", () => ((Player)Game.ScreenStack.CurrentScreen).ChildrenOfType<PassThroughInputManager>().Any(manager => manager.UseParentInput));

toggleSkinEditor();
AddUntilStep("nested input disabled", () => ((Player)Game.ScreenStack.CurrentScreen).ChildrenOfType<PassThroughInputManager>().All(manager => !manager.UseParentInput));
}

private void advanceToSongSelect()
{
PushAndConfirm(() => songSelect = new TestPlaySongSelect());
Expand Down
25 changes: 25 additions & 0 deletions osu.Game/Overlays/SkinEditor/SkinEditorOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics.Containers;
Expand Down Expand Up @@ -66,6 +68,7 @@ public partial class SkinEditorOverlay : OverlayContainer, IKeyBindingHandler<Gl
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;

private OsuScreen? lastTargetScreen;
private InvokeOnDisposal? nestedInputManagerDisable;

private Vector2 lastDrawSize;

Expand Down Expand Up @@ -105,6 +108,7 @@ protected override void PopIn()

if (skinEditor != null)
{
disableNestedInputManagers();
skinEditor.Show();
return;
}
Expand Down Expand Up @@ -132,6 +136,8 @@ protected override void PopOut()
{
skinEditor?.Save(false);
skinEditor?.Hide();
nestedInputManagerDisable?.Dispose();
nestedInputManagerDisable = null;

globallyReenableBeatmapSkinSetting();
}
Expand Down Expand Up @@ -243,6 +249,9 @@ public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
/// </summary>
public void SetTarget(OsuScreen screen)
{
nestedInputManagerDisable?.Dispose();
nestedInputManagerDisable = null;

lastTargetScreen = screen;

if (skinEditor == null) return;
Expand Down Expand Up @@ -271,6 +280,7 @@ private void setTarget(OsuScreen? target)
{
skinEditor.Save(false);
skinEditor.UpdateTargetScreen(target);
disableNestedInputManagers();
}
else
{
Expand All @@ -280,6 +290,21 @@ private void setTarget(OsuScreen? target)
}
}

private void disableNestedInputManagers()
{
if (lastTargetScreen == null)
return;

var nestedInputManagers = lastTargetScreen.ChildrenOfType<PassThroughInputManager>().Where(manager => manager.UseParentInput).ToArray();
foreach (var inputManager in nestedInputManagers)
inputManager.UseParentInput = false;
nestedInputManagerDisable = new InvokeOnDisposal(() =>
{
foreach (var inputManager in nestedInputManagers)
inputManager.UseParentInput = true;
});
}

private readonly Bindable<bool> beatmapSkins = new Bindable<bool>();
private LeasedBindable<bool>? leasedBeatmapSkins;

Expand Down