diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/CirclePiece.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/CirclePiece.cs index 3004dafda7..75a0c8e957 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/CirclePiece.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/CirclePiece.cs @@ -49,9 +49,19 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces disc.Texture = textures.Get(@"Play/osu/disc"); } - protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { - return Hit?.Invoke() ?? false; + if (state.Data is OsuAction) + { + switch ((OsuAction)state.Data) + { + case OsuAction.LeftButton: + case OsuAction.RightButton: + return IsHovered && (Hit?.Invoke() ?? false); + } + } + + return false; } } } \ No newline at end of file diff --git a/osu.Game.Rulesets.Osu/OsuInputManager.cs b/osu.Game.Rulesets.Osu/OsuInputManager.cs new file mode 100644 index 0000000000..83304a9615 --- /dev/null +++ b/osu.Game.Rulesets.Osu/OsuInputManager.cs @@ -0,0 +1,50 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Collections.Generic; +using System.Linq; +using osu.Framework.Input; +using osu.Game.Input; +using OpenTK.Input; +using KeyboardState = osu.Framework.Input.KeyboardState; +using MouseState = osu.Framework.Input.MouseState; + +namespace osu.Game.Rulesets.Osu +{ + public class OsuInputManager : ActionMappingInputManager + { + public OsuInputManager(RulesetInfo ruleset) : base(ruleset, concurrencyMode: ConcurrentActionMode.UniqueActions) + { + + } + protected override void TransformState(InputState state) + { + base.TransformState(state); + + var mouse = state.Mouse as MouseState; + var keyboard = state.Keyboard as KeyboardState; + + if (mouse != null && keyboard != null) + { + if (mouse.IsPressed(MouseButton.Left)) + keyboard.Keys = keyboard.Keys.Concat(new[] { Key.LastKey + 1 }); + if (mouse.IsPressed(MouseButton.Right)) + keyboard.Keys = keyboard.Keys.Concat(new[] { Key.LastKey + 2 }); + } + } + + protected override IDictionary CreateDefaultMappings() => new Dictionary + { + { Key.Z, OsuAction.LeftButton }, + { Key.X, OsuAction.RightButton }, + { Key.LastKey + 1, OsuAction.LeftButton }, + { Key.LastKey + 2, OsuAction.RightButton }, + }; + } + + public enum OsuAction + { + LeftButton, + RightButton + } +} diff --git a/osu.Game.Rulesets.Osu/OsuKeyConversionInputManager.cs b/osu.Game.Rulesets.Osu/OsuKeyConversionInputManager.cs deleted file mode 100644 index 10adca4e43..0000000000 --- a/osu.Game.Rulesets.Osu/OsuKeyConversionInputManager.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System.Linq; -using osu.Framework.Input; -using OpenTK.Input; -using KeyboardState = osu.Framework.Input.KeyboardState; -using MouseState = osu.Framework.Input.MouseState; - -namespace osu.Game.Rulesets.Osu -{ - public class OsuKeyConversionInputManager : PassThroughInputManager - { - private bool leftViaKeyboard; - private bool rightViaKeyboard; - - protected override void TransformState(InputState state) - { - base.TransformState(state); - - var mouse = state.Mouse as MouseState; - var keyboard = state.Keyboard as KeyboardState; - - if (keyboard != null) - { - leftViaKeyboard = keyboard.Keys.Contains(Key.Z); - rightViaKeyboard = keyboard.Keys.Contains(Key.X); - } - - if (mouse != null) - { - if (leftViaKeyboard) - mouse.SetPressed(MouseButton.Left, true); - if (rightViaKeyboard) - mouse.SetPressed(MouseButton.Right, true); - } - } - } -} diff --git a/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs b/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs index d029524a32..538b94603c 100644 --- a/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs +++ b/osu.Game.Rulesets.Osu/UI/OsuRulesetContainer.cs @@ -31,7 +31,7 @@ namespace osu.Game.Rulesets.Osu.UI protected override Playfield CreatePlayfield() => new OsuPlayfield(); - protected override PassThroughInputManager CreateActionMappingInputManager() => new OsuKeyConversionInputManager(); + protected override PassThroughInputManager CreateActionMappingInputManager() => new OsuInputManager(Ruleset?.RulesetInfo); protected override DrawableHitObject GetVisualRepresentation(OsuHitObject h) { diff --git a/osu.Game.Rulesets.Osu/osu.Game.Rulesets.Osu.csproj b/osu.Game.Rulesets.Osu/osu.Game.Rulesets.Osu.csproj index b24d5b3a4a..0b960d6607 100644 --- a/osu.Game.Rulesets.Osu/osu.Game.Rulesets.Osu.csproj +++ b/osu.Game.Rulesets.Osu/osu.Game.Rulesets.Osu.csproj @@ -77,7 +77,7 @@ - + diff --git a/osu.Game/Input/ActionMappingInputManager.cs b/osu.Game/Input/ActionMappingInputManager.cs index 8c8d274264..9d83ab8f50 100644 --- a/osu.Game/Input/ActionMappingInputManager.cs +++ b/osu.Game/Input/ActionMappingInputManager.cs @@ -94,7 +94,7 @@ namespace osu.Game.Input private readonly List pressedBindings = new List(); - protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) + protected override void PopulateDataKeyDown(InputState state, KeyDownEventArgs args) { if (!args.Repeat && (concurrencyMode > ConcurrentActionMode.None || pressedBindings.Count == 0)) { @@ -109,11 +109,9 @@ namespace osu.Game.Input pressedBindings.Add(validBinding); } } - - return base.OnKeyDown(state, args); } - protected override bool OnKeyUp(InputState state, KeyUpEventArgs args) + protected override void PopulateDataKeyUp(InputState state, KeyUpEventArgs args) { foreach (var binding in pressedBindings.ToList()) { @@ -127,8 +125,6 @@ namespace osu.Game.Input state.Data = binding.GetAction(); } } - - return base.OnKeyUp(state, args); } } }