mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 11:22:57 +08:00
Simplify BeatmapSearchMultipleSelectionFilterRow
This commit is contained in:
parent
fd11346a28
commit
03c5057a92
@ -55,8 +55,8 @@ namespace osu.Game.Overlays.BeatmapListing
|
|||||||
private readonly BeatmapSearchFilterRow<SearchCategory> categoryFilter;
|
private readonly BeatmapSearchFilterRow<SearchCategory> categoryFilter;
|
||||||
private readonly BeatmapSearchFilterRow<SearchGenre> genreFilter;
|
private readonly BeatmapSearchFilterRow<SearchGenre> genreFilter;
|
||||||
private readonly BeatmapSearchFilterRow<SearchLanguage> languageFilter;
|
private readonly BeatmapSearchFilterRow<SearchLanguage> languageFilter;
|
||||||
private readonly BeatmapSearchExtraFilterRow extraFilter;
|
private readonly BeatmapSearchMultipleSelectionFilterRow<SearchExtra> extraFilter;
|
||||||
private readonly BeatmapSearchRankFilterRow ranksFilter;
|
private readonly BeatmapSearchMultipleSelectionFilterRow<SearchRank> ranksFilter;
|
||||||
private readonly BeatmapSearchFilterRow<SearchPlayed> playedFilter;
|
private readonly BeatmapSearchFilterRow<SearchPlayed> playedFilter;
|
||||||
|
|
||||||
private readonly Box background;
|
private readonly Box background;
|
||||||
@ -115,8 +115,8 @@ namespace osu.Game.Overlays.BeatmapListing
|
|||||||
categoryFilter = new BeatmapSearchFilterRow<SearchCategory>(@"Categories"),
|
categoryFilter = new BeatmapSearchFilterRow<SearchCategory>(@"Categories"),
|
||||||
genreFilter = new BeatmapSearchFilterRow<SearchGenre>(@"Genre"),
|
genreFilter = new BeatmapSearchFilterRow<SearchGenre>(@"Genre"),
|
||||||
languageFilter = new BeatmapSearchFilterRow<SearchLanguage>(@"Language"),
|
languageFilter = new BeatmapSearchFilterRow<SearchLanguage>(@"Language"),
|
||||||
extraFilter = new BeatmapSearchExtraFilterRow(),
|
extraFilter = new BeatmapSearchMultipleSelectionFilterRow<SearchExtra>(@"Extra"),
|
||||||
ranksFilter = new BeatmapSearchRankFilterRow(),
|
ranksFilter = new BeatmapSearchMultipleSelectionFilterRow<SearchRank>(@"Rank Achieved"),
|
||||||
playedFilter = new BeatmapSearchFilterRow<SearchPlayed>(@"Played")
|
playedFilter = new BeatmapSearchFilterRow<SearchPlayed>(@"Played")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
// 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.
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.BeatmapListing
|
|
||||||
{
|
|
||||||
public class BeatmapSearchExtraFilterRow : BeatmapSearchMultipleSelectionFilterRow<SearchExtra>
|
|
||||||
{
|
|
||||||
public BeatmapSearchExtraFilterRow()
|
|
||||||
: base("Extra")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override MultipleSelectionFilter CreateMultipleSelectionFilter() => new ExtraFilter();
|
|
||||||
|
|
||||||
private class ExtraFilter : MultipleSelectionFilter
|
|
||||||
{
|
|
||||||
protected override MultipleSelectionFilterTabItem[] CreateItems() => new MultipleSelectionFilterTabItem[]
|
|
||||||
{
|
|
||||||
new ExtraFilterTabItem(SearchExtra.Video),
|
|
||||||
new ExtraFilterTabItem(SearchExtra.Storyboard)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ExtraFilterTabItem : MultipleSelectionFilterTabItem
|
|
||||||
{
|
|
||||||
public ExtraFilterTabItem(SearchExtra value)
|
|
||||||
: base(value)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string CreateText(SearchExtra value) => $@"Has {value.ToString()}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,10 @@
|
|||||||
// 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 System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
@ -11,18 +13,16 @@ using osuTK;
|
|||||||
|
|
||||||
namespace osu.Game.Overlays.BeatmapListing
|
namespace osu.Game.Overlays.BeatmapListing
|
||||||
{
|
{
|
||||||
public abstract class BeatmapSearchMultipleSelectionFilterRow<T> : BeatmapSearchFilterRow<List<T>>
|
public class BeatmapSearchMultipleSelectionFilterRow<T> : BeatmapSearchFilterRow<List<T>>
|
||||||
{
|
{
|
||||||
protected BeatmapSearchMultipleSelectionFilterRow(string headerName)
|
public BeatmapSearchMultipleSelectionFilterRow(string headerName)
|
||||||
: base(headerName)
|
: base(headerName)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Drawable CreateFilter() => CreateMultipleSelectionFilter();
|
protected override Drawable CreateFilter() => new MultipleSelectionFilter();
|
||||||
|
|
||||||
protected abstract MultipleSelectionFilter CreateMultipleSelectionFilter();
|
private class MultipleSelectionFilter : FillFlowContainer<MultipleSelectionFilterTabItem>, IHasCurrentValue<List<T>>
|
||||||
|
|
||||||
protected abstract class MultipleSelectionFilter : FillFlowContainer<MultipleSelectionFilterTabItem>, IHasCurrentValue<List<T>>
|
|
||||||
{
|
{
|
||||||
private readonly BindableWithCurrent<List<T>> current = new BindableWithCurrent<List<T>>();
|
private readonly BindableWithCurrent<List<T>> current = new BindableWithCurrent<List<T>>();
|
||||||
|
|
||||||
@ -32,21 +32,20 @@ namespace osu.Game.Overlays.BeatmapListing
|
|||||||
set => current.Current = value;
|
set => current.Current = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MultipleSelectionFilter()
|
public MultipleSelectionFilter()
|
||||||
{
|
{
|
||||||
Anchor = Anchor.BottomLeft;
|
Anchor = Anchor.BottomLeft;
|
||||||
Origin = Anchor.BottomLeft;
|
Origin = Anchor.BottomLeft;
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
Height = 15;
|
Height = 15;
|
||||||
Spacing = new Vector2(10, 0);
|
Spacing = new Vector2(10, 0);
|
||||||
AddRange(CreateItems());
|
|
||||||
|
((T[])Enum.GetValues(typeof(T))).ForEach(i => Add(new MultipleSelectionFilterTabItem(i)));
|
||||||
|
|
||||||
foreach (var item in Children)
|
foreach (var item in Children)
|
||||||
item.Active.BindValueChanged(_ => updateBindable());
|
item.Active.BindValueChanged(_ => updateBindable());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract MultipleSelectionFilterTabItem[] CreateItems();
|
|
||||||
|
|
||||||
private void updateBindable()
|
private void updateBindable()
|
||||||
{
|
{
|
||||||
var selectedValues = new List<T>();
|
var selectedValues = new List<T>();
|
||||||
@ -61,7 +60,7 @@ namespace osu.Game.Overlays.BeatmapListing
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class MultipleSelectionFilterTabItem : FilterTabItem<T>
|
private class MultipleSelectionFilterTabItem : FilterTabItem<T>
|
||||||
{
|
{
|
||||||
public MultipleSelectionFilterTabItem(T value)
|
public MultipleSelectionFilterTabItem(T value)
|
||||||
: base(value)
|
: base(value)
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
// 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 System.Linq;
|
|
||||||
using osu.Framework.Extensions;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.BeatmapListing
|
|
||||||
{
|
|
||||||
public class BeatmapSearchRankFilterRow : BeatmapSearchMultipleSelectionFilterRow<SearchRank>
|
|
||||||
{
|
|
||||||
public BeatmapSearchRankFilterRow()
|
|
||||||
: base("Rank Achieved")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override MultipleSelectionFilter CreateMultipleSelectionFilter() => new RankFilter();
|
|
||||||
|
|
||||||
private class RankFilter : MultipleSelectionFilter
|
|
||||||
{
|
|
||||||
protected override MultipleSelectionFilterTabItem[] CreateItems()
|
|
||||||
=> ((SearchRank[])Enum.GetValues(typeof(SearchRank))).Select(v => new RankFilterTabItem(v)).ToArray<MultipleSelectionFilterTabItem>();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RankFilterTabItem : MultipleSelectionFilterTabItem
|
|
||||||
{
|
|
||||||
public RankFilterTabItem(SearchRank value)
|
|
||||||
: base(value)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string CreateText(SearchRank value) => $@"{value.GetDescription() ?? value.ToString()}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -32,7 +32,7 @@ namespace osu.Game.Overlays.BeatmapListing
|
|||||||
text = new OsuSpriteText
|
text = new OsuSpriteText
|
||||||
{
|
{
|
||||||
Font = OsuFont.GetFont(size: 13, weight: FontWeight.Regular),
|
Font = OsuFont.GetFont(size: 13, weight: FontWeight.Regular),
|
||||||
Text = CreateText(value)
|
Text = (value as Enum)?.GetDescription() ?? value.ToString()
|
||||||
},
|
},
|
||||||
new HoverClickSounds()
|
new HoverClickSounds()
|
||||||
});
|
});
|
||||||
@ -40,8 +40,6 @@ namespace osu.Game.Overlays.BeatmapListing
|
|||||||
Enabled.Value = true;
|
Enabled.Value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual string CreateText(T value) => (value as Enum)?.GetDescription() ?? value.ToString();
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
// 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 System.ComponentModel;
|
||||||
|
|
||||||
namespace osu.Game.Overlays.BeatmapListing
|
namespace osu.Game.Overlays.BeatmapListing
|
||||||
{
|
{
|
||||||
public enum SearchExtra
|
public enum SearchExtra
|
||||||
{
|
{
|
||||||
|
[Description("Has Video")]
|
||||||
Video,
|
Video,
|
||||||
|
[Description("Has Storyboard")]
|
||||||
Storyboard
|
Storyboard
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user