1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 14:42:56 +08:00

Refactor InitialRoomsReceived to avoid extra bindables

This commit is contained in:
smoogipoo 2020-12-20 23:05:17 +09:00
parent 45107280a0
commit c33e693b8e
8 changed files with 24 additions and 17 deletions

View File

@ -18,7 +18,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
public readonly BindableList<Room> Rooms = new BindableList<Room>();
public Bindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
public IBindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
IBindableList<Room> IRoomManager.Rooms => Rooms;

View File

@ -131,7 +131,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
remove { }
}
public Bindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
public IBindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
public IBindableList<Room> Rooms => null;

View File

@ -151,7 +151,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
remove => throw new NotImplementedException();
}
public Bindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
public IBindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
public IBindableList<Room> Rooms { get; } = new BindableList<Room>();

View File

@ -25,8 +25,7 @@ namespace osu.Game.Screens.Multi.Components
{
currentFilter.BindValueChanged(_ =>
{
InitialRoomsReceived.Value = false;
NotifyRoomsReceived(null);
if (IsLoaded)
PollImmediately();
});

View File

@ -23,7 +23,8 @@ namespace osu.Game.Screens.Multi.Components
private readonly BindableList<Room> rooms = new BindableList<Room>();
public Bindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>();
public IBindable<bool> InitialRoomsReceived => initialRoomsReceived;
private readonly Bindable<bool> initialRoomsReceived = new Bindable<bool>();
public IBindableList<Room> Rooms => rooms;
@ -44,7 +45,6 @@ namespace osu.Game.Screens.Multi.Components
InternalChildren = CreatePollingComponents().Select(p =>
{
p.InitialRoomsReceived.BindTo(InitialRoomsReceived);
p.RoomsReceived = onRoomsReceived;
return p;
}).ToList();
@ -122,6 +122,13 @@ namespace osu.Game.Screens.Multi.Components
private void onRoomsReceived(List<Room> received)
{
if (received == null)
{
rooms.Clear();
initialRoomsReceived.Value = false;
return;
}
// Remove past matches
foreach (var r in rooms.ToList())
{
@ -155,6 +162,7 @@ namespace osu.Game.Screens.Multi.Components
}
RoomsUpdated?.Invoke();
initialRoomsReceived.Value = true;
}
/// <summary>

View File

@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Online;
using osu.Game.Online.API;
using osu.Game.Online.Multiplayer;
@ -13,17 +12,18 @@ namespace osu.Game.Screens.Multi.Components
{
public abstract class RoomPollingComponent : PollingComponent
{
/// <summary>
/// Invoked when any <see cref="Room"/>s have been received from the API.
/// <para>
/// Any <see cref="Room"/>s present locally but not returned by this event are to be removed from display.
/// If null, the display of local rooms is reset to an initial state.
/// </para>
/// </summary>
public Action<List<Room>> RoomsReceived;
public readonly Bindable<bool> InitialRoomsReceived = new Bindable<bool>();
[Resolved]
protected IAPIProvider API { get; private set; }
protected void NotifyRoomsReceived(List<Room> rooms)
{
InitialRoomsReceived.Value = true;
RoomsReceived?.Invoke(rooms);
}
protected void NotifyRoomsReceived(List<Room> rooms) => RoomsReceived?.Invoke(rooms);
}
}

View File

@ -19,7 +19,7 @@ namespace osu.Game.Screens.Multi
/// <summary>
/// Whether an initial listing of rooms has been received.
/// </summary>
Bindable<bool> InitialRoomsReceived { get; }
IBindable<bool> InitialRoomsReceived { get; }
/// <summary>
/// All the active <see cref="Room"/>s.

View File

@ -27,7 +27,7 @@ namespace osu.Game.Screens.Multi.Lounge
protected override UserActivity InitialActivity => new UserActivity.SearchingForLobby();
private readonly Bindable<bool> initialRoomsReceived = new Bindable<bool>();
private readonly IBindable<bool> initialRoomsReceived = new Bindable<bool>();
private Container content;
private LoadingLayer loadingLayer;