1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 05:27:40 +08:00
osu-lazer/osu.Game/Input/GlobalActionMappingInputManager.cs

68 lines
2.4 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 18:52:45 +08:00
using System.ComponentModel;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Input;
2017-08-09 16:21:44 +08:00
namespace osu.Game.Input
{
2017-08-10 16:22:08 +08:00
public class GlobalActionMappingInputManager : ActionMappingInputManager<GlobalAction>
{
2017-08-10 18:52:45 +08:00
private readonly Drawable handler;
public GlobalActionMappingInputManager(OsuGameBase game)
{
if (game is IHandleActions<GlobalAction>)
handler = game;
}
2017-08-10 16:22:08 +08:00
protected override IDictionary<KeyCombination, GlobalAction> CreateDefaultMappings() => new Dictionary<KeyCombination, GlobalAction>
{
2017-08-10 16:22:08 +08: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 18:52:45 +08: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,
}
}