mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 22:22:54 +08:00
Refactor / cleanup debouncing
This commit is contained in:
parent
10287eb66d
commit
0cbe29dbec
@ -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
|
||||||
|
@ -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)
|
||||||
|
@ -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>
|
||||||
|
Loading…
Reference in New Issue
Block a user