1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 15:03:13 +08:00

Rework multiple selection filter

This commit is contained in:
Bartłomiej Dach 2020-10-28 23:07:54 +01:00
parent e77049eae3
commit f5aedc96c4
2 changed files with 17 additions and 9 deletions

View File

@ -3,8 +3,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
@ -32,7 +33,8 @@ namespace osu.Game.Overlays.BeatmapListing
{
public readonly BindableList<T> Current = new BindableList<T>();
public MultipleSelectionFilter()
[BackgroundDependencyLoader]
private void load()
{
Anchor = Anchor.BottomLeft;
Origin = Anchor.BottomLeft;
@ -40,17 +42,22 @@ namespace osu.Game.Overlays.BeatmapListing
Height = 15;
Spacing = new Vector2(10, 0);
GetValues().ForEach(i => Add(CreateTabItem(i)));
foreach (var item in Children)
item.Active.BindValueChanged(active => updateBindable(item.Value, active.NewValue));
AddRange(GetValues().Select(CreateTabItem));
}
protected virtual T[] GetValues() => (T[])Enum.GetValues(typeof(T));
protected override void LoadComplete()
{
base.LoadComplete();
foreach (var item in Children)
item.Active.BindValueChanged(active => toggleItem(item.Value, active.NewValue));
}
protected virtual IEnumerable<T> GetValues() => Enum.GetValues(typeof(T)).Cast<T>();
protected virtual MultipleSelectionFilterTabItem CreateTabItem(T value) => new MultipleSelectionFilterTabItem(value);
private void updateBindable(T value, bool active)
private void toggleItem(T value, bool active)
{
if (active)
Current.Add(value);

View File

@ -1,6 +1,7 @@
// 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.Collections.Generic;
using System.Linq;
using osu.Game.Scoring;
@ -19,7 +20,7 @@ namespace osu.Game.Overlays.BeatmapListing
{
protected override MultipleSelectionFilterTabItem CreateTabItem(ScoreRank value) => new RankItem(value);
protected override ScoreRank[] GetValues() => base.GetValues().Reverse().ToArray();
protected override IEnumerable<ScoreRank> GetValues() => base.GetValues().Reverse();
}
private class RankItem : MultipleSelectionFilterTabItem