mirror of
https://github.com/ppy/osu.git
synced 2025-03-24 07:27:29 +08:00
Use BindableList<T>
This commit is contained in:
parent
914bd53788
commit
4f6081c7f3
@ -61,8 +61,8 @@ 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 == null ? "" : string.Join('.', e.NewValue.Select(i => i.ToString().ToLowerInvariant())))}", true);
|
||||
control.Ranks.BindValueChanged(r => ranks.Text = $"Ranks: {(r.NewValue == null ? "" : string.Join('.', r.NewValue.Select(i => i.ToString())))}", true);
|
||||
control.Extra.BindCollectionChanged((u, v) => extra.Text = $"Extra: {(control.Extra.Any() ? string.Join('.', control.Extra.Select(i => i.ToString().ToLowerInvariant())) : "")}", true);
|
||||
control.Ranks.BindCollectionChanged((u, v) => ranks.Text = $"Ranks: {(control.Ranks.Any() ? string.Join('.', control.Ranks.Select(i => i.ToString())) : "")}", true);
|
||||
control.Played.BindValueChanged(p => played.Text = $"Played: {p.NewValue}", true);
|
||||
}
|
||||
|
||||
|
@ -130,8 +130,8 @@ namespace osu.Game.Overlays.BeatmapListing
|
||||
searchControl.Category.BindValueChanged(_ => queueUpdateSearch());
|
||||
searchControl.Genre.BindValueChanged(_ => queueUpdateSearch());
|
||||
searchControl.Language.BindValueChanged(_ => queueUpdateSearch());
|
||||
searchControl.Extra.BindValueChanged(_ => queueUpdateSearch());
|
||||
searchControl.Ranks.BindValueChanged(_ => queueUpdateSearch());
|
||||
searchControl.Extra.CollectionChanged += (u, v) => queueUpdateSearch();
|
||||
searchControl.Ranks.CollectionChanged += (u, v) => queueUpdateSearch();
|
||||
searchControl.Played.BindValueChanged(_ => queueUpdateSearch());
|
||||
|
||||
sortCriteria.BindValueChanged(_ => queueUpdateSearch());
|
||||
@ -183,8 +183,8 @@ namespace osu.Game.Overlays.BeatmapListing
|
||||
sortControl.SortDirection.Value,
|
||||
searchControl.Genre.Value,
|
||||
searchControl.Language.Value,
|
||||
searchControl.Extra.Value,
|
||||
searchControl.Ranks.Value,
|
||||
searchControl.Extra,
|
||||
searchControl.Ranks,
|
||||
searchControl.Played.Value);
|
||||
|
||||
getSetsRequest.Success += response =>
|
||||
|
@ -13,7 +13,6 @@ using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osuTK.Graphics;
|
||||
using osu.Game.Rulesets;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace osu.Game.Overlays.BeatmapListing
|
||||
{
|
||||
@ -29,9 +28,9 @@ namespace osu.Game.Overlays.BeatmapListing
|
||||
|
||||
public Bindable<SearchLanguage> Language => languageFilter.Current;
|
||||
|
||||
public Bindable<List<SearchExtra>> Extra => extraFilter.Current;
|
||||
public BindableList<SearchExtra> Extra => extraFilter.Current;
|
||||
|
||||
public Bindable<List<SearchRank>> Ranks => ranksFilter.Current;
|
||||
public BindableList<SearchRank> Ranks => ranksFilter.Current;
|
||||
|
||||
public Bindable<SearchPlayed> Played => playedFilter.Current;
|
||||
|
||||
|
@ -61,7 +61,7 @@ namespace osu.Game.Overlays.BeatmapListing
|
||||
});
|
||||
|
||||
if (filter is IHasCurrentValue<T> filterWithValue)
|
||||
filterWithValue.Current = current;
|
||||
Current = filterWithValue.Current;
|
||||
}
|
||||
|
||||
[NotNull]
|
||||
|
@ -7,7 +7,6 @@ using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
using osuTK;
|
||||
|
||||
@ -15,22 +14,21 @@ namespace osu.Game.Overlays.BeatmapListing
|
||||
{
|
||||
public class BeatmapSearchMultipleSelectionFilterRow<T> : BeatmapSearchFilterRow<List<T>>
|
||||
{
|
||||
public new readonly BindableList<T> Current = new BindableList<T>();
|
||||
|
||||
private MultipleSelectionFilter filter;
|
||||
|
||||
public BeatmapSearchMultipleSelectionFilterRow(string headerName)
|
||||
: base(headerName)
|
||||
{
|
||||
Current.BindTo(filter.Current);
|
||||
}
|
||||
|
||||
protected override Drawable CreateFilter() => new MultipleSelectionFilter();
|
||||
protected override Drawable CreateFilter() => filter = new MultipleSelectionFilter();
|
||||
|
||||
private class MultipleSelectionFilter : FillFlowContainer<MultipleSelectionFilterTabItem>, IHasCurrentValue<List<T>>
|
||||
private class MultipleSelectionFilter : FillFlowContainer<MultipleSelectionFilterTabItem>
|
||||
{
|
||||
private readonly BindableWithCurrent<List<T>> current = new BindableWithCurrent<List<T>>();
|
||||
|
||||
public Bindable<List<T>> Current
|
||||
{
|
||||
get => current.Current;
|
||||
set => current.Current = value;
|
||||
}
|
||||
public readonly BindableList<T> Current = new BindableList<T>();
|
||||
|
||||
public MultipleSelectionFilter()
|
||||
{
|
||||
@ -43,20 +41,15 @@ namespace osu.Game.Overlays.BeatmapListing
|
||||
((T[])Enum.GetValues(typeof(T))).ForEach(i => Add(new MultipleSelectionFilterTabItem(i)));
|
||||
|
||||
foreach (var item in Children)
|
||||
item.Active.BindValueChanged(_ => updateBindable());
|
||||
item.Active.BindValueChanged(active => updateBindable(item.Value, active.NewValue));
|
||||
}
|
||||
|
||||
private void updateBindable()
|
||||
private void updateBindable(T value, bool active)
|
||||
{
|
||||
var selectedValues = new List<T>();
|
||||
|
||||
foreach (var item in Children)
|
||||
{
|
||||
if (item.Active.Value)
|
||||
selectedValues.Add(item.Value);
|
||||
}
|
||||
|
||||
Current.Value = selectedValues;
|
||||
if (active)
|
||||
Current.Add(value);
|
||||
else
|
||||
Current.Remove(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user