Skip to content

Commit

Permalink
Merge branch 'master' into adjust-minimum-scale
Browse files Browse the repository at this point in the history
  • Loading branch information
bdach committed Nov 4, 2024
2 parents f616c7b + 1868549 commit d0d28e5
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 13 deletions.
55 changes: 45 additions & 10 deletions osu.Game.Tests/Visual/Settings/TestSceneKeyBindingPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,7 @@ public void TestResettingEntireSectionDoesNotCauseBindingConflicts()
});
AddStep("move mouse to centre", () => InputManager.MoveMouseTo(panel.ScreenSpaceDrawQuad.Centre));
scrollToAndStartBinding("Left (centre)");
AddStep("clear binding", () =>
{
var row = panel.ChildrenOfType<KeyBindingRow>().First(r => r.ChildrenOfType<OsuSpriteText>().Any(s => s.Text.ToString() == "Left (centre)"));
row.ChildrenOfType<KeyBindingRow.ClearButton>().Single().TriggerClick();
});
clearBinding();
scrollToAndStartBinding("Left (rim)");
AddStep("bind M1", () => InputManager.Click(MouseButton.Left));

Expand All @@ -431,6 +427,45 @@ public void TestResettingEntireSectionDoesNotCauseBindingConflicts()
AddUntilStep("conflict popover not shown", () => panel.ChildrenOfType<KeyBindingConflictPopover>().SingleOrDefault(), () => Is.Null);
}

[Test]
public void TestResettingRowCannotConflictWithItself()
{
AddStep("reset taiko section to default", () =>
{
var section = panel.ChildrenOfType<VariantBindingsSubsection>().First(section => new TaikoRuleset().RulesetInfo.Equals(section.Ruleset));
section.ChildrenOfType<ResetButton>().Single().TriggerClick();
});
AddStep("move mouse to centre", () => InputManager.MoveMouseTo(panel.ScreenSpaceDrawQuad.Centre));

scrollToAndStartBinding("Left (centre)");
clearBinding();
scrollToAndStartBinding("Left (centre)", 1);
clearBinding();

scrollToAndStartBinding("Left (centre)");
AddStep("bind F", () => InputManager.Key(Key.F));
scrollToAndStartBinding("Left (centre)", 1);
AddStep("bind M1", () => InputManager.Click(MouseButton.Left));

AddStep("revert row to default", () =>
{
var row = panel.ChildrenOfType<KeyBindingRow>().First(r => r.ChildrenOfType<OsuSpriteText>().Any(s => s.Text.ToString() == "Left (centre)"));
InputManager.MoveMouseTo(row.ChildrenOfType<RevertToDefaultButton<bool>>().Single());
InputManager.Click(MouseButton.Left);
});
AddWaitStep("wait a bit", 3);
AddUntilStep("conflict popover not shown", () => panel.ChildrenOfType<KeyBindingConflictPopover>().SingleOrDefault(), () => Is.Null);
}

private void clearBinding()
{
AddStep("clear binding", () =>
{
var row = panel.ChildrenOfType<KeyBindingRow>().First(r => r.ChildrenOfType<OsuSpriteText>().Any(s => s.Text.ToString() == "Left (centre)"));
row.ChildrenOfType<KeyBindingRow.ClearButton>().Single().TriggerClick();
});
}

private void checkBinding(string name, string keyName)
{
AddAssert($"Check {name} is bound to {keyName}", () =>
Expand All @@ -442,23 +477,23 @@ private void checkBinding(string name, string keyName)
}, () => Is.EqualTo(keyName));
}

private void scrollToAndStartBinding(string name)
private void scrollToAndStartBinding(string name, int bindingIndex = 0)
{
KeyBindingRow.KeyButton firstButton = null;
KeyBindingRow.KeyButton targetButton = null;

AddStep($"Scroll to {name}", () =>
{
var firstRow = panel.ChildrenOfType<KeyBindingRow>().First(r => r.ChildrenOfType<OsuSpriteText>().Any(s => s.Text.ToString() == name));
firstButton = firstRow.ChildrenOfType<KeyBindingRow.KeyButton>().First();
targetButton = firstRow.ChildrenOfType<KeyBindingRow.KeyButton>().ElementAt(bindingIndex);

panel.ChildrenOfType<SettingsPanel.SettingsSectionsContainer>().First().ScrollTo(firstButton);
panel.ChildrenOfType<SettingsPanel.SettingsSectionsContainer>().First().ScrollTo(targetButton);
});

AddWaitStep("wait for scroll", 5);

AddStep("click to bind", () =>
{
InputManager.MoveMouseTo(firstButton);
InputManager.MoveMouseTo(targetButton);
InputManager.Click(MouseButton.Left);
});
}
Expand Down
19 changes: 16 additions & 3 deletions osu.Game/Overlays/Settings/Sections/Input/KeyBindingRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public void RestoreDefaults()
var button = buttons[i++];
button.UpdateKeyCombination(d);

tryPersistKeyBinding(button.KeyBinding.Value, advanceToNextBinding: false);
tryPersistKeyBinding(button.KeyBinding.Value, advanceToNextBinding: false, restoringDefaults: true);
}

isDefault.Value = true;
Expand Down Expand Up @@ -489,12 +489,25 @@ protected override void OnFocusLost(FocusLostEvent e)
base.OnFocusLost(e);
}

private void tryPersistKeyBinding(RealmKeyBinding keyBinding, bool advanceToNextBinding)
private bool isConflictingBinding(RealmKeyBinding first, RealmKeyBinding second, bool restoringDefaults)
{
if (first.ID == second.ID)
return false;

// ignore conflicts with same action bindings during revert. the assumption is that the other binding will be reverted subsequently in the same higher-level operation.
// this happens if the bindings for an action are rebound to the same keys, but the ordering of the bindings itself is different.
if (restoringDefaults && first.ActionInt == second.ActionInt)
return false;

return first.KeyCombination.Equals(second.KeyCombination);
}

private void tryPersistKeyBinding(RealmKeyBinding keyBinding, bool advanceToNextBinding, bool restoringDefaults = false)
{
List<RealmKeyBinding> bindings = GetAllSectionBindings();
RealmKeyBinding? existingBinding = keyBinding.KeyCombination.Equals(new KeyCombination(InputKey.None))
? null
: bindings.FirstOrDefault(other => other.ID != keyBinding.ID && other.KeyCombination.Equals(keyBinding.KeyCombination));
: bindings.FirstOrDefault(other => isConflictingBinding(keyBinding, other, restoringDefaults));

if (existingBinding == null)
{
Expand Down

0 comments on commit d0d28e5

Please sign in to comment.