mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:47:26 +08:00
Refactor / cleanup debouncing
This commit is contained in:
parent
10287eb66d
commit
0cbe29dbec
@ -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,10 +38,18 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
{
|
||||
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()
|
||||
{
|
||||
filter.Value = new FilterCriteria
|
||||
|
@ -9,7 +9,6 @@ using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osuTK;
|
||||
@ -63,10 +62,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
filter?.BindValueChanged(f => scheduleFilter());
|
||||
|
||||
if (filter != null)
|
||||
Filter(filter.Value);
|
||||
filter?.BindValueChanged(f => Filter(f.NewValue), true);
|
||||
}
|
||||
|
||||
public void Filter(FilterCriteria criteria)
|
||||
@ -93,23 +89,13 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
});
|
||||
}
|
||||
|
||||
private ScheduledDelegate scheduledFilter;
|
||||
|
||||
private void scheduleFilter()
|
||||
{
|
||||
if (filter == null)
|
||||
return;
|
||||
|
||||
scheduledFilter?.Cancel();
|
||||
scheduledFilter = Scheduler.AddDelayed(() => Filter(filter.Value), 200);
|
||||
}
|
||||
|
||||
private void addRooms(IEnumerable<Room> rooms)
|
||||
{
|
||||
foreach (var r in rooms)
|
||||
roomFlow.Add(new DrawableRoom(r) { Action = () => selectRoom(r) });
|
||||
|
||||
filter?.TriggerChange();
|
||||
if (filter != null)
|
||||
Filter(filter.Value);
|
||||
}
|
||||
|
||||
private void removeRooms(IEnumerable<Room> rooms)
|
||||
|
@ -7,7 +7,6 @@ using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online;
|
||||
using osu.Game.Online.API;
|
||||
@ -45,7 +44,7 @@ namespace osu.Game.Screens.Multi
|
||||
currentFilter.BindValueChanged(_ =>
|
||||
{
|
||||
if (IsLoaded)
|
||||
schedulePoll();
|
||||
PollImmediately();
|
||||
});
|
||||
}
|
||||
|
||||
@ -158,14 +157,6 @@ namespace osu.Game.Screens.Multi
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
private ScheduledDelegate scheduledPoll;
|
||||
|
||||
private void schedulePoll()
|
||||
{
|
||||
scheduledPoll?.Cancel();
|
||||
scheduledPoll = Scheduler.AddDelayed(PollImmediately, 200);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates a local <see cref="Room"/> with a remote copy.
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user