Merge pull request #22773 from peppy/show-song-select-visible-beatmap-count

Show count of visible beatmaps at song select
This commit is contained in:
Dean Herbert
2023-03-21 18:22:29 +09:00
committed by GitHub
4 changed files with 111 additions and 62 deletions

View File

@ -1,4 +1,4 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Localisation; using osu.Framework.Localisation;

View File

@ -49,6 +49,11 @@ namespace osu.Game.Screens.Select
/// </summary> /// </summary>
public Action? BeatmapSetsChanged; public Action? BeatmapSetsChanged;
/// <summary>
/// Triggered after filter conditions have finished being applied to the model hierarchy.
/// </summary>
public Action? FilterApplied;
/// <summary> /// <summary>
/// The currently selected beatmap. /// The currently selected beatmap.
/// </summary> /// </summary>
@ -56,6 +61,11 @@ namespace osu.Game.Screens.Select
private CarouselBeatmap? selectedBeatmap => selectedBeatmapSet?.Beatmaps.FirstOrDefault(s => s.State.Value == CarouselItemState.Selected); private CarouselBeatmap? selectedBeatmap => selectedBeatmapSet?.Beatmaps.FirstOrDefault(s => s.State.Value == CarouselItemState.Selected);
/// <summary>
/// The total count of non-filtered beatmaps displayed.
/// </summary>
public int CountDisplayed => beatmapSets.Where(s => !s.Filtered.Value).Sum(s => s.Beatmaps.Count(b => !b.Filtered.Value));
/// <summary> /// <summary>
/// The currently selected beatmap set. /// The currently selected beatmap set.
/// </summary> /// </summary>
@ -639,6 +649,8 @@ namespace osu.Game.Screens.Select
if (alwaysResetScrollPosition || !Scroll.UserScrolling) if (alwaysResetScrollPosition || !Scroll.UserScrolling)
ScrollToSelected(true); ScrollToSelected(true);
FilterApplied?.Invoke();
} }
} }

View File

