mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 08:49:59 +09:00
Refactor InitialRoomsReceived to avoid extra bindables
This commit is contained in:
@ -18,7 +18,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
public readonly BindableList<Room> Rooms = new BindableList<Room>();
|
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;
|
IBindableList<Room> IRoomManager.Rooms => Rooms;
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
remove { }
|
remove { }
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
|
public IBindable<bool> InitialRoomsReceived { get; } = new Bindable<bool>(true);
|
||||||
|
|
||||||
public IBindableList<Room> Rooms => null;
|
public IBindableList<Room> Rooms => null;
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
remove => throw new NotImplementedException();
|
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>();
|
public IBindableList<Room> Rooms { get; } = new BindableList<Room>();
|
||||||
|
|
||||||
|
@ -25,8 +25,7 @@ namespace osu.Game.Screens.Multi.Components
|
|||||||
{
|
{
|
||||||
currentFilter.BindValueChanged(_ =>
|
currentFilter.BindValueChanged(_ =>
|
||||||
{
|
{
|
||||||
InitialRoomsReceived.Value = false;
|
NotifyRoomsReceived(null);
|
||||||
|
|
||||||
if (IsLoaded)
|
if (IsLoaded)
|
||||||
PollImmediately();
|
PollImmediately();
|
||||||
});
|
});
|
||||||
|
@ -23,7 +23,8 @@ namespace osu.Game.Screens.Multi.Components
|
|||||||
|
|
||||||
private readonly BindableList<Room> rooms = new BindableList<Room>();
|
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;
|
public IBindableList<Room> Rooms => rooms;
|
||||||
|
|
||||||
@ -44,7 +45,6 @@ namespace osu.Game.Screens.Multi.Components
|
|||||||
|
|
||||||
InternalChildren = CreatePollingComponents().Select(p =>
|
InternalChildren = CreatePollingComponents().Select(p =>
|
||||||
{
|
{
|
||||||
p.InitialRoomsReceived.BindTo(InitialRoomsReceived);
|
|
||||||
p.RoomsReceived = onRoomsReceived;
|
p.RoomsReceived = onRoomsReceived;
|
||||||
return p;
|
return p;
|
||||||
}).ToList();
|
}).ToList();
|
||||||
@ -122,6 +122,13 @@ namespace osu.Game.Screens.Multi.Components
|
|||||||
|
|
||||||
private void onRoomsReceived(List<Room> received)
|
private void onRoomsReceived(List<Room> received)
|
||||||
{
|
{
|
||||||
|
if (received == null)
|
||||||
|
{
|
||||||
|
rooms.Clear();
|
||||||
|
initialRoomsReceived.Value = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove past matches
|
// Remove past matches
|
||||||
foreach (var r in rooms.ToList())
|
foreach (var r in rooms.ToList())
|
||||||
{
|
{
|
||||||
@ -155,6 +162,7 @@ namespace osu.Game.Screens.Multi.Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
RoomsUpdated?.Invoke();
|
RoomsUpdated?.Invoke();
|
||||||
|
initialRoomsReceived.Value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Game.Online;
|
using osu.Game.Online;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
@ -13,17 +12,18 @@ namespace osu.Game.Screens.Multi.Components
|
|||||||
{
|
{
|
||||||
public abstract class RoomPollingComponent : PollingComponent
|
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 Action<List<Room>> RoomsReceived;
|
||||||
|
|
||||||
public readonly Bindable<bool> InitialRoomsReceived = new Bindable<bool>();
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
protected IAPIProvider API { get; private set; }
|
protected IAPIProvider API { get; private set; }
|
||||||
|
|
||||||
protected void NotifyRoomsReceived(List<Room> rooms)
|
protected void NotifyRoomsReceived(List<Room> rooms) => RoomsReceived?.Invoke(rooms);
|
||||||
{
|
|
||||||
InitialRoomsReceived.Value = true;
|
|
||||||
RoomsReceived?.Invoke(rooms);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ namespace osu.Game.Screens.Multi
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether an initial listing of rooms has been received.
|
/// Whether an initial listing of rooms has been received.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Bindable<bool> InitialRoomsReceived { get; }
|
IBindable<bool> InitialRoomsReceived { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All the active <see cref="Room"/>s.
|
/// All the active <see cref="Room"/>s.
|
||||||
|
@ -27,7 +27,7 @@ namespace osu.Game.Screens.Multi.Lounge
|
|||||||
|
|
||||||
protected override UserActivity InitialActivity => new UserActivity.SearchingForLobby();
|
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 Container content;
|
||||||
private LoadingLayer loadingLayer;
|
private LoadingLayer loadingLayer;
|
||||||
|
Reference in New Issue
Block a user