mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 18:13:09 +08:00
Rework multiple selection filter
This commit is contained in:
parent
e77049eae3
commit
f5aedc96c4
@ -3,8 +3,9 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
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.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
@ -32,7 +33,8 @@ namespace osu.Game.Overlays.BeatmapListing
|
|||||||
{
|
{
|
||||||
public readonly BindableList<T> Current = new BindableList<T>();
|
public readonly BindableList<T> Current = new BindableList<T>();
|
||||||
|
|
||||||
public MultipleSelectionFilter()
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
{
|
{
|
||||||
Anchor = Anchor.BottomLeft;
|
Anchor = Anchor.BottomLeft;
|
||||||
Origin = Anchor.BottomLeft;
|
Origin = Anchor.BottomLeft;
|
||||||
@ -40,17 +42,22 @@ namespace osu.Game.Overlays.BeatmapListing
|
|||||||
Height = 15;
|
Height = 15;
|
||||||
Spacing = new Vector2(10, 0);
|
Spacing = new Vector2(10, 0);
|
||||||
|
|
||||||
GetValues().ForEach(i => Add(CreateTabItem(i)));
|
AddRange(GetValues().Select(CreateTabItem));
|
||||||
|
|
||||||
foreach (var item in Children)
|
|
||||||
item.Active.BindValueChanged(active => updateBindable(item.Value, active.NewValue));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
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)
|
if (active)
|
||||||
Current.Add(value);
|
Current.Add(value);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// 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.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
|
|
||||||
@ -19,7 +20,7 @@ namespace osu.Game.Overlays.BeatmapListing
|
|||||||
{
|
{
|
||||||
protected override MultipleSelectionFilterTabItem CreateTabItem(ScoreRank value) => new RankItem(value);
|
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
|
private class RankItem : MultipleSelectionFilterTabItem
|
||||||
|
Loading…
Reference in New Issue
Block a user