Skip to content

Commit

Permalink
Merge pull request #25756 from bdach/mod-select-search-by-default
Browse files Browse the repository at this point in the history
Add setting for mod select search box focusing by default
  • Loading branch information
peppy authored Dec 14, 2023
2 parents 33d3766 + b3a7c7a commit 59355dc
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
32 changes: 26 additions & 6 deletions osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using osu.Framework.Localisation;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Configuration;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osu.Game.Overlays.Mods;
Expand All @@ -38,6 +39,9 @@ public partial class TestSceneModSelectOverlay : OsuManualInputManagerTestScene

private TestModSelectOverlay modSelectOverlay = null!;

[Resolved]
private OsuConfigManager configManager { get; set; } = null!;

[BackgroundDependencyLoader]
private void load()
{
Expand Down Expand Up @@ -566,17 +570,33 @@ void navigateAndClick<T>() where T : Drawable
}

[Test]
public void TestSearchFocusChangeViaKey()
public void TestTextSearchActiveByDefault()
{
configManager.SetValue(OsuSetting.ModSelectTextSearchStartsActive, true);
createScreen();

const Key focus_switch_key = Key.Tab;
AddUntilStep("search text box focused", () => modSelectOverlay.SearchTextBox.HasFocus);

AddStep("press tab", () => InputManager.Key(focus_switch_key));
AddAssert("focused", () => modSelectOverlay.SearchTextBox.HasFocus);
AddStep("press tab", () => InputManager.Key(Key.Tab));
AddAssert("search text box unfocused", () => !modSelectOverlay.SearchTextBox.HasFocus);

AddStep("press tab", () => InputManager.Key(focus_switch_key));
AddAssert("lost focus", () => !modSelectOverlay.SearchTextBox.HasFocus);
AddStep("press tab", () => InputManager.Key(Key.Tab));
AddAssert("search text box focused", () => modSelectOverlay.SearchTextBox.HasFocus);
}

[Test]
public void TestTextSearchNotActiveByDefault()
{
configManager.SetValue(OsuSetting.ModSelectTextSearchStartsActive, false);
createScreen();

AddUntilStep("search text box not focused", () => !modSelectOverlay.SearchTextBox.HasFocus);

AddStep("press tab", () => InputManager.Key(Key.Tab));
AddAssert("search text box focused", () => modSelectOverlay.SearchTextBox.HasFocus);

AddStep("press tab", () => InputManager.Key(Key.Tab));
AddAssert("search text box unfocused", () => !modSelectOverlay.SearchTextBox.HasFocus);
}

[Test]
Expand Down
2 changes: 2 additions & 0 deletions osu.Game/Configuration/OsuConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected override void InitialiseDefaults()

SetDefault(OsuSetting.RandomSelectAlgorithm, RandomSelectAlgorithm.RandomPermutation);
SetDefault(OsuSetting.ModSelectHotkeyStyle, ModSelectHotkeyStyle.Sequential);
SetDefault(OsuSetting.ModSelectTextSearchStartsActive, true);

SetDefault(OsuSetting.ChatDisplayHeight, ChatOverlay.DEFAULT_HEIGHT, 0.2f, 1f);

Expand Down Expand Up @@ -416,5 +417,6 @@ public enum OsuSetting
AutomaticallyDownloadMissingBeatmaps,
EditorShowSpeedChanges,
TouchDisableGameplayTaps,
ModSelectTextSearchStartsActive,
}
}
5 changes: 5 additions & 0 deletions osu.Game/Localisation/UserInterfaceStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public static class UserInterfaceStrings
/// </summary>
public static LocalisableString ModSelectHotkeyStyle => new TranslatableString(getKey(@"mod_select_hotkey_style"), @"Mod select hotkey style");

/// <summary>
/// "Automatically focus search text box in mod select"
/// </summary>
public static LocalisableString ModSelectTextSearchStartsActive => new TranslatableString(getKey(@"mod_select_text_search_starts_active"), @"Automatically focus search text box in mod select");

/// <summary>
/// "no limit"
/// </summary>
Expand Down
8 changes: 7 additions & 1 deletion osu.Game/Overlays/Mods/ModSelectOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ protected virtual IEnumerable<ShearedButton> CreateFooterButtons()
public IEnumerable<ModState> AllAvailableMods => AvailableMods.Value.SelectMany(pair => pair.Value);

private readonly BindableBool customisationVisible = new BindableBool();
private Bindable<bool> textSearchStartsActive = null!;

private ModSettingsArea modSettingsArea = null!;
private ColumnScrollContainer columnScroll = null!;
Expand Down Expand Up @@ -154,7 +155,7 @@ protected ModSelectOverlay(OverlayColourScheme colourScheme = OverlayColourSchem
}

[BackgroundDependencyLoader]
private void load(OsuGameBase game, OsuColour colours, AudioManager audio)
private void load(OsuGameBase game, OsuColour colours, AudioManager audio, OsuConfigManager configManager)
{
Header.Title = ModSelectOverlayStrings.ModSelectTitle;
Header.Description = ModSelectOverlayStrings.ModSelectDescription;
Expand Down Expand Up @@ -282,6 +283,8 @@ private void load(OsuGameBase game, OsuColour colours, AudioManager audio)
}

globalAvailableMods.BindTo(game.AvailableMods);

textSearchStartsActive = configManager.GetBindable<bool>(OsuSetting.ModSelectTextSearchStartsActive);
}

public override void Hide()
Expand Down Expand Up @@ -617,6 +620,9 @@ protected override void PopIn()

nonFilteredColumnCount += 1;
}

if (textSearchStartsActive.Value)
SearchTextBox.TakeFocus();
}

protected override void PopOut()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ private void load(OsuConfigManager config)
ClassicDefault = ModSelectHotkeyStyle.Classic
},
new SettingsCheckbox
{
LabelText = UserInterfaceStrings.ModSelectTextSearchStartsActive,
Current = config.GetBindable<bool>(OsuSetting.ModSelectTextSearchStartsActive),
ClassicDefault = false
},
new SettingsCheckbox
{
LabelText = GameplaySettingsStrings.BackgroundBlur,
Current = config.GetBindable<bool>(OsuSetting.SongSelectBackgroundBlur),
Expand Down

0 comments on commit 59355dc

Please sign in to comment.