mirror of
https://github.com/ppy/osu.git
synced 2025-01-31 17:52:54 +08:00
Merge pull request #30330 from jhk2601/mod_acronym_search_fix
Prioritize selecting exact searched acronym with select keybind
This commit is contained in:
commit
84e08d96ca
@ -6,6 +6,7 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Effects;
|
||||||
using osu.Framework.Localisation;
|
using osu.Framework.Localisation;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
@ -58,6 +59,21 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
modState.ValidForSelection.BindValueChanged(_ => updateFilterState());
|
modState.ValidForSelection.BindValueChanged(_ => updateFilterState());
|
||||||
modState.MatchingTextFilter.BindValueChanged(_ => updateFilterState(), true);
|
modState.MatchingTextFilter.BindValueChanged(_ => updateFilterState(), true);
|
||||||
|
modState.Preselected.BindValueChanged(b =>
|
||||||
|
{
|
||||||
|
if (b.NewValue)
|
||||||
|
{
|
||||||
|
Content.EdgeEffect = new EdgeEffectParameters
|
||||||
|
{
|
||||||
|
Type = EdgeEffectType.Glow,
|
||||||
|
Colour = AccentColour,
|
||||||
|
Hollow = true,
|
||||||
|
Radius = 2,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Content.EdgeEffect = default;
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Select()
|
protected override void Select()
|
||||||
|
@ -243,6 +243,9 @@ namespace osu.Game.Overlays.Mods
|
|||||||
{
|
{
|
||||||
foreach (var column in columnFlow.Columns)
|
foreach (var column in columnFlow.Columns)
|
||||||
column.SearchTerm = query.NewValue;
|
column.SearchTerm = query.NewValue;
|
||||||
|
|
||||||
|
if (SearchTextBox.HasFocus)
|
||||||
|
preselectMod();
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
// Start scrolling from the end, to give the user a sense that
|
// Start scrolling from the end, to give the user a sense that
|
||||||
@ -254,6 +257,26 @@ namespace osu.Game.Overlays.Mods
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void preselectMod()
|
||||||
|
{
|
||||||
|
var visibleMods = columnFlow.Columns.OfType<ModColumn>().Where(c => c.IsPresent).SelectMany(c => c.AvailableMods.Where(m => m.Visible));
|
||||||
|
|
||||||
|
// Search for an exact acronym or name match, or otherwise default to the first visible mod.
|
||||||
|
ModState? matchingMod =
|
||||||
|
visibleMods.FirstOrDefault(m => m.Mod.Acronym.Equals(SearchTerm, StringComparison.OrdinalIgnoreCase) || m.Mod.Name.Equals(SearchTerm, StringComparison.OrdinalIgnoreCase))
|
||||||
|
?? visibleMods.FirstOrDefault();
|
||||||
|
var preselectedMod = matchingMod;
|
||||||
|
|
||||||
|
foreach (var mod in AllAvailableMods)
|
||||||
|
mod.Preselected.Value = mod == preselectedMod && SearchTextBox.Current.Value.Length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearPreselection()
|
||||||
|
{
|
||||||
|
foreach (var mod in AllAvailableMods)
|
||||||
|
mod.Preselected.Value = false;
|
||||||
|
}
|
||||||
|
|
||||||
public new ModSelectFooterContent? DisplayedFooterContent => base.DisplayedFooterContent as ModSelectFooterContent;
|
public new ModSelectFooterContent? DisplayedFooterContent => base.DisplayedFooterContent as ModSelectFooterContent;
|
||||||
|
|
||||||
public override VisibilityContainer CreateFooterContent() => new ModSelectFooterContent(this)
|
public override VisibilityContainer CreateFooterContent() => new ModSelectFooterContent(this)
|
||||||
@ -383,7 +406,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
{
|
{
|
||||||
columnScroll.FadeColour(OsuColour.Gray(0.5f), 400, Easing.OutQuint);
|
columnScroll.FadeColour(OsuColour.Gray(0.5f), 400, Easing.OutQuint);
|
||||||
SearchTextBox.FadeColour(OsuColour.Gray(0.5f), 400, Easing.OutQuint);
|
SearchTextBox.FadeColour(OsuColour.Gray(0.5f), 400, Easing.OutQuint);
|
||||||
SearchTextBox.KillFocus();
|
setTextBoxFocus(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -590,11 +613,11 @@ namespace osu.Game.Overlays.Mods
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModState? firstMod = columnFlow.Columns.OfType<ModColumn>().FirstOrDefault(m => m.IsPresent)?.AvailableMods.FirstOrDefault(x => x.Visible);
|
var matchingMod = AllAvailableMods.SingleOrDefault(m => m.Preselected.Value);
|
||||||
|
|
||||||
if (firstMod is not null)
|
if (matchingMod is not null)
|
||||||
{
|
{
|
||||||
firstMod.Active.Value = !firstMod.Active.Value;
|
matchingMod.Active.Value = !matchingMod.Active.Value;
|
||||||
SearchTextBox.SelectAll();
|
SearchTextBox.SelectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -648,9 +671,15 @@ namespace osu.Game.Overlays.Mods
|
|||||||
private void setTextBoxFocus(bool focus)
|
private void setTextBoxFocus(bool focus)
|
||||||
{
|
{
|
||||||
if (focus)
|
if (focus)
|
||||||
|
{
|
||||||
SearchTextBox.TakeFocus();
|
SearchTextBox.TakeFocus();
|
||||||
|
preselectMod();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
SearchTextBox.KillFocus();
|
SearchTextBox.KillFocus();
|
||||||
|
clearPreselection();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -22,6 +22,8 @@ namespace osu.Game.Overlays.Mods
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public BindableBool Active { get; } = new BindableBool();
|
public BindableBool Active { get; } = new BindableBool();
|
||||||
|
|
||||||
|
public BindableBool Preselected { get; } = new BindableBool();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether the mod requires further customisation.
|
/// Whether the mod requires further customisation.
|
||||||
/// This flag is read by the <see cref="ModSelectOverlay"/> to determine if the customisation panel should be opened after a mod change
|
/// This flag is read by the <see cref="ModSelectOverlay"/> to determine if the customisation panel should be opened after a mod change
|
||||||
|
Loading…
Reference in New Issue
Block a user