Select/deselect first visible mod when GlobalAction.Select is triggered

This commit is contained in:
Cootz 2023-05-21 11:05:01 +03:00
parent 6647d95ea7
commit 67bf1b4dfe
2 changed files with 34 additions and 2 deletions

View File

@ -468,6 +468,24 @@ namespace osu.Game.Tests.Visual.UserInterface
AddAssert("unimplemented mod panel is filtered", () => !getPanelForMod(typeof(TestUnimplementedMod)).IsValid);
}
[Test]
public void TestFirstModSelectDeselect()
{
createScreen();
AddStep("apply search", () => modSelectOverlay.SearchTerm = "HD");
AddStep("press enter", () => InputManager.Key(Key.Enter));
AddAssert("hidden selected", () => getPanelForMod(typeof(OsuModHidden)).Active.Value);
AddStep("press enter again", () => InputManager.Key(Key.Enter));
AddAssert("hidden deselected", () => !getPanelForMod(typeof(OsuModHidden)).Active.Value);
AddStep("clear search", () => modSelectOverlay.SearchTerm = string.Empty);
AddStep("press enter", () => InputManager.Key(Key.Enter));
AddAssert("mod select hidden", () => modSelectOverlay.State.Value == Visibility.Hidden);
}
[Test]
public void TestSearchFocusChange()
{

View File

@ -612,10 +612,24 @@ namespace osu.Game.Overlays.Mods
// This is handled locally here because this overlay is being registered at the game level
// and therefore takes away keyboard focus from the screen stack.
case GlobalAction.ToggleModSelection:
// Pressing toggle should completely hide the overlay in one shot.
hideOverlay(true);
return true;
case GlobalAction.Select:
{
// Pressing toggle or select should completely hide the overlay in one shot.
hideOverlay(true);
// Pressing select should select first filtered mod or completely hide the overlay in one shot if search term is empty.
if (string.IsNullOrEmpty(SearchTerm))
{
hideOverlay(true);
return true;
}
ModState? firstMod = columnFlow.Columns.OfType<ModColumn>().FirstOrDefault(m => m.IsPresent)?.AvailableMods.FirstOrDefault(x => x.IsValid);
if (firstMod is not null)
firstMod.Active.Value = !firstMod.Active.Value;
return true;
}
}