1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 20:05:29 +08:00

Block deselect all short key when using the search box

This commit is contained in:
Cootz 2023-05-09 16:14:42 +03:00
parent 4c3af6ecfe
commit 2467813d81
4 changed files with 39 additions and 11 deletions

View File

@ -481,6 +481,26 @@ namespace osu.Game.Tests.Visual.UserInterface
AddUntilStep("all mods deselected", () => !SelectedMods.Value.Any());
}
[Test]
public void TestDeselectAllViaKey_WithSearchApplied()
{
createScreen();
changeRuleset(0);
AddStep("select DT + HD", () => SelectedMods.Value = new Mod[] { new OsuModDoubleTime(), new OsuModHidden() });
AddStep("focus on search", () => modSelectOverlay.SearchTextBox.TakeFocus());
AddStep("apply search", () => modSelectOverlay.SearchTerm = "Easy");
AddAssert("DT + HD selected and hidden", () => modSelectOverlay.ChildrenOfType<ModPanel>().Count(panel => !panel.IsValid && panel.Active.Value) == 2);
AddStep("press backspace", () => InputManager.Key(Key.BackSpace));
AddAssert("DT + HD still selected", () => modSelectOverlay.ChildrenOfType<ModPanel>().Count(panel => panel.Active.Value) == 2);
AddAssert("search term changed", () => modSelectOverlay.SearchTerm == "Eas");
AddStep("kill focus", () => modSelectOverlay.SearchTextBox.KillFocus());
AddStep("press backspace", () => InputManager.Key(Key.BackSpace));
AddUntilStep("all mods deselected", () => !SelectedMods.Value.Any());
}
[Test]
public void TestDeselectAllViaButton()
{

View File

@ -37,6 +37,8 @@ namespace osu.Game.Graphics.UserInterface
set => textBox.HoldFocus = value;
}
public new bool HasFocus => textBox.HasFocus;
public void TakeFocus() => textBox.TakeFocus();
public void KillFocus() => textBox.KillFocus();

View File

@ -18,6 +18,7 @@ namespace osu.Game.Overlays.Mods
public partial class DeselectAllModsButton : ShearedButton, IKeyBindingHandler<GlobalAction>
{
private readonly Bindable<IReadOnlyList<Mod>> selectedMods = new Bindable<IReadOnlyList<Mod>>();
private readonly ShearedSearchTextBox searchTextBox;
public DeselectAllModsButton(ModSelectOverlay modSelectOverlay)
: base(ModSelectOverlay.BUTTON_WIDTH)
@ -25,6 +26,8 @@ namespace osu.Game.Overlays.Mods
Text = CommonStrings.DeselectAll;
Action = modSelectOverlay.DeselectAll;
searchTextBox = modSelectOverlay.SearchTextBox;
selectedMods.BindTo(modSelectOverlay.SelectedMods);
}
@ -40,9 +43,8 @@ namespace osu.Game.Overlays.Mods
Enabled.Value = selectedMods.Value.Any();
}
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (e.Repeat || e.Action != GlobalAction.DeselectAllMods)
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e) {
if (e.Repeat || e.Action != GlobalAction.DeselectAllMods || searchTextBox.HasFocus)
return false;
TriggerClick();

View File

@ -69,16 +69,21 @@ namespace osu.Game.Overlays.Mods
/// </summary>
public string SearchTerm
{
get => searchTextBox.Current.Value;
get => SearchTextBox.Current.Value;
set
{
if (searchTextBox.Current.Value == value)
if (SearchTextBox.Current.Value == value)
return;
searchTextBox.Current.Value = value;
SearchTextBox.Current.Value = value;
}
}
/// <summary>
/// Search box applied on mod overlay
/// </summary>
public ShearedSearchTextBox SearchTextBox { get; private set; } = null!;
/// <summary>
/// Whether the total score multiplier calculated from the current selected set of mods should be shown.
/// </summary>
@ -124,7 +129,6 @@ namespace osu.Game.Overlays.Mods
private FillFlowContainer<ShearedButton> footerButtonFlow = null!;
private Container aboveColumnsContent = null!;
private ShearedSearchTextBox searchTextBox = null!;
private DifficultyMultiplierDisplay? multiplierDisplay;
protected ShearedButton BackButton { get; private set; } = null!;
@ -168,7 +172,7 @@ namespace osu.Game.Overlays.Mods
RelativeSizeAxes = Axes.X,
Height = ModsEffectDisplay.HEIGHT,
Padding = new MarginPadding { Horizontal = 100 },
Child = searchTextBox = new ShearedSearchTextBox
Child = SearchTextBox = new ShearedSearchTextBox
{
HoldFocus = false,
Width = 300
@ -250,8 +254,8 @@ namespace osu.Game.Overlays.Mods
{
base.Hide();
//We want to clear search for next user iteraction with mod overlay
searchTextBox.Current.Value = string.Empty;
//We want to clear search for next user interaction with mod overlay
SearchTextBox.Current.Value = string.Empty;
}
private ModSettingChangeTracker? modSettingChangeTracker;
@ -287,7 +291,7 @@ namespace osu.Game.Overlays.Mods
customisationVisible.BindValueChanged(_ => updateCustomisationVisualState(), true);
searchTextBox.Current.BindValueChanged(query =>
SearchTextBox.Current.BindValueChanged(query =>
{
foreach (var column in columnFlow.Columns)
column.SearchTerm = query.NewValue;