diff --git a/osu.Game.Tests/Visual/Settings/TestSceneKeyConfiguration.cs b/osu.Game.Tests/Visual/Settings/TestSceneKeyBindingPanel.cs similarity index 50% rename from osu.Game.Tests/Visual/Settings/TestSceneKeyConfiguration.cs rename to osu.Game.Tests/Visual/Settings/TestSceneKeyBindingPanel.cs index d06d82ddb5..426ff988c4 100644 --- a/osu.Game.Tests/Visual/Settings/TestSceneKeyConfiguration.cs +++ b/osu.Game.Tests/Visual/Settings/TestSceneKeyBindingPanel.cs @@ -1,17 +1,30 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; +using System.Collections.Generic; using NUnit.Framework; using osu.Game.Overlays; +using osu.Game.Overlays.KeyBinding; namespace osu.Game.Tests.Visual.Settings { [TestFixture] - public class TestSceneKeyConfiguration : OsuTestScene + public class TestSceneKeyBindingPanel : OsuTestScene { private readonly KeyBindingPanel panel; - public TestSceneKeyConfiguration() + public override IReadOnlyList RequiredTypes => new[] + { + typeof(KeyBindingRow), + typeof(GlobalKeyBindingsSection), + typeof(KeyBindingRow), + typeof(KeyBindingsSubsection), + typeof(RulesetBindingsSection), + typeof(VariantBindingsSubsection), + }; + + public TestSceneKeyBindingPanel() { Child = panel = new KeyBindingPanel(); } diff --git a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs index 9a707adaea..8317951c8a 100644 --- a/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingRow.cs @@ -13,9 +13,10 @@ using osu.Framework.Input.Bindings; using osu.Framework.Input.Events; using osu.Game.Graphics; -using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; +using osu.Game.Graphics.UserInterface; using osu.Game.Input; +using osuTK; using osuTK.Graphics; using osuTK.Input; @@ -47,7 +48,7 @@ public bool MatchingFilter public bool FilteringActive { get; set; } private OsuSpriteText text; - private OsuTextFlowContainer pressAKey; + private Drawable pressAKey; private FillFlowContainer buttons; @@ -80,7 +81,7 @@ private void load(OsuColour colours, KeyBindingStore store) Hollow = true, }; - Children = new Drawable[] + Children = new[] { new Box { @@ -99,15 +100,19 @@ private void load(OsuColour colours, KeyBindingStore store) Anchor = Anchor.TopRight, Origin = Anchor.TopRight }, - pressAKey = new OsuTextFlowContainer + pressAKey = new FillFlowContainer { - Text = "Press a key to change binding, Shift+Delete to delete, Escape to cancel.", - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Margin = new MarginPadding(padding), - Padding = new MarginPadding { Top = height }, + AutoSizeAxes = Axes.Both, + Padding = new MarginPadding(padding) { Top = height + padding * 2 }, + Anchor = Anchor.TopRight, + Origin = Anchor.TopRight, Alpha = 0, - Colour = colours.YellowDark + Spacing = new Vector2(5), + Children = new Drawable[] + { + new CancelButton { Action = finalise }, + new ClearButton { Action = clear }, + }, } }; @@ -205,21 +210,6 @@ protected override bool OnKeyDown(KeyDownEvent e) if (!HasFocus) return false; - switch (e.Key) - { - case Key.Delete: - { - if (e.ShiftPressed) - { - bindTarget.UpdateKeyCombination(InputKey.None); - finalise(); - return true; - } - - break; - } - } - bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState)); if (!isModifier(e.Key)) finalise(); @@ -254,6 +244,12 @@ protected override bool OnJoystickRelease(JoystickReleaseEvent e) return true; } + private void clear() + { + bindTarget.UpdateKeyCombination(InputKey.None); + finalise(); + } + private void finalise() { if (bindTarget != null) @@ -300,6 +296,41 @@ private void updateBindTarget() if (bindTarget != null) bindTarget.IsBinding = true; } + private class CancelButton : TriangleButton + { + public CancelButton() + { + Text = "Cancel"; + Size = new Vector2(80, 20); + } + } + + private class ClearButton : TriangleButton + { + public ClearButton() + { + Text = "Clear"; + Size = new Vector2(80, 20); + } + + protected override bool OnMouseUp(MouseUpEvent e) + { + base.OnMouseUp(e); + + // without this, the mouse up triggers a finalise (and deselection) of the current binding target. + return true; + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + BackgroundColour = colours.Pink; + + Triangles.ColourDark = colours.PinkDark; + Triangles.ColourLight = colours.PinkLight; + } + } + private class KeyButton : Container { public readonly Framework.Input.Bindings.KeyBinding KeyBinding; diff --git a/osu.Game/Overlays/KeyBinding/KeyBindingsSubsection.cs b/osu.Game/Overlays/KeyBinding/KeyBindingsSubsection.cs index 08288516e3..d784b7aec9 100644 --- a/osu.Game/Overlays/KeyBinding/KeyBindingsSubsection.cs +++ b/osu.Game/Overlays/KeyBinding/KeyBindingsSubsection.cs @@ -60,7 +60,7 @@ public class ResetButton : TriangleButton [BackgroundDependencyLoader] private void load(OsuColour colours) { - Text = "Reset"; + Text = "Reset all bindings in section"; RelativeSizeAxes = Axes.X; Margin = new MarginPadding { Top = 5 }; Height = 20;