1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 01:43:20 +08:00

Refactor / cleanup debouncing

This commit is contained in:
smoogipoo 2019-11-21 11:05:18 +09:00
parent 10287eb66d
commit 0cbe29dbec
3 changed files with 14 additions and 28 deletions

View File

@ -4,6 +4,7 @@
using System.ComponentModel; using System.ComponentModel;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Threading;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Overlays.SearchableList; using osu.Game.Overlays.SearchableList;
using osuTK.Graphics; using osuTK.Graphics;
@ -37,10 +38,18 @@ namespace osu.Game.Screens.Multi.Lounge.Components
{ {
base.LoadComplete(); base.LoadComplete();
Search.Current.BindValueChanged(_ => updateFilter()); Search.Current.BindValueChanged(_ => scheduleUpdateFilter());
Tabs.Current.BindValueChanged(_ => updateFilter(), true); Tabs.Current.BindValueChanged(_ => updateFilter(), true);
} }
private ScheduledDelegate scheduledFilterUpdate;
private void scheduleUpdateFilter()
{
scheduledFilterUpdate?.Cancel();
scheduledFilterUpdate = Scheduler.AddDelayed(updateFilter, 200);
}
private void updateFilter() private void updateFilter()
{ {
filter.Value = new FilterCriteria filter.Value = new FilterCriteria

View File

@ -9,7 +9,6 @@ using osu.Framework.Bindables;
using osu.Framework.Extensions.IEnumerableExtensions; 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.Threading;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
using osuTK; using osuTK;
@ -63,10 +62,7 @@ namespace osu.Game.Screens.Multi.Lounge.Components
protected override void LoadComplete() protected override void LoadComplete()
{ {
filter?.BindValueChanged(f => scheduleFilter()); filter?.BindValueChanged(f => Filter(f.NewValue), true);
if (filter != null)
Filter(filter.Value);
} }
public void Filter(FilterCriteria criteria) 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) private void addRooms(IEnumerable<Room> rooms)
{ {
foreach (var r in rooms) foreach (var r in rooms)
roomFlow.Add(new DrawableRoom(r) { Action = () => selectRoom(r) }); roomFlow.Add(new DrawableRoom(r) { Action = () => selectRoom(r) });
filter?.TriggerChange(); if (filter != null)
Filter(filter.Value);
} }
private void removeRooms(IEnumerable<Room> rooms) private void removeRooms(IEnumerable<Room> rooms)

View File

@ -7,7 +7,6 @@ using System.Threading.Tasks;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Logging; using osu.Framework.Logging;
using osu.Framework.Threading;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Online; using osu.Game.Online;
using osu.Game.Online.API; using osu.Game.Online.API;
@ -45,7 +44,7 @@ namespace osu.Game.Screens.Multi
currentFilter.BindValueChanged(_ => currentFilter.BindValueChanged(_ =>
{ {
if (IsLoaded) if (IsLoaded)
schedulePoll(); PollImmediately();
}); });
} }
@ -158,14 +157,6 @@ namespace osu.Game.Screens.Multi
return tcs.Task; return tcs.Task;
} }
private ScheduledDelegate scheduledPoll;
private void schedulePoll()
{
scheduledPoll?.Cancel();
scheduledPoll = Scheduler.AddDelayed(PollImmediately, 200);
}
/// <summary> /// <summary>
/// Updates a local <see cref="Room"/> with a remote copy. /// Updates a local <see cref="Room"/> with a remote copy.
/// </summary> /// </summary>