mirror of
https://github.com/osukey/osukey.git
synced 2025-08-07 16:43:52 +09:00
Clear rooms and poll only when connected to multiplayer server
This commit is contained in:
@ -157,6 +157,12 @@ namespace osu.Game.Screens.Multi.Components
|
|||||||
RoomsUpdated?.Invoke();
|
RoomsUpdated?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void ClearRooms()
|
||||||
|
{
|
||||||
|
rooms.Clear();
|
||||||
|
InitialRoomsReceived.Value = false;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates a local <see cref="Room"/> with a remote copy.
|
/// Updates a local <see cref="Room"/> with a remote copy.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -5,6 +5,7 @@ using System;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Online.RealtimeMultiplayer;
|
using osu.Game.Online.RealtimeMultiplayer;
|
||||||
@ -17,6 +18,22 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private StatefulMultiplayerClient multiplayerClient { get; set; }
|
private StatefulMultiplayerClient multiplayerClient { get; set; }
|
||||||
|
|
||||||
|
public readonly Bindable<double> TimeBetweenListingPolls = new Bindable<double>();
|
||||||
|
public readonly Bindable<double> TimeBetweenSelectionPolls = new Bindable<double>();
|
||||||
|
private readonly IBindable<bool> isConnected = new Bindable<bool>();
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
isConnected.BindTo(multiplayerClient.IsConnected);
|
||||||
|
isConnected.BindValueChanged(connected => Schedule(() =>
|
||||||
|
{
|
||||||
|
if (!connected.NewValue)
|
||||||
|
ClearRooms();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
public override void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
|
public override void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
|
||||||
=> base.CreateRoom(room, r => joinMultiplayerRoom(r, onSuccess), onError);
|
=> base.CreateRoom(room, r => joinMultiplayerRoom(r, onSuccess), onError);
|
||||||
|
|
||||||
@ -39,7 +56,52 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
|
|||||||
|
|
||||||
protected override RoomPollingComponent[] CreatePollingComponents() => new RoomPollingComponent[]
|
protected override RoomPollingComponent[] CreatePollingComponents() => new RoomPollingComponent[]
|
||||||
{
|
{
|
||||||
new ListingPollingComponent()
|
new RealtimeListingPollingComponent
|
||||||
|
{
|
||||||
|
TimeBetweenPolls = { BindTarget = TimeBetweenListingPolls },
|
||||||
|
AllowPolling = { BindTarget = isConnected }
|
||||||
|
},
|
||||||
|
new RealtimeSelectionPollingComponent
|
||||||
|
{
|
||||||
|
TimeBetweenPolls = { BindTarget = TimeBetweenSelectionPolls },
|
||||||
|
AllowPolling = { BindTarget = isConnected }
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private class RealtimeListingPollingComponent : ListingPollingComponent
|
||||||
|
{
|
||||||
|
public readonly IBindable<bool> AllowPolling = new Bindable<bool>();
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
AllowPolling.BindValueChanged(_ =>
|
||||||
|
{
|
||||||
|
if (IsLoaded)
|
||||||
|
PollImmediately();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Task Poll() => !AllowPolling.Value ? Task.CompletedTask : base.Poll();
|
||||||
|
}
|
||||||
|
|
||||||
|
private class RealtimeSelectionPollingComponent : SelectionPollingComponent
|
||||||
|
{
|
||||||
|
public readonly IBindable<bool> AllowPolling = new Bindable<bool>();
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
AllowPolling.BindValueChanged(_ =>
|
||||||
|
{
|
||||||
|
if (IsLoaded)
|
||||||
|
PollImmediately();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Task Poll() => !AllowPolling.Value ? Task.CompletedTask : base.Poll();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user