mirror of
https://github.com/ppy/osu.git
synced 2025-02-13 15:53:51 +08:00
Remove necessity for nested PassThroughInputManger
This commit is contained in:
parent
0a4b621739
commit
8aff53172d
@ -27,7 +27,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuGameBase game)
|
||||
{
|
||||
Child = globalActionContainer = new GlobalActionContainer(game, null);
|
||||
Child = globalActionContainer = new GlobalActionContainer(game);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
|
@ -4,7 +4,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Input.Bindings;
|
||||
@ -13,20 +12,23 @@ namespace osu.Game.Input.Bindings
|
||||
{
|
||||
public class GlobalActionContainer : DatabasedKeyBindingContainer<GlobalAction>, IHandleGlobalKeyboardInput
|
||||
{
|
||||
[CanBeNull]
|
||||
private readonly GlobalInputManager globalInputManager;
|
||||
|
||||
private readonly Drawable handler;
|
||||
private InputManager parentInputManager;
|
||||
|
||||
public GlobalActionContainer(OsuGameBase game, [CanBeNull] GlobalInputManager globalInputManager)
|
||||
public GlobalActionContainer(OsuGameBase game)
|
||||
: base(matchingMode: KeyCombinationMatchingMode.Modifiers)
|
||||
{
|
||||
this.globalInputManager = globalInputManager;
|
||||
|
||||
if (game is IKeyBindingHandler<GlobalAction>)
|
||||
handler = game;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
parentInputManager = GetContainingInputManager();
|
||||
}
|
||||
|
||||
public override IEnumerable<IKeyBinding> DefaultKeyBindings => GlobalKeyBindings
|
||||
.Concat(EditorKeyBindings)
|
||||
.Concat(InGameKeyBindings)
|
||||
@ -113,7 +115,12 @@ namespace osu.Game.Input.Bindings
|
||||
{
|
||||
get
|
||||
{
|
||||
var inputQueue = globalInputManager?.NonPositionalInputQueue ?? base.KeyBindingInputQueue;
|
||||
// To ensure the global actions are handled with priority, this GlobalActionContainer is actually placed after game content.
|
||||
// It does not contain children as expected, so we need to forward the NonPositionalInputQueue from the parent input manager to correctly
|
||||
// allow the whole game to handle these actions.
|
||||
|
||||
// An eventual solution to this hack is to create localised action containers for individual components like SongSelect, but this will take some rearranging.
|
||||
var inputQueue = parentInputManager?.NonPositionalInputQueue ?? base.KeyBindingInputQueue;
|
||||
|
||||
return handler != null ? inputQueue.Prepend(handler) : inputQueue;
|
||||
}
|
||||
|
@ -1,29 +0,0 @@
|
||||
// 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.
|
||||
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input;
|
||||
|
||||
namespace osu.Game.Input.Bindings
|
||||
{
|
||||
public class GlobalInputManager : PassThroughInputManager
|
||||
{
|
||||
public readonly GlobalActionContainer GlobalBindings;
|
||||
|
||||
protected override Container<Drawable> Content { get; }
|
||||
|
||||
public GlobalInputManager(OsuGameBase game)
|
||||
{
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
Content = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
// to avoid positional input being blocked by children, ensure the GlobalActionContainer is above everything.
|
||||
GlobalBindings = new GlobalActionContainer(game, this)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -308,18 +308,21 @@ namespace osu.Game
|
||||
|
||||
AddInternal(RulesetConfigCache);
|
||||
|
||||
var globalInput = new GlobalInputManager(this)
|
||||
GlobalActionContainer globalBindings;
|
||||
|
||||
var mainContent = new Drawable[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = MenuCursorContainer = new MenuCursorContainer { RelativeSizeAxes = Axes.Both }
|
||||
MenuCursorContainer = new MenuCursorContainer { RelativeSizeAxes = Axes.Both },
|
||||
// to avoid positional input being blocked by children, ensure the GlobalActionContainer is above everything.
|
||||
globalBindings = new GlobalActionContainer(this)
|
||||
};
|
||||
|
||||
MenuCursorContainer.Child = content = new OsuTooltipContainer(MenuCursorContainer.Cursor) { RelativeSizeAxes = Axes.Both };
|
||||
|
||||
base.Content.Add(CreateScalingContainer().WithChild(globalInput));
|
||||
base.Content.Add(CreateScalingContainer().WithChildren(mainContent));
|
||||
|
||||
KeyBindingStore.Register(globalInput.GlobalBindings);
|
||||
dependencies.Cache(globalInput.GlobalBindings);
|
||||
KeyBindingStore.Register(globalBindings);
|
||||
dependencies.Cache(globalBindings);
|
||||
|
||||
PreviewTrackManager previewTrackManager;
|
||||
dependencies.Cache(previewTrackManager = new PreviewTrackManager());
|
||||
|
@ -40,7 +40,7 @@ namespace osu.Game.Tests.Visual
|
||||
|
||||
if (CreateNestedActionContainer)
|
||||
{
|
||||
mainContent = new GlobalActionContainer(null, null).WithChild(mainContent);
|
||||
mainContent = new GlobalActionContainer(null).WithChild(mainContent);
|
||||
}
|
||||
|
||||
base.Content.AddRange(new Drawable[]
|
||||
|
Loading…
Reference in New Issue
Block a user