mirror of
https://github.com/ppy/osu.git
synced 2025-02-16 00:22:58 +08:00
Refactor InitialRoomsReceived to avoid extra bindables
This commit is contained in:
parent
45107280a0
commit
c33e693b8e
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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>();
|
||||
|
||||
|
@ -25,8 +25,7 @@ namespace osu.Game.Screens.Multi.Components
|
||||
{
|
||||
currentFilter.BindValueChanged(_ =>
|
||||
{
|
||||
InitialRoomsReceived.Value = false;
|
||||
|
||||
NotifyRoomsReceived(null);
|
||||
if (IsLoaded)
|
||||
PollImmediately();
|
||||
});
|
||||
|
@ -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>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user