mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:52:53 +08:00
Merge pull request #5096 from peppy/key-binding-fixes
Add buttons to clear or cancel key binding
This commit is contained in:
commit
8cbea298d8
@ -1,17 +1,30 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
|
using osu.Game.Overlays.KeyBinding;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Settings
|
namespace osu.Game.Tests.Visual.Settings
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestSceneKeyConfiguration : OsuTestScene
|
public class TestSceneKeyBindingPanel : OsuTestScene
|
||||||
{
|
{
|
||||||
private readonly KeyBindingPanel panel;
|
private readonly KeyBindingPanel panel;
|
||||||
|
|
||||||
public TestSceneKeyConfiguration()
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
|
{
|
||||||
|
typeof(KeyBindingRow),
|
||||||
|
typeof(GlobalKeyBindingsSection),
|
||||||
|
typeof(KeyBindingRow),
|
||||||
|
typeof(KeyBindingsSubsection),
|
||||||
|
typeof(RulesetBindingsSection),
|
||||||
|
typeof(VariantBindingsSubsection),
|
||||||
|
};
|
||||||
|
|
||||||
|
public TestSceneKeyBindingPanel()
|
||||||
{
|
{
|
||||||
Child = panel = new KeyBindingPanel();
|
Child = panel = new KeyBindingPanel();
|
||||||
}
|
}
|
@ -13,9 +13,10 @@ using osu.Framework.Graphics.Shapes;
|
|||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Containers;
|
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Input;
|
using osu.Game.Input;
|
||||||
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
|
|
||||||
@ -47,7 +48,7 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
public bool FilteringActive { get; set; }
|
public bool FilteringActive { get; set; }
|
||||||
|
|
||||||
private OsuSpriteText text;
|
private OsuSpriteText text;
|
||||||
private OsuTextFlowContainer pressAKey;
|
private Drawable pressAKey;
|
||||||
|
|
||||||
private FillFlowContainer<KeyButton> buttons;
|
private FillFlowContainer<KeyButton> buttons;
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
Hollow = true,
|
Hollow = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new[]
|
||||||
{
|
{
|
||||||
new Box
|
new Box
|
||||||
{
|
{
|
||||||
@ -99,15 +100,19 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
Anchor = Anchor.TopRight,
|
Anchor = Anchor.TopRight,
|
||||||
Origin = 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.",
|
AutoSizeAxes = Axes.Both,
|
||||||
RelativeSizeAxes = Axes.X,
|
Padding = new MarginPadding(padding) { Top = height + padding * 2 },
|
||||||
AutoSizeAxes = Axes.Y,
|
Anchor = Anchor.TopRight,
|
||||||
Margin = new MarginPadding(padding),
|
Origin = Anchor.TopRight,
|
||||||
Padding = new MarginPadding { Top = height },
|
|
||||||
Alpha = 0,
|
Alpha = 0,
|
||||||
Colour = colours.YellowDark
|
Spacing = new Vector2(5),
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new CancelButton { Action = finalise },
|
||||||
|
new ClearButton { Action = clear },
|
||||||
|
},
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -205,21 +210,6 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
if (!HasFocus)
|
if (!HasFocus)
|
||||||
return false;
|
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));
|
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState));
|
||||||
if (!isModifier(e.Key)) finalise();
|
if (!isModifier(e.Key)) finalise();
|
||||||
|
|
||||||
@ -254,6 +244,12 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void clear()
|
||||||
|
{
|
||||||
|
bindTarget.UpdateKeyCombination(InputKey.None);
|
||||||
|
finalise();
|
||||||
|
}
|
||||||
|
|
||||||
private void finalise()
|
private void finalise()
|
||||||
{
|
{
|
||||||
if (bindTarget != null)
|
if (bindTarget != null)
|
||||||
@ -300,6 +296,41 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
if (bindTarget != null) bindTarget.IsBinding = true;
|
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
|
private class KeyButton : Container
|
||||||
{
|
{
|
||||||
public readonly Framework.Input.Bindings.KeyBinding KeyBinding;
|
public readonly Framework.Input.Bindings.KeyBinding KeyBinding;
|
||||||
|
@ -60,7 +60,7 @@ namespace osu.Game.Overlays.KeyBinding
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour colours)
|
private void load(OsuColour colours)
|
||||||
{
|
{
|
||||||
Text = "Reset";
|
Text = "Reset all bindings in section";
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
Margin = new MarginPadding { Top = 5 };
|
Margin = new MarginPadding { Top = 5 };
|
||||||
Height = 20;
|
Height = 20;
|
||||||
|
Loading…
Reference in New Issue
Block a user