Skip to content

Commit

Permalink
Allow selecting all mods at free mod select using ctrl+a
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed May 14, 2022
1 parent 8a01050 commit b6575c2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
13 changes: 13 additions & 0 deletions osu.Game.Tests/Visual/Multiplayer/TestSceneFreeModSelectOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Mods;
Expand Down Expand Up @@ -55,6 +56,18 @@ public void TestCustomisationNotAvailable()
AddAssert("customisation area not expanded", () => this.ChildrenOfType<ModSettingsArea>().Single().Height == 0);
}

[Test]
public void TestSelectDeselectAllViaKeyboard()
{
createFreeModSelect();

AddStep("press ctrl+a", () => InputManager.Keys(PlatformAction.SelectAll));
AddUntilStep("all mods selected", assertAllAvailableModsSelected);

AddStep("press backspace", () => InputManager.Key(Key.BackSpace));
AddUntilStep("all mods deselected", () => !freeModSelectOverlay.SelectedMods.Value.Any());
}

[Test]
public void TestSelectDeselectAll()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,7 @@ public void TestDeselectAllViaKey()
AddStep("select DT + HD", () => SelectedMods.Value = new Mod[] { new OsuModDoubleTime(), new OsuModHidden() });
AddAssert("DT + HD selected", () => modSelectOverlay.ChildrenOfType<ModPanel>().Count(panel => panel.Active.Value) == 2);

AddStep("press backspace", () =>
{
InputManager.Key(Key.BackSpace);
});
AddStep("press backspace", () => InputManager.Key(Key.BackSpace));
AddUntilStep("all mods deselected", () => !SelectedMods.Value.Any());
}

Expand Down
28 changes: 26 additions & 2 deletions osu.Game/Screens/OnlinePlay/FreeModSelectOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Mods;
using osu.Game.Rulesets.Mods;
Expand All @@ -14,7 +17,7 @@

namespace osu.Game.Screens.OnlinePlay
{
public class FreeModSelectOverlay : ModSelectOverlay
public class FreeModSelectOverlay : ModSelectOverlay, IKeyBindingHandler<PlatformAction>
{
protected override bool ShowTotalMultiplier => false;

Expand All @@ -26,6 +29,8 @@ public class FreeModSelectOverlay : ModSelectOverlay
set => base.IsValidMod = m => m.UserPlayable && value.Invoke(m);
}

private ShearedButton selectAllButton;

public FreeModSelectOverlay()
: base(OverlayColourScheme.Plum)
{
Expand All @@ -35,12 +40,31 @@ public FreeModSelectOverlay()
protected override ModColumn CreateModColumn(ModType modType, Key[] toggleKeys = null) => new ModColumn(modType, true, toggleKeys);

protected override IEnumerable<ShearedButton> CreateFooterButtons() => base.CreateFooterButtons().Prepend(
new ShearedButton(BUTTON_WIDTH)
selectAllButton = new ShearedButton(BUTTON_WIDTH)
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Text = CommonStrings.SelectAll,
Action = SelectAll
});

public bool OnPressed(KeyBindingPressEvent<PlatformAction> e)
{
if (e.Repeat)
return false;

switch (e.Action)
{
case PlatformAction.SelectAll:
selectAllButton.TriggerClick();
return true;
}

return false;
}

public void OnReleased(KeyBindingReleaseEvent<PlatformAction> e)
{
}
}
}

0 comments on commit b6575c2

Please sign in to comment.