1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-24 12:42:57 +08:00

Prevent key bind conflict on reversion

This commit is contained in:
Luke Knight 2024-10-30 02:04:03 -05:00
parent 904b76b9d7
commit b42fa23e42

View File

@ -222,7 +222,7 @@ namespace osu.Game.Overlays.Settings.Sections.Input
var button = buttons[i++]; var button = buttons[i++];
button.UpdateKeyCombination(d); button.UpdateKeyCombination(d);
tryPersistKeyBinding(button.KeyBinding.Value, advanceToNextBinding: false); tryPersistKeyBinding(button.KeyBinding.Value, advanceToNextBinding: false, restoringBinding: true);
} }
isDefault.Value = true; isDefault.Value = true;
@ -489,13 +489,12 @@ namespace osu.Game.Overlays.Settings.Sections.Input
base.OnFocusLost(e); base.OnFocusLost(e);
} }
private void tryPersistKeyBinding(RealmKeyBinding keyBinding, bool advanceToNextBinding) private void tryPersistKeyBinding(RealmKeyBinding keyBinding, bool advanceToNextBinding, bool restoringBinding = false)
{ {
List<RealmKeyBinding> bindings = GetAllSectionBindings(); List<RealmKeyBinding> bindings = GetAllSectionBindings();
RealmKeyBinding? existingBinding = keyBinding.KeyCombination.Equals(new KeyCombination(InputKey.None)) RealmKeyBinding? existingBinding = keyBinding.KeyCombination.Equals(new KeyCombination(InputKey.None))
? null ? null
: bindings.FirstOrDefault(other => other.ID != keyBinding.ID && other.KeyCombination.Equals(keyBinding.KeyCombination)); : bindings.FirstOrDefault(other => other.ID != keyBinding.ID && other.KeyCombination.Equals(keyBinding.KeyCombination) && (!restoringBinding || other.ActionInt != keyBinding.ActionInt));
if (existingBinding == null) if (existingBinding == null)
{ {
realm.Write(r => r.Find<RealmKeyBinding>(keyBinding.ID)!.KeyCombinationString = keyBinding.KeyCombination.ToString()); realm.Write(r => r.Find<RealmKeyBinding>(keyBinding.ID)!.KeyCombinationString = keyBinding.KeyCombination.ToString());