1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 00:42:55 +08:00

Implement BeatmapSearchExtraFilterRow

This commit is contained in:
Andrei Zavatski 2020-10-27 21:22:20 +03:00
parent 742a96484b
commit 26a60d898c
7 changed files with 176 additions and 66 deletions

View File

@ -27,6 +27,7 @@ namespace osu.Game.Tests.Visual.UserInterface
OsuSpriteText category;
OsuSpriteText genre;
OsuSpriteText language;
OsuSpriteText extra;
Add(control = new BeatmapListingSearchControl
{
@ -46,6 +47,7 @@ namespace osu.Game.Tests.Visual.UserInterface
category = new OsuSpriteText(),
genre = new OsuSpriteText(),
language = new OsuSpriteText(),
extra = new OsuSpriteText()
}
});
@ -54,6 +56,7 @@ namespace osu.Game.Tests.Visual.UserInterface
control.Category.BindValueChanged(c => category.Text = $"Category: {c.NewValue}", true);
control.Genre.BindValueChanged(g => genre.Text = $"Genre: {g.NewValue}", true);
control.Language.BindValueChanged(l => language.Text = $"Language: {l.NewValue}", true);
control.Extra.BindValueChanged(e => extra.Text = $"Extra: {e.NewValue}", true);
}
[Test]

View File

@ -130,6 +130,7 @@ namespace osu.Game.Overlays.BeatmapListing
searchControl.Category.BindValueChanged(_ => queueUpdateSearch());
searchControl.Genre.BindValueChanged(_ => queueUpdateSearch());
searchControl.Language.BindValueChanged(_ => queueUpdateSearch());
searchControl.Extra.BindValueChanged(_ => queueUpdateSearch());
sortCriteria.BindValueChanged(_ => queueUpdateSearch());
sortDirection.BindValueChanged(_ => queueUpdateSearch());
@ -179,7 +180,8 @@ namespace osu.Game.Overlays.BeatmapListing
sortControl.Current.Value,
sortControl.SortDirection.Value,
searchControl.Genre.Value,
searchControl.Language.Value);
searchControl.Language.Value,
searchControl.Extra.Value);
getSetsRequest.Success += response =>
{

View File

@ -28,6 +28,8 @@ namespace osu.Game.Overlays.BeatmapListing
public Bindable<SearchLanguage> Language => languageFilter.Current;
public Bindable<SearchExtra> Extra => extraFilter.Current;
public BeatmapSetInfo BeatmapSet
{
set
@ -48,6 +50,7 @@ namespace osu.Game.Overlays.BeatmapListing
private readonly BeatmapSearchFilterRow<SearchCategory> categoryFilter;
private readonly BeatmapSearchFilterRow<SearchGenre> genreFilter;
private readonly BeatmapSearchFilterRow<SearchLanguage> languageFilter;
private readonly BeatmapSearchExtraFilterRow extraFilter;
private readonly Box background;
private readonly UpdateableBeatmapSetCover beatmapCover;
@ -105,6 +108,7 @@ namespace osu.Game.Overlays.BeatmapListing
categoryFilter = new BeatmapSearchFilterRow<SearchCategory>(@"Categories"),
genreFilter = new BeatmapSearchFilterRow<SearchGenre>(@"Genre"),
languageFilter = new BeatmapSearchFilterRow<SearchLanguage>(@"Language"),
extraFilter = new BeatmapSearchExtraFilterRow()
}
}
}

View File

@ -0,0 +1,97 @@
// 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.
using System;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osuTK;
namespace osu.Game.Overlays.BeatmapListing
{
public class BeatmapSearchExtraFilterRow : BeatmapSearchFilterRow<SearchExtra>
{
public BeatmapSearchExtraFilterRow()
: base("Extra")
{
}
protected override Drawable CreateFilter() => new ExtraFilter();
private class ExtraFilter : FillFlowContainer<ExtraFilterTabItem>, IHasCurrentValue<SearchExtra>
{
private readonly BindableWithCurrent<SearchExtra> current = new BindableWithCurrent<SearchExtra>();
public Bindable<SearchExtra> Current
{
get => current.Current;
set => current.Current = value;
}
private readonly ExtraFilterTabItem videoItem;
private readonly ExtraFilterTabItem storyboardItem;
public ExtraFilter()
{
Anchor = Anchor.BottomLeft;
Origin = Anchor.BottomLeft;
RelativeSizeAxes = Axes.X;
Height = 15;
Spacing = new Vector2(10, 0);
AddRange(new[]
{
videoItem = new ExtraFilterTabItem(SearchExtra.Video),
storyboardItem = new ExtraFilterTabItem(SearchExtra.Storyboard)
});
foreach (var item in Children)
item.StateUpdated += updateBindable;
}
private void updateBindable()
{
if (videoItem.Active.Value && storyboardItem.Active.Value)
{
Current.Value = SearchExtra.Both;
return;
}
if (videoItem.Active.Value)
{
Current.Value = SearchExtra.Video;
return;
}
if (storyboardItem.Active.Value)
{
Current.Value = SearchExtra.Storyboard;
return;
}
Current.Value = SearchExtra.Any;
}
}
private class ExtraFilterTabItem : FilterTabItem
{
public event Action StateUpdated;
public ExtraFilterTabItem(SearchExtra value)
: base(value)
{
Active.BindValueChanged(_ => StateUpdated?.Invoke());
}
protected override bool OnClick(ClickEvent e)
{
base.OnClick(e);
Active.Value = !Active.Value;
return true;
}
protected override string CreateText(SearchExtra value) => $@"Has {value.ToString()}";
}
}
}

