mirror of
https://github.com/ppy/osu
synced 2025-03-04 18:40:24 +00:00
Ensure GlobalActions are handled before anything else game-wide
This commit is contained in:
parent
f40cf499bc
commit
05961e98d5
@ -1,6 +1,7 @@
|
|||||||
// 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;
|
||||||
@ -14,11 +15,13 @@ namespace osu.Game.Input.Bindings
|
|||||||
{
|
{
|
||||||
private readonly Drawable handler;
|
private readonly Drawable handler;
|
||||||
|
|
||||||
public GlobalActionContainer(OsuGameBase game)
|
public GlobalActionContainer(OsuGameBase game, bool nested = false)
|
||||||
: base(matchingMode: KeyCombinationMatchingMode.Modifiers)
|
: base(matchingMode: KeyCombinationMatchingMode.Modifiers)
|
||||||
{
|
{
|
||||||
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);
|
||||||
@ -91,8 +94,10 @@ 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 =>
|
protected override IEnumerable<Drawable> KeyBindingInputQueue =>
|
||||||
handler == null ? base.KeyBindingInputQueue : base.KeyBindingInputQueue.Prepend(handler);
|
handler == null ? GetInputQueue() : GetInputQueue().Prepend(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum GlobalAction
|
public enum GlobalAction
|
||||||
|
33
osu.Game/Input/Bindings/GlobalInputManager.cs
Normal file
33
osu.Game/Input/Bindings/GlobalInputManager.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// 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 System.Linq;
|
||||||
|
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, true)
|
||||||
|
{
|
||||||
|
GetInputQueue = () => NonPositionalInputQueue.ToArray()
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -310,9 +310,9 @@ namespace osu.Game
|
|||||||
|
|
||||||
MenuCursorContainer = new MenuCursorContainer { RelativeSizeAxes = Axes.Both };
|
MenuCursorContainer = new MenuCursorContainer { RelativeSizeAxes = Axes.Both };
|
||||||
|
|
||||||
GlobalActionContainer globalBindings;
|
GlobalInputManager globalInput;
|
||||||
|
|
||||||
MenuCursorContainer.Child = globalBindings = new GlobalActionContainer(this)
|
MenuCursorContainer.Child = globalInput = new GlobalInputManager(this)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Child = content = new OsuTooltipContainer(MenuCursorContainer.Cursor) { RelativeSizeAxes = Axes.Both }
|
Child = content = new OsuTooltipContainer(MenuCursorContainer.Cursor) { RelativeSizeAxes = Axes.Both }
|
||||||
@ -320,8 +320,8 @@ namespace osu.Game
|
|||||||
|
|
||||||
base.Content.Add(CreateScalingContainer().WithChild(MenuCursorContainer));
|
base.Content.Add(CreateScalingContainer().WithChild(MenuCursorContainer));
|
||||||
|
|
||||||
KeyBindingStore.Register(globalBindings);
|
KeyBindingStore.Register(globalInput.GlobalBindings);
|
||||||
dependencies.Cache(globalBindings);
|
dependencies.Cache(globalInput.GlobalBindings);
|
||||||
|
|
||||||
PreviewTrackManager previewTrackManager;
|
PreviewTrackManager previewTrackManager;
|
||||||
dependencies.Cache(previewTrackManager = new PreviewTrackManager());
|
dependencies.Cache(previewTrackManager = new PreviewTrackManager());
|
||||||
|
Loading…
Reference in New Issue
Block a user