Hook up multiplayer search filter (#6857)

Hook up multiplayer search filter

Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
Dean Herbert 2019-11-21 14:14:24 +09:00 committed by GitHub
commit f6b25ba2f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 8 deletions

View File

@ -74,7 +74,9 @@ public bool MatchingFilter
set
{
matchingFilter = value;
this.FadeTo(MatchingFilter ? 1 : 0, 200);
if (IsLoaded)
this.FadeTo(MatchingFilter ? 1 : 0, 200);
}
}
@ -203,7 +205,11 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
protected override void LoadComplete()
{
base.LoadComplete();
this.FadeInFromZero(transition_duration);
if (matchingFilter)
this.FadeInFromZero(transition_duration);
else
Alpha = 0;
}
private class RoomName : OsuSpriteText

View File

@ -4,6 +4,7 @@
using System.ComponentModel;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Threading;
using osu.Game.Graphics;
using osu.Game.Overlays.SearchableList;
using osuTK.Graphics;
@ -37,12 +38,22 @@ protected override void LoadComplete()
{
base.LoadComplete();
Search.Current.BindValueChanged(_ => updateFilter());
Search.Current.BindValueChanged(_ => scheduleUpdateFilter());
Tabs.Current.BindValueChanged(_ => updateFilter(), true);
}
private ScheduledDelegate scheduledFilterUpdate;
private void scheduleUpdateFilter()
{
scheduledFilterUpdate?.Cancel();
scheduledFilterUpdate = Scheduler.AddDelayed(updateFilter, 200);
}
private void updateFilter()
{
scheduledFilterUpdate?.Cancel();
filter.Value = new FilterCriteria
{
SearchString = Search.Current.Value ?? string.Empty,

View File

@ -24,6 +24,9 @@ public class RoomsContainer : CompositeDrawable
private readonly FillFlowContainer<DrawableRoom> roomFlow;
public IReadOnlyList<DrawableRoom> Rooms => roomFlow;
[Resolved(CanBeNull = true)]
private Bindable<FilterCriteria> filter { get; set; }
[Resolved]
private Bindable<Room> currentRoom { get; set; }
@ -57,7 +60,10 @@ private void load()
addRooms(rooms);
}
private FilterCriteria currentFilter;
protected override void LoadComplete()
{
filter?.BindValueChanged(f => Filter(f.NewValue), true);
}
public void Filter(FilterCriteria criteria)
{
@ -74,15 +80,13 @@ public void Filter(FilterCriteria criteria)
{
default:
case SecondaryFilter.Public:
r.MatchingFilter = r.Room.Availability.Value == RoomAvailability.Public;
matchingFilter &= r.Room.Availability.Value == RoomAvailability.Public;
break;
}
r.MatchingFilter = matchingFilter;
}
});
currentFilter = criteria;
}
private void addRooms(IEnumerable<Room> rooms)
@ -90,7 +94,8 @@ private void addRooms(IEnumerable<Room> rooms)
foreach (var r in rooms)
roomFlow.Add(new DrawableRoom(r) { Action = () => selectRoom(r) });
Filter(currentFilter);
if (filter != null)
Filter(filter.Value);
}
private void removeRooms(IEnumerable<Room> rooms)