@ -10,6 +10,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Collections; using osu.Game.Collections;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Graphics; using osu.Game.Graphics;
@ -27,20 +28,27 @@ namespace osu.Game.Screens.Select
{ {
public partial class FilterControl : Container public partial class FilterControl : Container
{ {
public const float HEIGHT = 2 * side_margin + 85; public const float HEIGHT = 2 * side_margin + 120;
private const float side_margin = 20;
private const float side_margin = 10;
public Action<FilterCriteria> FilterChanged; public Action<FilterCriteria> FilterChanged;
public Bindable<string> CurrentTextSearch => searchTextBox.Current; public Bindable<string> CurrentTextSearch => searchTextBox.Current;
public LocalisableString InformationalText
{
get => searchTextBox.FilterText.Text;
set => searchTextBox.FilterText.Text = value;
}
private OsuTabControl<SortMode> sortTabs; private OsuTabControl<SortMode> sortTabs;
private Bindable<SortMode> sortMode; private Bindable<SortMode> sortMode;
private Bindable<GroupMode> groupMode; private Bindable<GroupMode> groupMode;
private SeekLimitedSearchTextBox searchTextBox; private FilterControlTextBox searchTextBox;
private CollectionDropdown collectionDropdown; private CollectionDropdown collectionDropdown;
@ -99,72 +107,63 @@ namespace osu.Game.Screens.Select
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Spacing = new Vector2(0, 5), Spacing = new Vector2(0, 5),
Children = new[] Children = new Drawable[]
{ {
new Container searchTextBox = new FilterControlTextBox
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
Height = 60, },
Children = new Drawable[] new Box
{
RelativeSizeAxes = Axes.X,
Height = 1,
Colour = OsuColour.Gray(80),
},
new GridContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
ColumnDimensions = new[]
{ {
searchTextBox = new SeekLimitedSearchTextBox { RelativeSizeAxes = Axes.X }, new Dimension(GridSizeMode.AutoSize),
new Box new Dimension(GridSizeMode.Absolute, OsuTabControl<SortMode>.HORIZONTAL_SPACING),
new Dimension(),
new Dimension(GridSizeMode.Absolute, OsuTabControl<SortMode>.HORIZONTAL_SPACING),
new Dimension(GridSizeMode.AutoSize),
},
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) },
Content = new[]
{
new[]
{ {
RelativeSizeAxes = Axes.X, new OsuSpriteText
Height = 1,
Colour = OsuColour.Gray(80),
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
},
new GridContainer
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
ColumnDimensions = new[]
{ {
new Dimension(GridSizeMode.AutoSize), Text = SortStrings.Default,
new Dimension(GridSizeMode.Absolute, OsuTabControl<SortMode>.HORIZONTAL_SPACING), Font = OsuFont.GetFont(size: 14),
new Dimension(), Margin = new MarginPadding(5),
new Dimension(GridSizeMode.Absolute, OsuTabControl<SortMode>.HORIZONTAL_SPACING), Anchor = Anchor.BottomRight,
new Dimension(GridSizeMode.AutoSize), Origin = Anchor.BottomRight,
}, },
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }, Empty(),
Content = new[] sortTabs = new OsuTabControl<SortMode>
{ {
new[] RelativeSizeAxes = Axes.X,
{ Height = 24,
new OsuSpriteText AutoSort = true,
{ Anchor = Anchor.BottomRight,
Text = SortStrings.Default, Origin = Anchor.BottomRight,
Font = OsuFont.GetFont(size: 14), AccentColour = colours.GreenLight,
Margin = new MarginPadding(5), Current = { BindTarget = sortMode }
Anchor = Anchor.BottomRight, },
Origin = Anchor.BottomRight, Empty(),
}, new OsuTabControlCheckbox
Empty(), {
sortTabs = new OsuTabControl<SortMode> Text = "Show converted",
{ Current = config.GetBindable<bool>(OsuSetting.ShowConvertedBeatmaps),
RelativeSizeAxes = Axes.X, Anchor = Anchor.BottomRight,
Height = 24, Origin = Anchor.BottomRight,
AutoSort = true, },
Anchor = Anchor.BottomRight, }
Origin = Anchor.BottomRight,
AccentColour = colours.GreenLight,
Current = { BindTarget = sortMode }
},
Empty(),
new OsuTabControlCheckbox
{
Text = "Show converted",
Current = config.GetBindable<bool>(OsuSetting.ShowConvertedBeatmaps),
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
},
}
}
},
} }
}, },
new Container new Container
@ -248,5 +247,32 @@ namespace osu.Game.Screens.Select
protected override bool OnClick(ClickEvent e) => true; protected override bool OnClick(ClickEvent e) => true;
protected override bool OnHover(HoverEvent e) => true; protected override bool OnHover(HoverEvent e) => true;
private partial class FilterControlTextBox : SeekLimitedSearchTextBox
{
private const float filter_text_size = 12;
public OsuSpriteText FilterText { get; private set; }
public FilterControlTextBox()
{
Height += filter_text_size;
TextContainer.Margin = new MarginPadding { Bottom = filter_text_size };
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
TextContainer.Add(FilterText = new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.TopLeft,
Depth = float.MinValue,
Font = OsuFont.Default.With(size: filter_text_size, weight: FontWeight.SemiBold),
Margin = new MarginPadding { Top = 2, Left = 2 },
Colour = colours.Yellow
});
}
}
} }
} }

View File

@ -162,6 +162,7 @@ namespace osu.Game.Screens.Select
BleedBottom = Footer.HEIGHT, BleedBottom = Footer.HEIGHT,
SelectionChanged = updateSelectedBeatmap, SelectionChanged = updateSelectedBeatmap,
BeatmapSetsChanged = carouselBeatmapsLoaded, BeatmapSetsChanged = carouselBeatmapsLoaded,
FilterApplied = updateVisibleBeatmapCount,
GetRecommendedBeatmap = s => recommender?.GetRecommendedBeatmap(s), GetRecommendedBeatmap = s => recommender?.GetRecommendedBeatmap(s),
}, c => carouselContainer.Child = c); }, c => carouselContainer.Child = c);
@ -828,6 +829,7 @@ namespace osu.Game.Screens.Select
private void carouselBeatmapsLoaded() private void carouselBeatmapsLoaded()
{ {
bindBindables(); bindBindables();
updateVisibleBeatmapCount();
Carousel.AllowSelection = true; Carousel.AllowSelection = true;
@ -857,6 +859,15 @@ namespace osu.Game.Screens.Select
} }
} }
private void updateVisibleBeatmapCount()
{
FilterControl.InformationalText = Carousel.CountDisplayed == 1
// Intentionally not localised until we have proper support for this (see https://github.com/ppy/osu-framework/pull/4918
// but also in this case we want support for formatting a number within a string).
? $"{Carousel.CountDisplayed:#,0} matching beatmap"
: $"{Carousel.CountDisplayed:#,0} matching beatmaps";
}
private bool boundLocalBindables; private bool boundLocalBindables;
private void bindBindables() private void bindBindables()