Clean up implementation

This commit is contained in:
Dean Herbert
2021-04-05 22:30:51 +09:00
parent 38e95a0e73
commit beebdb0734
5 changed files with 16 additions and 15 deletions

View File

@ -27,7 +27,7 @@ namespace osu.Game.Tests.Visual.Gameplay
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuGameBase game) private void load(OsuGameBase game)
{ {
Child = globalActionContainer = new GlobalActionContainer(game); Child = globalActionContainer = new GlobalActionContainer(game, null);
} }
[SetUp] [SetUp]

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
@ -13,15 +12,17 @@ namespace osu.Game.Input.Bindings
{ {
public class GlobalActionContainer : DatabasedKeyBindingContainer<GlobalAction>, IHandleGlobalKeyboardInput public class GlobalActionContainer : DatabasedKeyBindingContainer<GlobalAction>, IHandleGlobalKeyboardInput
{ {
private readonly GlobalInputManager globalInputManager;
private readonly Drawable handler; private readonly Drawable handler;
public GlobalActionContainer(OsuGameBase game, bool nested = false) public GlobalActionContainer(OsuGameBase game, GlobalInputManager globalInputManager)
: base(matchingMode: KeyCombinationMatchingMode.Modifiers) : base(matchingMode: KeyCombinationMatchingMode.Modifiers)
{ {
this.globalInputManager = globalInputManager;
if (game is IKeyBindingHandler<GlobalAction>) if (game is IKeyBindingHandler<GlobalAction>)
handler = game; handler = game;
GetInputQueue = () => base.KeyBindingInputQueue.ToArray();
} }
public override IEnumerable<IKeyBinding> DefaultKeyBindings => GlobalKeyBindings.Concat(InGameKeyBindings).Concat(AudioControlKeyBindings).Concat(EditorKeyBindings); public override IEnumerable<IKeyBinding> DefaultKeyBindings => GlobalKeyBindings.Concat(InGameKeyBindings).Concat(AudioControlKeyBindings).Concat(EditorKeyBindings);
@ -94,10 +95,15 @@ namespace osu.Game.Input.Bindings
new KeyBinding(InputKey.F3, GlobalAction.MusicPlay) new KeyBinding(InputKey.F3, GlobalAction.MusicPlay)
}; };
public Func<Drawable[]> GetInputQueue { get; set; } protected override IEnumerable<Drawable> KeyBindingInputQueue
{
get
{
var inputQueue = globalInputManager?.NonPositionalInputQueue ?? base.KeyBindingInputQueue;
protected override IEnumerable<Drawable> KeyBindingInputQueue => return handler != null ? inputQueue.Prepend(handler) : inputQueue;
handler == null ? GetInputQueue() : GetInputQueue().Prepend(handler); }
}
} }
public enum GlobalAction public enum GlobalAction

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Linq;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input; using osu.Framework.Input;
@ -23,10 +22,7 @@ namespace osu.Game.Input.Bindings
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}, },
// to avoid positional input being blocked by children, ensure the GlobalActionContainer is above everything. // to avoid positional input being blocked by children, ensure the GlobalActionContainer is above everything.
GlobalBindings = new GlobalActionContainer(game, true) GlobalBindings = new GlobalActionContainer(game, this)
{
GetInputQueue = () => NonPositionalInputQueue.ToArray()
},
}; };
} }
} }

View File

@ -27,7 +27,6 @@ using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Collections; using osu.Game.Collections;

View File

@ -33,7 +33,7 @@ namespace osu.Game.Tests.Visual
InputManager = new ManualInputManager InputManager = new ManualInputManager
{ {
UseParentInput = true, UseParentInput = true,
Child = new GlobalActionContainer(null) Child = new GlobalActionContainer(null, null)
.WithChild((cursorContainer = new MenuCursorContainer { RelativeSizeAxes = Axes.Both }) .WithChild((cursorContainer = new MenuCursorContainer { RelativeSizeAxes = Axes.Both })
.WithChild(content = new OsuTooltipContainer(cursorContainer.Cursor) { RelativeSizeAxes = Axes.Both })) .WithChild(content = new OsuTooltipContainer(cursorContainer.Cursor) { RelativeSizeAxes = Axes.Both }))
}, },