osu/osu.Game/Input/Bindings/GlobalBindingInputManager.cs

69 lines
2.5 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK.Input;
using System.Collections.Generic;
2017-08-10 10:52:45 +00:00
using System.ComponentModel;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Input;
2017-08-11 07:11:46 +00:00
using osu.Framework.Input.Bindings;
2017-08-11 07:11:46 +00:00
namespace osu.Game.Input.Bindings
{
2017-08-11 07:11:46 +00:00
public class GlobalBindingInputManager : DatabasedKeyBindingInputManager<GlobalAction>
{
2017-08-10 10:52:45 +00:00
private readonly Drawable handler;
2017-08-11 07:11:46 +00:00
public GlobalBindingInputManager(OsuGameBase game)
2017-08-10 10:52:45 +00:00
{
2017-08-11 07:11:46 +00:00
if (game is IHandleKeyBindings<GlobalAction>)
2017-08-10 10:52:45 +00:00
handler = game;
}
2017-08-10 08:22:08 +00:00
protected override IDictionary<KeyCombination, GlobalAction> CreateDefaultMappings() => new Dictionary<KeyCombination, GlobalAction>
{
2017-08-10 08:22:08 +00:00
{ Key.F8, GlobalAction.ToggleChat },
{ Key.F9, GlobalAction.ToggleSocial },
{ new[] { Key.LControl, Key.LAlt, Key.R }, GlobalAction.ResetInputSettings },
{ new[] { Key.LControl, Key.T }, GlobalAction.ToggleToolbar },
{ new[] { Key.LControl, Key.O }, GlobalAction.ToggleSettings },
{ new[] { Key.LControl, Key.D }, GlobalAction.ToggleDirect },
};
2017-08-10 10:52:45 +00:00
protected override bool PropagateKeyDown(IEnumerable<Drawable> drawables, InputState state, KeyDownEventArgs args)
{
if (handler != null)
drawables = new[] { handler }.Concat(drawables);
// always handle ourselves before all children.
return base.PropagateKeyDown(drawables, state, args);
}
protected override bool PropagateKeyUp(IEnumerable<Drawable> drawables, InputState state, KeyUpEventArgs args)
{
if (handler != null)
drawables = new[] { handler }.Concat(drawables);
// always handle ourselves before all children.
return base.PropagateKeyUp(drawables, state, args);
}
}
public enum GlobalAction
{
[Description("Toggle chat overlay")]
ToggleChat,
[Description("Toggle social overlay")]
ToggleSocial,
[Description("Reset input settings")]
ResetInputSettings,
[Description("Toggle toolbar")]
ToggleToolbar,
[Description("Toggle settings")]
ToggleSettings,
[Description("Toggle osu!direct")]
ToggleDirect,
}
}