mirror of
https://github.com/ppy/osu
synced 2025-01-20 21:10:49 +00:00
Merge pull request #21292 from peppy/fix-binding-two-keys-single-binding
Fix being able to bind two non-modifier keys to the same binding
This commit is contained in:
commit
9d33a6568e
@ -40,6 +40,43 @@ namespace osu.Game.Tests.Visual.Settings
|
|||||||
AddWaitStep("wait for scroll", 5);
|
AddWaitStep("wait for scroll", 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestBindingTwoNonModifiers()
|
||||||
|
{
|
||||||
|
AddStep("press j", () => InputManager.PressKey(Key.J));
|
||||||
|
scrollToAndStartBinding("Increase volume");
|
||||||
|
AddStep("press k", () => InputManager.Key(Key.K));
|
||||||
|
AddStep("release j", () => InputManager.ReleaseKey(Key.J));
|
||||||
|
checkBinding("Increase volume", "K");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestBindingSingleKey()
|
||||||
|
{
|
||||||
|
scrollToAndStartBinding("Increase volume");
|
||||||
|
AddStep("press k", () => InputManager.Key(Key.K));
|
||||||
|
checkBinding("Increase volume", "K");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestBindingSingleModifier()
|
||||||
|
{
|
||||||
|
scrollToAndStartBinding("Increase volume");
|
||||||
|
AddStep("press shift", () => InputManager.PressKey(Key.ShiftLeft));
|
||||||
|
AddStep("release shift", () => InputManager.ReleaseKey(Key.ShiftLeft));
|
||||||
|
checkBinding("Increase volume", "LShift");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestBindingSingleKeyWithModifier()
|
||||||
|
{
|
||||||
|
scrollToAndStartBinding("Increase volume");
|
||||||
|
AddStep("press shift", () => InputManager.PressKey(Key.ShiftLeft));
|
||||||
|
AddStep("press k", () => InputManager.Key(Key.K));
|
||||||
|
AddStep("release shift", () => InputManager.ReleaseKey(Key.ShiftLeft));
|
||||||
|
checkBinding("Increase volume", "LShift-K");
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestBindingMouseWheelToNonGameplay()
|
public void TestBindingMouseWheelToNonGameplay()
|
||||||
{
|
{
|
||||||
@ -169,7 +206,8 @@ namespace osu.Game.Tests.Visual.Settings
|
|||||||
|
|
||||||
AddUntilStep("restore button hidden", () => settingsKeyBindingRow.ChildrenOfType<RestoreDefaultValueButton<bool>>().First().Alpha == 0);
|
AddUntilStep("restore button hidden", () => settingsKeyBindingRow.ChildrenOfType<RestoreDefaultValueButton<bool>>().First().Alpha == 0);
|
||||||
|
|
||||||
AddAssert("binding cleared", () => settingsKeyBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(0).KeyBinding.KeyCombination.Equals(settingsKeyBindingRow.Defaults.ElementAt(0)));
|
AddAssert("binding cleared",
|
||||||
|
() => settingsKeyBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(0).KeyBinding.KeyCombination.Equals(settingsKeyBindingRow.Defaults.ElementAt(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -198,7 +236,8 @@ namespace osu.Game.Tests.Visual.Settings
|
|||||||
|
|
||||||
AddUntilStep("restore button hidden", () => settingsKeyBindingRow.ChildrenOfType<RestoreDefaultValueButton<bool>>().First().Alpha == 0);
|
AddUntilStep("restore button hidden", () => settingsKeyBindingRow.ChildrenOfType<RestoreDefaultValueButton<bool>>().First().Alpha == 0);
|
||||||
|
|
||||||
AddAssert("binding cleared", () => settingsKeyBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(0).KeyBinding.KeyCombination.Equals(settingsKeyBindingRow.Defaults.ElementAt(0)));
|
AddAssert("binding cleared",
|
||||||
|
() => settingsKeyBindingRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(0).KeyBinding.KeyCombination.Equals(settingsKeyBindingRow.Defaults.ElementAt(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -256,8 +295,8 @@ namespace osu.Game.Tests.Visual.Settings
|
|||||||
var firstRow = panel.ChildrenOfType<KeyBindingRow>().First(r => r.ChildrenOfType<OsuSpriteText>().Any(s => s.Text.ToString() == name));
|
var firstRow = panel.ChildrenOfType<KeyBindingRow>().First(r => r.ChildrenOfType<OsuSpriteText>().Any(s => s.Text.ToString() == name));
|
||||||
var firstButton = firstRow.ChildrenOfType<KeyBindingRow.KeyButton>().First();
|
var firstButton = firstRow.ChildrenOfType<KeyBindingRow.KeyButton>().First();
|
||||||
|
|
||||||
return firstButton.Text.Text == keyName;
|
return firstButton.Text.Text.ToString();
|
||||||
});
|
}, () => Is.EqualTo(keyName));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void scrollToAndStartBinding(string name)
|
private void scrollToAndStartBinding(string name)
|
||||||
|
@ -226,7 +226,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState));
|
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState), KeyCombination.FromMouseButton(e.Button));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,7 +252,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
{
|
{
|
||||||
if (bindTarget.IsHovered)
|
if (bindTarget.IsHovered)
|
||||||
{
|
{
|
||||||
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState, e.ScrollDelta));
|
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState, e.ScrollDelta), KeyCombination.FromScrollDelta(e.ScrollDelta).First());
|
||||||
finalise();
|
finalise();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -263,10 +263,10 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
|
|
||||||
protected override bool OnKeyDown(KeyDownEvent e)
|
protected override bool OnKeyDown(KeyDownEvent e)
|
||||||
{
|
{
|
||||||
if (!HasFocus)
|
if (!HasFocus || e.Repeat)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState));
|
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState), KeyCombination.FromKey(e.Key));
|
||||||
if (!isModifier(e.Key)) finalise();
|
if (!isModifier(e.Key)) finalise();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -288,7 +288,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
if (!HasFocus)
|
if (!HasFocus)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState));
|
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState), KeyCombination.FromJoystickButton(e.Button));
|
||||||
finalise();
|
finalise();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -310,7 +310,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
if (!HasFocus)
|
if (!HasFocus)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState));
|
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState), KeyCombination.FromMidiKey(e.Key));
|
||||||
finalise();
|
finalise();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -332,7 +332,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
if (!HasFocus)
|
if (!HasFocus)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState));
|
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState), KeyCombination.FromTabletAuxiliaryButton(e.Button));
|
||||||
finalise();
|
finalise();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -354,7 +354,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
if (!HasFocus)
|
if (!HasFocus)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState));
|
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState), KeyCombination.FromTabletPenButton(e.Button));
|
||||||
finalise();
|
finalise();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -563,6 +563,14 @@ namespace osu.Game.Overlays.Settings.Sections.Input
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Update from a key combination, only allowing a single non-modifier key to be specified.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fullState">A <see cref="KeyCombination"/> generated from the full input state.</param>
|
||||||
|
/// <param name="triggerKey">The key which triggered this update, and should be used as the binding.</param>
|
||||||
|
public void UpdateKeyCombination(KeyCombination fullState, InputKey triggerKey) =>
|
||||||
|
UpdateKeyCombination(new KeyCombination(fullState.Keys.Where(KeyCombination.IsModifierKey).Append(triggerKey)));
|
||||||
|
|
||||||
public void UpdateKeyCombination(KeyCombination newCombination)
|
public void UpdateKeyCombination(KeyCombination newCombination)
|
||||||
{
|
{
|
||||||
if (KeyBinding.RulesetName != null && !RealmKeyBindingStore.CheckValidForGameplay(newCombination))
|
if (KeyBinding.RulesetName != null && !RealmKeyBindingStore.CheckValidForGameplay(newCombination))
|
||||||
|
Loading…
Reference in New Issue
Block a user