From 90c44cee5475ebfc4702e9c1cf64040aa1d4fe22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Mon, 16 Oct 2023 20:46:20 +0200 Subject: [PATCH] Implement method to deduplicate keybindings --- .../Input/RealmKeyBindingStoreTest.cs | 5 +++-- osu.Game/Input/RealmKeyBindingStore.cs | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/osu.Game.Tests/Input/RealmKeyBindingStoreTest.cs b/osu.Game.Tests/Input/RealmKeyBindingStoreTest.cs index 0e8e73b8b4..fb1e27d9a9 100644 --- a/osu.Game.Tests/Input/RealmKeyBindingStoreTest.cs +++ b/osu.Game.Tests/Input/RealmKeyBindingStoreTest.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; +using System.Linq; using NUnit.Framework; using osu.Framework.Input.Bindings; using osu.Game.Input; @@ -24,7 +25,7 @@ namespace osu.Game.Tests.Input new RealmKeyBinding(GlobalAction.MusicNext, KeyCombination.FromKey(Key.F5)) }; - bool anyCleared = RealmKeyBindingStore.ClearDuplicateBindings(bindings); + bool anyCleared = RealmKeyBindingStore.ClearDuplicateBindings(bindings.AsQueryable()); Assert.Multiple(() => { @@ -58,7 +59,7 @@ namespace osu.Game.Tests.Input new RealmKeyBinding(GlobalAction.TakeScreenshot, KeyCombination.FromKey(Key.PrintScreen)), }; - bool anyCleared = RealmKeyBindingStore.ClearDuplicateBindings(bindings); + bool anyCleared = RealmKeyBindingStore.ClearDuplicateBindings(bindings.AsQueryable()); Assert.Multiple(() => { diff --git a/osu.Game/Input/RealmKeyBindingStore.cs b/osu.Game/Input/RealmKeyBindingStore.cs index 6affdab277..ceef751605 100644 --- a/osu.Game/Input/RealmKeyBindingStore.cs +++ b/osu.Game/Input/RealmKeyBindingStore.cs @@ -139,7 +139,22 @@ namespace osu.Game.Input /// Whether any bindings have been cleared. public static bool ClearDuplicateBindings(IQueryable keyBindings) { - return false; + bool anyRemoved = false; + + var lookup = keyBindings.ToLookup(kb => kb.KeyCombination); + + foreach (var group in lookup) + { + if (group.Count() <= 1) + continue; + + foreach (var binding in group) + binding.KeyCombination = new KeyCombination(InputKey.None); + + anyRemoved = true; + } + + return anyRemoved; } } }