Add preselection indicator for better visibility what will be selected

This commit is contained in:
Bartłomiej Dach 2024-10-18 13:23:37 +02:00
parent 083644b713
commit 05e2f6db8e
No known key found for this signature in database
3 changed files with 49 additions and 7 deletions

View File

@ -4,8 +4,10 @@
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Rulesets.Mods;
@ -58,6 +60,20 @@ namespace osu.Game.Overlays.Mods
modState.ValidForSelection.BindValueChanged(_ => updateFilterState());
modState.MatchingTextFilter.BindValueChanged(_ => updateFilterState(), true);
modState.Preselected.BindValueChanged(b =>
{
if (b.NewValue)
{
Content.EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Colour = AccentColour.Opacity(0.5f),
Radius = 10,
};
}
else
Content.EdgeEffect = default;
}, true);
}
protected override void Select()

View File

@ -243,6 +243,9 @@ namespace osu.Game.Overlays.Mods
{
foreach (var column in columnFlow.Columns)
column.SearchTerm = query.NewValue;
if (SearchTextBox.HasFocus)
preselectMod();
}, true);
// 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 override VisibilityContainer CreateFooterContent() => new ModSelectFooterContent(this)
@ -383,7 +406,7 @@ namespace osu.Game.Overlays.Mods
{
columnScroll.FadeColour(OsuColour.Gray(0.5f), 400, Easing.OutQuint);
SearchTextBox.FadeColour(OsuColour.Gray(0.5f), 400, Easing.OutQuint);
SearchTextBox.KillFocus();
setTextBoxFocus(false);
}
else
{
@ -590,12 +613,7 @@ namespace osu.Game.Overlays.Mods
return true;
}
IEnumerable<ModState> 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 matchingMod = AllAvailableMods.SingleOrDefault(m => m.Preselected.Value);
if (matchingMod is not null)
{
@ -653,9 +671,15 @@ namespace osu.Game.Overlays.Mods
private void setTextBoxFocus(bool focus)
{
if (focus)
{
SearchTextBox.TakeFocus();
preselectMod();
}
else
{
SearchTextBox.KillFocus();
clearPreselection();
}
}
#endregion

View File

@ -22,6 +22,8 @@ namespace osu.Game.Overlays.Mods
/// </summary>
public BindableBool Active { get; } = new BindableBool();
public BindableBool Preselected { get; } = new BindableBool();
/// <summary>
/// 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