1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 12:32:56 +08:00

Adding a reset button to individual keybinds

This commit is contained in:
Ibby 2021-05-09 15:51:17 +10:00
parent 0e91e6a155
commit 075350e125
2 changed files with 68 additions and 0 deletions

View File

@ -104,6 +104,46 @@ namespace osu.Game.Tests.Visual.Settings
}
}
[Test]
public void TestSingleBindResetButton()
{
KeyBindingRow multiBindingRow = null;
AddStep("click first row with two bindings", () =>
{
multiBindingRow = panel.ChildrenOfType<KeyBindingRow>().First(row => row.Defaults.Count() > 1);
InputManager.MoveMouseTo(multiBindingRow);
InputManager.Click(MouseButton.Left);
});
clickSingleBindResetButton();
AddAssert("first binding cleared", () => multiBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(0).KeyBinding.KeyCombination.Equals(multiBindingRow.Defaults.ElementAt(0)));
AddStep("click second binding", () =>
{
var target = multiBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(1);
InputManager.MoveMouseTo(target);
InputManager.Click(MouseButton.Left);
});
clickSingleBindResetButton();
AddAssert("second binding cleared", () => multiBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(1).KeyBinding.KeyCombination.Equals(multiBindingRow.Defaults.ElementAt(1)));
void clickSingleBindResetButton()
{
AddStep("click reset button for single binding", () =>
{
var clearButton = multiBindingRow.ChildrenOfType<KeyBindingRow.SingleBindResetButton>().Single();
InputManager.MoveMouseTo(clearButton);
InputManager.Click(MouseButton.Left);
});
}
}
[Test]
public void TestClickRowSelectsFirstBinding()
{

View File

@ -109,6 +109,7 @@ namespace osu.Game.Overlays.KeyBinding
Children = new Drawable[]
{
new CancelButton { Action = finalise },
new SingleBindResetButton { Action = singleBindReset },
new ClearButton { Action = clear },
},
}
@ -281,6 +282,15 @@ namespace osu.Game.Overlays.KeyBinding
finalise();
}
private void singleBindReset()
{
if (bindTarget == null)
return;
bindTarget.UpdateKeyCombination(Defaults.ElementAt(buttons.IndexOf(bindTarget)));
finalise();
}
private void finalise()
{
if (bindTarget != null)
@ -339,6 +349,24 @@ namespace osu.Game.Overlays.KeyBinding
}
}
public class SingleBindResetButton : TriangleButton
{
public SingleBindResetButton()
{
Text = "Reset";
Size = new Vector2(80, 20);
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
BackgroundColour = colours.Green;
Triangles.ColourDark = colours.GreenDark;
Triangles.ColourLight = colours.GreenLight;
}
}
public class ClearButton : TriangleButton
{
public ClearButton()