diff --git a/osu-framework b/osu-framework index e52af1e5ad..4834d27107 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit e52af1e5ada07468512e19c86b6dcd5a23fe3707 +Subproject commit 4834d27107198b9dc2f0e073be484cf0b92e0416 diff --git a/osu.Game.Modes.Osu/OsuKeyConversionInputManager.cs b/osu.Game.Modes.Osu/OsuKeyConversionInputManager.cs new file mode 100644 index 0000000000..986240b37f --- /dev/null +++ b/osu.Game.Modes.Osu/OsuKeyConversionInputManager.cs @@ -0,0 +1,56 @@ +// 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.Allocation; +using osu.Framework.Configuration; +using osu.Framework.Input; +using osu.Game.Configuration; +using osu.Game.Screens.Play; +using OpenTK.Input; +using KeyboardState = osu.Framework.Input.KeyboardState; +using MouseState = osu.Framework.Input.MouseState; + +namespace osu.Game.Modes.Osu +{ + public class OsuKeyConversionInputManager : KeyConversionInputManager + { + private bool leftViaKeyboard; + private bool rightViaKeyboard; + private Bindable mouseDisabled; + + [BackgroundDependencyLoader] + private void load(OsuConfigManager config) + { + mouseDisabled = config.GetBindable(OsuConfig.MouseDisableButtons); + } + + 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 (mouseDisabled.Value) + { + mouse.PressedButtons.Remove(MouseButton.Left); + mouse.PressedButtons.Remove(MouseButton.Right); + } + + if (leftViaKeyboard) + mouse.PressedButtons.Add(MouseButton.Left); + if (rightViaKeyboard) + mouse.PressedButtons.Add(MouseButton.Right); + } + } + } +} diff --git a/osu.Game.Modes.Osu/UI/OsuHitRenderer.cs b/osu.Game.Modes.Osu/UI/OsuHitRenderer.cs index a3b05fe009..448b41e7c3 100644 --- a/osu.Game.Modes.Osu/UI/OsuHitRenderer.cs +++ b/osu.Game.Modes.Osu/UI/OsuHitRenderer.cs @@ -7,6 +7,7 @@ using osu.Game.Modes.Osu.Beatmaps; using osu.Game.Modes.Osu.Objects; using osu.Game.Modes.Osu.Objects.Drawables; using osu.Game.Modes.UI; +using osu.Game.Screens.Play; namespace osu.Game.Modes.Osu.UI { @@ -23,6 +24,8 @@ namespace osu.Game.Modes.Osu.UI protected override Playfield CreatePlayfield() => new OsuPlayfield(); + protected override KeyConversionInputManager CreateKeyConversionInputManager() => new OsuKeyConversionInputManager(); + protected override DrawableHitObject GetVisualRepresentation(OsuHitObject h) { var circle = h as HitCircle; diff --git a/osu.Game.Modes.Osu/osu.Game.Modes.Osu.csproj b/osu.Game.Modes.Osu/osu.Game.Modes.Osu.csproj index e2c1a71cb9..38d392dc25 100644 --- a/osu.Game.Modes.Osu/osu.Game.Modes.Osu.csproj +++ b/osu.Game.Modes.Osu/osu.Game.Modes.Osu.csproj @@ -74,6 +74,7 @@ + diff --git a/osu.Game/Modes/UI/HitRenderer.cs b/osu.Game/Modes/UI/HitRenderer.cs index 7c7349b929..88f1f68709 100644 --- a/osu.Game/Modes/UI/HitRenderer.cs +++ b/osu.Game/Modes/UI/HitRenderer.cs @@ -23,6 +23,14 @@ namespace osu.Game.Modes.UI internal readonly PlayerInputManager InputManager = new PlayerInputManager(); + protected readonly KeyConversionInputManager KeyConversionInputManager; + + protected HitRenderer() + { + KeyConversionInputManager = CreateKeyConversionInputManager(); + KeyConversionInputManager.RelativeSizeAxes = Axes.Both; + } + /// /// Whether all the HitObjects have been judged. /// @@ -35,6 +43,8 @@ namespace osu.Game.Modes.UI if (AllObjectsJudged) OnAllJudged?.Invoke(); } + + protected virtual KeyConversionInputManager CreateKeyConversionInputManager() => new KeyConversionInputManager(); } public abstract class HitRenderer : HitRenderer @@ -42,8 +52,6 @@ namespace osu.Game.Modes.UI { public Beatmap Beatmap; - public IEnumerable DrawableObjects => Playfield.HitObjects.Children; - protected override Container Content => content; protected override bool AllObjectsJudged => Playfield.HitObjects.Children.All(h => h.Judgement.Result.HasValue); @@ -64,13 +72,12 @@ namespace osu.Game.Modes.UI RelativeSizeAxes = Axes.Both; + KeyConversionInputManager.Add(Playfield = CreatePlayfield()); + InputManager.Add(content = new Container { RelativeSizeAxes = Axes.Both, - Children = new[] - { - Playfield = CreatePlayfield(), - } + Children = new[] { KeyConversionInputManager } }); AddInternal(InputManager); diff --git a/osu.Game/Screens/Play/KeyConversionInputManager.cs b/osu.Game/Screens/Play/KeyConversionInputManager.cs new file mode 100644 index 0000000000..f3ca764bd7 --- /dev/null +++ b/osu.Game/Screens/Play/KeyConversionInputManager.cs @@ -0,0 +1,16 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Input; + +namespace osu.Game.Screens.Play +{ + /// + /// An InputManager primarily used to map keys to new functions. + /// By default this does nothing; override TransformState to make alterations. + /// + public class KeyConversionInputManager : PassThroughInputManager + { + + } +} \ No newline at end of file diff --git a/osu.Game/Screens/Play/KeyCounterMouse.cs b/osu.Game/Screens/Play/KeyCounterMouse.cs index 037d890a9e..425bcffee5 100644 --- a/osu.Game/Screens/Play/KeyCounterMouse.cs +++ b/osu.Game/Screens/Play/KeyCounterMouse.cs @@ -10,11 +10,25 @@ namespace osu.Game.Screens.Play public class KeyCounterMouse : KeyCounter { public MouseButton Button { get; } - public KeyCounterMouse(MouseButton button) : base(button.ToString()) + + public KeyCounterMouse(MouseButton button) : base(getStringRepresentation(button)) { Button = button; } + private static string getStringRepresentation(MouseButton button) + { + switch (button) + { + default: + return button.ToString(); + case MouseButton.Left: + return @"M1"; + case MouseButton.Right: + return @"M2"; + } + } + public override bool Contains(Vector2 screenSpacePos) => true; protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) diff --git a/osu.Game/Screens/Play/PlayerInputManager.cs b/osu.Game/Screens/Play/PlayerInputManager.cs index 3eab30c50d..32d20118af 100644 --- a/osu.Game/Screens/Play/PlayerInputManager.cs +++ b/osu.Game/Screens/Play/PlayerInputManager.cs @@ -1,25 +1,14 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.Allocation; -using osu.Framework.Configuration; using osu.Framework.Input; -using osu.Game.Configuration; -using System.Linq; using osu.Framework.Timing; using osu.Game.Input.Handlers; -using OpenTK.Input; -using KeyboardState = osu.Framework.Input.KeyboardState; -using MouseState = osu.Framework.Input.MouseState; namespace osu.Game.Screens.Play { public class PlayerInputManager : PassThroughInputManager { - private bool leftViaKeyboard; - private bool rightViaKeyboard; - private Bindable mouseDisabled; - private ManualClock clock = new ManualClock(); private IFrameBasedClock parentClock; @@ -47,40 +36,6 @@ namespace osu.Game.Screens.Play Clock = new FramedClock(clock); } - [BackgroundDependencyLoader] - private void load(OsuConfigManager config) - { - mouseDisabled = config.GetBindable(OsuConfig.MouseDisableButtons); - } - - 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 (mouseDisabled.Value) - { - mouse.PressedButtons.Remove(MouseButton.Left); - mouse.PressedButtons.Remove(MouseButton.Right); - } - - if (leftViaKeyboard) - mouse.PressedButtons.Add(MouseButton.Left); - if (rightViaKeyboard) - mouse.PressedButtons.Add(MouseButton.Right); - } - } - protected override void Update() { base.Update(); diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 92ac77091c..7b35374669 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -181,6 +181,7 @@ +