View File

@ -32,6 +32,7 @@ namespace osu.Game.Overlays.BeatmapListing
public BeatmapSearchFilterRow(string headerName)
{
Drawable filter;
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
AddInternal(new GridContainer
@ -49,7 +50,7 @@ namespace osu.Game.Overlays.BeatmapListing
},
Content = new[]
{
new Drawable[]
new[]
{
new OsuSpriteText
{
@ -58,17 +59,17 @@ namespace osu.Game.Overlays.BeatmapListing
Font = OsuFont.GetFont(size: 13),
Text = headerName.Titleize()
},
CreateFilter().With(f =>
{
f.Current = current;
})
filter = CreateFilter()
}
}
});
if (filter is IHasCurrentValue<T> filterWithValue)
filterWithValue.Current = current;
}
[NotNull]
protected virtual BeatmapSearchFilter CreateFilter() => new BeatmapSearchFilter();
protected virtual Drawable CreateFilter() => new BeatmapSearchFilter();
protected class BeatmapSearchFilter : TabControl<T>
{
@ -99,62 +100,6 @@ namespace osu.Game.Overlays.BeatmapListing
protected override TabItem<T> CreateTabItem(T value) => new FilterTabItem(value);
protected class FilterTabItem : TabItem<T>
{
protected virtual float TextSize => 13;
[Resolved]
private OverlayColourProvider colourProvider { get; set; }
private readonly OsuSpriteText text;
public FilterTabItem(T value)
: base(value)
{
AutoSizeAxes = Axes.Both;
Anchor = Anchor.BottomLeft;
Origin = Anchor.BottomLeft;
AddRangeInternal(new Drawable[]
{
text = new OsuSpriteText
{
Font = OsuFont.GetFont(size: TextSize, weight: FontWeight.Regular),
Text = (value as Enum)?.GetDescription() ?? value.ToString()
},
new HoverClickSounds()
});
Enabled.Value = true;
}
[BackgroundDependencyLoader]
private void load()
{
updateState();
}
protected override bool OnHover(HoverEvent e)
{
base.OnHover(e);
updateState();
return true;
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
updateState();
}
protected override void OnActivated() => updateState();
protected override void OnDeactivated() => updateState();
private void updateState() => text.FadeColour(Active.Value ? Color4.White : getStateColour(), 200, Easing.OutQuint);
private Color4 getStateColour() => IsHovered ? colourProvider.Light1 : colourProvider.Light3;
}
private class FilterDropdown : OsuTabDropdown<T>
{
protected override DropdownHeader CreateHeader() => new FilterHeader
@ -172,5 +117,63 @@ namespace osu.Game.Overlays.BeatmapListing
}
}
}
protected class FilterTabItem : TabItem<T>
{
protected virtual float TextSize => 13;
[Resolved]
private OverlayColourProvider colourProvider { get; set; }
private readonly OsuSpriteText text;
public FilterTabItem(T value)
: base(value)
{
AutoSizeAxes = Axes.Both;
Anchor = Anchor.BottomLeft;
Origin = Anchor.BottomLeft;
AddRangeInternal(new Drawable[]
{
text = new OsuSpriteText
{
Font = OsuFont.GetFont(size: TextSize, weight: FontWeight.Regular),
Text = CreateText(value)
},
new HoverClickSounds()
});
Enabled.Value = true;
}
protected virtual string CreateText(T value) => (value as Enum)?.GetDescription() ?? value.ToString();
[BackgroundDependencyLoader]
private void load()
{
updateState();
}
protected override bool OnHover(HoverEvent e)
{
base.OnHover(e);
updateState();
return true;
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
updateState();
}
protected override void OnActivated() => updateState();
protected override void OnDeactivated() => updateState();
private void updateState() => text.FadeColour(Active.Value ? Color4.White : getStateColour(), 200, Easing.OutQuint);
private Color4 getStateColour() => IsHovered ? colourProvider.Light1 : colourProvider.Light3;
}
}
}

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Rulesets;
namespace osu.Game.Overlays.BeatmapListing
@ -13,7 +14,7 @@ namespace osu.Game.Overlays.BeatmapListing
{
}
protected override BeatmapSearchFilter CreateFilter() => new RulesetFilter();
protected override Drawable CreateFilter() => new RulesetFilter();
private class RulesetFilter : BeatmapSearchFilter
{

View File

@ -5,9 +5,9 @@ namespace osu.Game.Overlays.BeatmapListing
{
public enum SearchExtra
{
Any,
Video,
Storyboard,
Both,
Any
Both
}
}