mirror of
https://github.com/ppy/osu.git
synced 2024-12-16 00:02:54 +08:00
Merge pull request #14274 from smoogipoo/multi-polling-request-refactor
Refactor multiplayer/playlist polling out of RoomManager
This commit is contained in:
commit
4b55ba7fa4
@ -74,7 +74,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
var room = RoomManager.Rooms[1];
|
var room = RoomManager.Rooms[1];
|
||||||
|
|
||||||
RoomManager.RemoveRoom(room);
|
RoomManager.RemoveRoom(room);
|
||||||
RoomManager.AddRoom(room);
|
RoomManager.AddOrUpdateRoom(room);
|
||||||
});
|
});
|
||||||
|
|
||||||
AddAssert("no selection", () => checkRoomSelected(null));
|
AddAssert("no selection", () => checkRoomSelected(null));
|
||||||
@ -115,11 +115,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
AddUntilStep("4 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 4);
|
AddUntilStep("4 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 4);
|
||||||
|
|
||||||
AddStep("filter one room", () => container.Filter(new FilterCriteria { SearchString = "1" }));
|
AddStep("filter one room", () => container.Filter.Value = new FilterCriteria { SearchString = "1" });
|
||||||
|
|
||||||
AddUntilStep("1 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 1);
|
AddUntilStep("1 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 1);
|
||||||
|
|
||||||
AddStep("remove filter", () => container.Filter(null));
|
AddStep("remove filter", () => container.Filter.Value = null);
|
||||||
|
|
||||||
AddUntilStep("4 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 4);
|
AddUntilStep("4 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 4);
|
||||||
}
|
}
|
||||||
@ -131,13 +131,13 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
AddStep("add rooms", () => RoomManager.AddRooms(3, new CatchRuleset().RulesetInfo));
|
AddStep("add rooms", () => RoomManager.AddRooms(3, new CatchRuleset().RulesetInfo));
|
||||||
|
|
||||||
// Todo: What even is this case...?
|
// Todo: What even is this case...?
|
||||||
AddStep("set empty filter criteria", () => container.Filter(null));
|
AddStep("set empty filter criteria", () => container.Filter.Value = null);
|
||||||
AddUntilStep("5 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 5);
|
AddUntilStep("5 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 5);
|
||||||
|
|
||||||
AddStep("filter osu! rooms", () => container.Filter(new FilterCriteria { Ruleset = new OsuRuleset().RulesetInfo }));
|
AddStep("filter osu! rooms", () => container.Filter.Value = new FilterCriteria { Ruleset = new OsuRuleset().RulesetInfo });
|
||||||
AddUntilStep("2 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 2);
|
AddUntilStep("2 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 2);
|
||||||
|
|
||||||
AddStep("filter catch rooms", () => container.Filter(new FilterCriteria { Ruleset = new CatchRuleset().RulesetInfo }));
|
AddStep("filter catch rooms", () => container.Filter.Value = new FilterCriteria { Ruleset = new CatchRuleset().RulesetInfo });
|
||||||
AddUntilStep("3 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 3);
|
AddUntilStep("3 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
private TestMultiplayer multiplayerScreen;
|
private TestMultiplayer multiplayerScreen;
|
||||||
private TestMultiplayerClient client;
|
private TestMultiplayerClient client;
|
||||||
|
|
||||||
|
private TestRequestHandlingMultiplayerRoomManager roomManager => multiplayerScreen.RoomManager;
|
||||||
|
|
||||||
[Cached(typeof(UserLookupCache))]
|
[Cached(typeof(UserLookupCache))]
|
||||||
private UserLookupCache lookupCache = new TestUserLookupCache();
|
private UserLookupCache lookupCache = new TestUserLookupCache();
|
||||||
|
|
||||||
@ -68,7 +70,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
AddStep("load dependencies", () =>
|
AddStep("load dependencies", () =>
|
||||||
{
|
{
|
||||||
client = new TestMultiplayerClient(multiplayerScreen.RoomManager);
|
client = new TestMultiplayerClient(roomManager);
|
||||||
|
|
||||||
// The screen gets suspended so it stops receiving updates.
|
// The screen gets suspended so it stops receiving updates.
|
||||||
Child = client;
|
Child = client;
|
||||||
@ -132,11 +134,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
[Test]
|
[Test]
|
||||||
public void TestExitMidJoin()
|
public void TestExitMidJoin()
|
||||||
{
|
{
|
||||||
Room room = null;
|
|
||||||
|
|
||||||
AddStep("create room", () =>
|
AddStep("create room", () =>
|
||||||
{
|
{
|
||||||
room = new Room
|
roomManager.AddServerSideRoom(new Room
|
||||||
{
|
{
|
||||||
Name = { Value = "Test Room" },
|
Name = { Value = "Test Room" },
|
||||||
Playlist =
|
Playlist =
|
||||||
@ -147,14 +147,16 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("refresh rooms", () => multiplayerScreen.RoomManager.Filter.Value = new FilterCriteria());
|
AddStep("refresh rooms", () => this.ChildrenOfType<LoungeSubScreen>().Single().UpdateFilter());
|
||||||
|
AddUntilStep("wait for room", () => this.ChildrenOfType<DrawableRoom>().Any());
|
||||||
|
|
||||||
AddStep("select room", () => InputManager.Key(Key.Down));
|
AddStep("select room", () => InputManager.Key(Key.Down));
|
||||||
AddStep("join room and immediately exit", () =>
|
AddStep("join room and immediately exit select", () =>
|
||||||
{
|
{
|
||||||
multiplayerScreen.ChildrenOfType<LoungeSubScreen>().Single().Open(room);
|
InputManager.Key(Key.Enter);
|
||||||
Schedule(() => Stack.CurrentScreen.Exit());
|
Schedule(() => Stack.CurrentScreen.Exit());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -164,7 +166,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
{
|
{
|
||||||
AddStep("create room", () =>
|
AddStep("create room", () =>
|
||||||
{
|
{
|
||||||
multiplayerScreen.RoomManager.AddRoom(new Room
|
roomManager.AddServerSideRoom(new Room
|
||||||
{
|
{
|
||||||
Name = { Value = "Test Room" },
|
Name = { Value = "Test Room" },
|
||||||
Playlist =
|
Playlist =
|
||||||
@ -178,7 +180,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("refresh rooms", () => multiplayerScreen.RoomManager.Filter.Value = new FilterCriteria());
|
AddStep("refresh rooms", () => this.ChildrenOfType<LoungeSubScreen>().Single().UpdateFilter());
|
||||||
|
AddUntilStep("wait for room", () => this.ChildrenOfType<DrawableRoom>().Any());
|
||||||
|
|
||||||
AddStep("select room", () => InputManager.Key(Key.Down));
|
AddStep("select room", () => InputManager.Key(Key.Down));
|
||||||
AddStep("join room", () => InputManager.Key(Key.Enter));
|
AddStep("join room", () => InputManager.Key(Key.Enter));
|
||||||
|
|
||||||
@ -211,7 +215,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
{
|
{
|
||||||
AddStep("create room", () =>
|
AddStep("create room", () =>
|
||||||
{
|
{
|
||||||
multiplayerScreen.RoomManager.AddRoom(new Room
|
roomManager.AddServerSideRoom(new Room
|
||||||
{
|
{
|
||||||
Name = { Value = "Test Room" },
|
Name = { Value = "Test Room" },
|
||||||
Password = { Value = "password" },
|
Password = { Value = "password" },
|
||||||
@ -226,7 +230,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
AddStep("refresh rooms", () => multiplayerScreen.RoomManager.Filter.Value = new FilterCriteria());
|
AddStep("refresh rooms", () => this.ChildrenOfType<LoungeSubScreen>().Single().UpdateFilter());
|
||||||
|
AddUntilStep("wait for room", () => this.ChildrenOfType<DrawableRoom>().Any());
|
||||||
|
|
||||||
AddStep("select room", () => InputManager.Key(Key.Down));
|
AddStep("select room", () => InputManager.Key(Key.Down));
|
||||||
AddStep("join room", () => InputManager.Key(Key.Enter));
|
AddStep("join room", () => InputManager.Key(Key.Enter));
|
||||||
|
|
||||||
|
@ -1,157 +0,0 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using osu.Framework.Testing;
|
|
||||||
using osu.Game.Online.Rooms;
|
|
||||||
using osu.Game.Screens.OnlinePlay.Components;
|
|
||||||
using osu.Game.Tests.Beatmaps;
|
|
||||||
using osu.Game.Tests.Visual.OnlinePlay;
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Multiplayer
|
|
||||||
{
|
|
||||||
[HeadlessTest]
|
|
||||||
public class TestSceneMultiplayerRoomManager : MultiplayerTestScene
|
|
||||||
{
|
|
||||||
protected override OnlinePlayTestSceneDependencies CreateOnlinePlayDependencies() => new TestDependencies();
|
|
||||||
|
|
||||||
public TestSceneMultiplayerRoomManager()
|
|
||||||
: base(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestPollsInitially()
|
|
||||||
{
|
|
||||||
AddStep("create room manager with a few rooms", () =>
|
|
||||||
{
|
|
||||||
RoomManager.CreateRoom(createRoom(r => r.Name.Value = "1"));
|
|
||||||
RoomManager.PartRoom();
|
|
||||||
RoomManager.CreateRoom(createRoom(r => r.Name.Value = "2"));
|
|
||||||
RoomManager.PartRoom();
|
|
||||||
RoomManager.ClearRooms();
|
|
||||||
});
|
|
||||||
|
|
||||||
AddAssert("manager polled for rooms", () => ((RoomManager)RoomManager).Rooms.Count == 2);
|
|
||||||
AddAssert("initial rooms received", () => RoomManager.InitialRoomsReceived.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestRoomsClearedOnDisconnection()
|
|
||||||
{
|
|
||||||
AddStep("create room manager with a few rooms", () =>
|
|
||||||
{
|
|
||||||
RoomManager.CreateRoom(createRoom());
|
|
||||||
RoomManager.PartRoom();
|
|
||||||
RoomManager.CreateRoom(createRoom());
|
|
||||||
RoomManager.PartRoom();
|
|
||||||
});
|
|
||||||
|
|
||||||
AddStep("disconnect", () => Client.Disconnect());
|
|
||||||
|
|
||||||
AddAssert("rooms cleared", () => ((RoomManager)RoomManager).Rooms.Count == 0);
|
|
||||||
AddAssert("initial rooms not received", () => !RoomManager.InitialRoomsReceived.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestRoomsPolledOnReconnect()
|
|
||||||
{
|
|
||||||
AddStep("create room manager with a few rooms", () =>
|
|
||||||
{
|
|
||||||
RoomManager.CreateRoom(createRoom());
|
|
||||||
RoomManager.PartRoom();
|
|
||||||
RoomManager.CreateRoom(createRoom());
|
|
||||||
RoomManager.PartRoom();
|
|
||||||
});
|
|
||||||
|
|
||||||
AddStep("disconnect", () => Client.Disconnect());
|
|
||||||
AddStep("connect", () => Client.Connect());
|
|
||||||
|
|
||||||
AddAssert("manager polled for rooms", () => ((RoomManager)RoomManager).Rooms.Count == 2);
|
|
||||||
AddAssert("initial rooms received", () => RoomManager.InitialRoomsReceived.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestRoomsNotPolledWhenJoined()
|
|
||||||
{
|
|
||||||
AddStep("create room manager with a room", () =>
|
|
||||||
{
|
|
||||||
RoomManager.CreateRoom(createRoom());
|
|
||||||
RoomManager.ClearRooms();
|
|
||||||
});
|
|
||||||
|
|
||||||
AddAssert("manager not polled for rooms", () => ((RoomManager)RoomManager).Rooms.Count == 0);
|
|
||||||
AddAssert("initial rooms not received", () => !RoomManager.InitialRoomsReceived.Value);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestMultiplayerRoomJoinedWhenCreated()
|
|
||||||
{
|
|
||||||
AddStep("create room manager with a room", () =>
|
|
||||||
{
|
|
||||||
RoomManager.CreateRoom(createRoom());
|
|
||||||
});
|
|
||||||
|
|
||||||
AddUntilStep("multiplayer room joined", () => Client.Room != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestMultiplayerRoomPartedWhenAPIRoomParted()
|
|
||||||
{
|
|
||||||
AddStep("create room manager with a room", () =>
|
|
||||||
{
|
|
||||||
RoomManager.CreateRoom(createRoom());
|
|
||||||
RoomManager.PartRoom();
|
|
||||||
});
|
|
||||||
|
|
||||||
AddAssert("multiplayer room parted", () => Client.Room == null);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void TestMultiplayerRoomJoinedWhenAPIRoomJoined()
|
|
||||||
{
|
|
||||||
AddStep("create room manager with a room", () =>
|
|
||||||
{
|
|
||||||
var r = createRoom();
|
|
||||||
RoomManager.CreateRoom(r);
|
|
||||||
RoomManager.PartRoom();
|
|
||||||
RoomManager.JoinRoom(r);
|
|
||||||
});
|
|
||||||
|
|
||||||
AddUntilStep("multiplayer room joined", () => Client.Room != null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Room createRoom(Action<Room> initFunc = null)
|
|
||||||
{
|
|
||||||
var room = new Room
|
|
||||||
{
|
|
||||||
Name =
|
|
||||||
{
|
|
||||||
Value = "test room"
|
|
||||||
},
|
|
||||||
Playlist =
|
|
||||||
{
|
|
||||||
new PlaylistItem
|
|
||||||
{
|
|
||||||
Beatmap = { Value = new TestBeatmap(Ruleset.Value).BeatmapInfo },
|
|
||||||
Ruleset = { Value = Ruleset.Value }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
initFunc?.Invoke(room);
|
|
||||||
return room;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TestDependencies : MultiplayerTestSceneDependencies
|
|
||||||
{
|
|
||||||
public TestDependencies()
|
|
||||||
{
|
|
||||||
// Need to set these values as early as possible.
|
|
||||||
RoomManager.TimeBetweenListingPolls.Value = 1;
|
|
||||||
RoomManager.TimeBetweenSelectionPolls.Value = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -141,6 +141,12 @@ namespace osu.Game.Tests.Visual.Playlists
|
|||||||
|
|
||||||
public IBindableList<Room> Rooms => null;
|
public IBindableList<Room> Rooms => null;
|
||||||
|
|
||||||
|
public void AddOrUpdateRoom(Room room) => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public void RemoveRoom(Room room) => throw new NotImplementedException();
|
||||||
|
|
||||||
|
public void ClearRooms() => throw new NotImplementedException();
|
||||||
|
|
||||||
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
|
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
|
||||||
{
|
{
|
||||||
if (CreateRequested == null)
|
if (CreateRequested == null)
|
||||||
|
@ -47,39 +47,13 @@ namespace osu.Game.Online
|
|||||||
pollIfNecessary();
|
pollIfNecessary();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool pollIfNecessary()
|
/// <summary>
|
||||||
|
/// Immediately performs a <see cref="Poll"/>.
|
||||||
|
/// </summary>
|
||||||
|
public void PollImmediately()
|
||||||
{
|
{
|
||||||
// we must be loaded so we have access to clock.
|
lastTimePolled = Time.Current - TimeBetweenPolls.Value;
|
||||||
if (!IsLoaded) return false;
|
|
||||||
|
|
||||||
// there's already a poll process running.
|
|
||||||
if (pollingActive) return false;
|
|
||||||
|
|
||||||
// don't try polling if the time between polls hasn't been set.
|
|
||||||
if (TimeBetweenPolls.Value == 0) return false;
|
|
||||||
|
|
||||||
if (!lastTimePolled.HasValue)
|
|
||||||
{
|
|
||||||
doPoll();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Time.Current - lastTimePolled.Value > TimeBetweenPolls.Value)
|
|
||||||
{
|
|
||||||
doPoll();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// not enough time has passed since the last poll. we do want to schedule a poll to happen, though.
|
|
||||||
scheduleNextPoll();
|
scheduleNextPoll();
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doPoll()
|
|
||||||
{
|
|
||||||
scheduledPoll = null;
|
|
||||||
pollingActive = true;
|
|
||||||
Poll().ContinueWith(_ => pollComplete());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -90,13 +64,11 @@ namespace osu.Game.Online
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
private void doPoll()
|
||||||
/// Immediately performs a <see cref="Poll"/>.
|
|
||||||
/// </summary>
|
|
||||||
public void PollImmediately()
|
|
||||||
{
|
{
|
||||||
lastTimePolled = Time.Current - TimeBetweenPolls.Value;
|
scheduledPoll = null;
|
||||||
scheduleNextPoll();
|
pollingActive = true;
|
||||||
|
Poll().ContinueWith(_ => pollComplete());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -111,6 +83,33 @@ namespace osu.Game.Online
|
|||||||
pollIfNecessary();
|
pollIfNecessary();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void pollIfNecessary()
|
||||||
|
{
|
||||||
|
// we must be loaded so we have access to clock.
|
||||||
|
if (!IsLoaded) return;
|
||||||
|
|
||||||
|
// there's already a poll process running.
|
||||||
|
if (pollingActive) return;
|
||||||
|
|
||||||
|
// don't try polling if the time between polls hasn't been set.
|
||||||
|
if (TimeBetweenPolls.Value == 0) return;
|
||||||
|
|
||||||
|
if (!lastTimePolled.HasValue)
|
||||||
|
{
|
||||||
|
doPoll();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Time.Current - lastTimePolled.Value > TimeBetweenPolls.Value)
|
||||||
|
{
|
||||||
|
doPoll();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// not enough time has passed since the last poll. we do want to schedule a poll to happen, though.
|
||||||
|
scheduleNextPoll();
|
||||||
|
}
|
||||||
|
|
||||||
private void scheduleNextPoll()
|
private void scheduleNextPoll()
|
||||||
{
|
{
|
||||||
scheduledPoll?.Cancel();
|
scheduledPoll?.Cancel();
|
||||||
|
@ -134,7 +134,7 @@ namespace osu.Game.Online.Rooms
|
|||||||
/// The position of this <see cref="Room"/> in the list. This is not read from or written to the API.
|
/// The position of this <see cref="Room"/> in the list. This is not read from or written to the API.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public readonly Bindable<int> Position = new Bindable<int>(-1);
|
public readonly Bindable<long> Position = new Bindable<long>(-1); // Todo: This does not need to exist.
|
||||||
|
|
||||||
public Room()
|
public Room()
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
@ -14,8 +15,10 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ListingPollingComponent : RoomPollingComponent
|
public class ListingPollingComponent : RoomPollingComponent
|
||||||
{
|
{
|
||||||
[Resolved]
|
public IBindable<bool> InitialRoomsReceived => initialRoomsReceived;
|
||||||
private Bindable<FilterCriteria> currentFilter { get; set; }
|
private readonly Bindable<bool> initialRoomsReceived = new Bindable<bool>();
|
||||||
|
|
||||||
|
public readonly Bindable<FilterCriteria> Filter = new Bindable<FilterCriteria>();
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private Bindable<Room> selectedRoom { get; set; }
|
private Bindable<Room> selectedRoom { get; set; }
|
||||||
@ -23,9 +26,11 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
currentFilter.BindValueChanged(_ =>
|
Filter.BindValueChanged(_ =>
|
||||||
{
|
{
|
||||||
NotifyRoomsReceived(null);
|
RoomManager.ClearRooms();
|
||||||
|
initialRoomsReceived.Value = false;
|
||||||
|
|
||||||
if (IsLoaded)
|
if (IsLoaded)
|
||||||
PollImmediately();
|
PollImmediately();
|
||||||
});
|
});
|
||||||
@ -38,24 +43,26 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
if (!API.IsLoggedIn)
|
if (!API.IsLoggedIn)
|
||||||
return base.Poll();
|
return base.Poll();
|
||||||
|
|
||||||
|
if (Filter.Value == null)
|
||||||
|
return base.Poll();
|
||||||
|
|
||||||
var tcs = new TaskCompletionSource<bool>();
|
var tcs = new TaskCompletionSource<bool>();
|
||||||
|
|
||||||
pollReq?.Cancel();
|
pollReq?.Cancel();
|
||||||
pollReq = new GetRoomsRequest(currentFilter.Value.Status, currentFilter.Value.Category);
|
pollReq = new GetRoomsRequest(Filter.Value.Status, Filter.Value.Category);
|
||||||
|
|
||||||
pollReq.Success += result =>
|
pollReq.Success += result =>
|
||||||
{
|
{
|
||||||
for (int i = 0; i < result.Count; i++)
|
foreach (var existing in RoomManager.Rooms.ToArray())
|
||||||
{
|
{
|
||||||
if (result[i].RoomID.Value == selectedRoom.Value?.RoomID.Value)
|
if (result.All(r => r.RoomID.Value != existing.RoomID.Value))
|
||||||
{
|
RoomManager.RemoveRoom(existing);
|
||||||
// The listing request always has less information than the opened room, so don't include it.
|
|
||||||
result[i] = selectedRoom.Value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NotifyRoomsReceived(result);
|
foreach (var incoming in result)
|
||||||
|
RoomManager.AddOrUpdateRoom(incoming);
|
||||||
|
|
||||||
|
initialRoomsReceived.Value = true;
|
||||||
tcs.SetResult(true);
|
tcs.SetResult(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@ using System.Linq;
|
|||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
@ -17,15 +16,12 @@ using osu.Game.Rulesets;
|
|||||||
|
|
||||||
namespace osu.Game.Screens.OnlinePlay.Components
|
namespace osu.Game.Screens.OnlinePlay.Components
|
||||||
{
|
{
|
||||||
public abstract class RoomManager : CompositeDrawable, IRoomManager
|
public class RoomManager : Component, IRoomManager
|
||||||
{
|
{
|
||||||
public event Action RoomsUpdated;
|
public event Action RoomsUpdated;
|
||||||
|
|
||||||
private readonly BindableList<Room> rooms = new BindableList<Room>();
|
private readonly BindableList<Room> rooms = new BindableList<Room>();
|
||||||
|
|
||||||
public IBindable<bool> InitialRoomsReceived => initialRoomsReceived;
|
|
||||||
private readonly Bindable<bool> initialRoomsReceived = new Bindable<bool>();
|
|
||||||
|
|
||||||
public IBindableList<Room> Rooms => rooms;
|
public IBindableList<Room> Rooms => rooms;
|
||||||
|
|
||||||
protected IBindable<Room> JoinedRoom => joinedRoom;
|
protected IBindable<Room> JoinedRoom => joinedRoom;
|
||||||
@ -40,15 +36,9 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private IAPIProvider api { get; set; }
|
private IAPIProvider api { get; set; }
|
||||||
|
|
||||||
protected RoomManager()
|
public RoomManager()
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
|
||||||
InternalChildren = CreatePollingComponents().Select(p =>
|
|
||||||
{
|
|
||||||
p.RoomsReceived = onRoomsReceived;
|
|
||||||
return p;
|
|
||||||
}).ToList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
@ -67,10 +57,10 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
{
|
{
|
||||||
joinedRoom.Value = room;
|
joinedRoom.Value = room;
|
||||||
|
|
||||||
update(room, result);
|
AddOrUpdateRoom(result);
|
||||||
addRoom(room);
|
room.CopyFrom(result); // Also copy back to the source model, since this is likely to have been stored elsewhere.
|
||||||
|
|
||||||
RoomsUpdated?.Invoke();
|
// The server may not contain all properties (such as password), so invoke success with the given room.
|
||||||
onSuccess?.Invoke(room);
|
onSuccess?.Invoke(room);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -118,36 +108,25 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
|
|
||||||
private readonly HashSet<long> ignoredRooms = new HashSet<long>();
|
private readonly HashSet<long> ignoredRooms = new HashSet<long>();
|
||||||
|
|
||||||
private void onRoomsReceived(List<Room> received)
|
public void AddOrUpdateRoom(Room room)
|
||||||
{
|
{
|
||||||
if (received == null)
|
|
||||||
{
|
|
||||||
ClearRooms();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove past matches
|
|
||||||
foreach (var r in rooms.ToList())
|
|
||||||
{
|
|
||||||
if (received.All(e => e.RoomID.Value != r.RoomID.Value))
|
|
||||||
rooms.Remove(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < received.Count; i++)
|
|
||||||
{
|
|
||||||
var room = received[i];
|
|
||||||
|
|
||||||
Debug.Assert(room.RoomID.Value != null);
|
Debug.Assert(room.RoomID.Value != null);
|
||||||
|
|
||||||
if (ignoredRooms.Contains(room.RoomID.Value.Value))
|
if (ignoredRooms.Contains(room.RoomID.Value.Value))
|
||||||
continue;
|
return;
|
||||||
|
|
||||||
room.Position.Value = i;
|
room.Position.Value = -room.RoomID.Value.Value;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
update(room, room);
|
foreach (var pi in room.Playlist)
|
||||||
addRoom(room);
|
pi.MapObjects(beatmaps, rulesets);
|
||||||
|
|
||||||
|
var existing = rooms.FirstOrDefault(e => e.RoomID.Value == room.RoomID.Value);
|
||||||
|
if (existing == null)
|
||||||
|
rooms.Add(room);
|
||||||
|
else
|
||||||
|
existing.CopyFrom(room);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -156,46 +135,22 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
ignoredRooms.Add(room.RoomID.Value.Value);
|
ignoredRooms.Add(room.RoomID.Value.Value);
|
||||||
rooms.Remove(room);
|
rooms.Remove(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notifyRoomsUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
RoomsUpdated?.Invoke();
|
public void RemoveRoom(Room room)
|
||||||
initialRoomsReceived.Value = true;
|
{
|
||||||
|
rooms.Remove(room);
|
||||||
|
notifyRoomsUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void RemoveRoom(Room room) => rooms.Remove(room);
|
public void ClearRooms()
|
||||||
|
|
||||||
protected void ClearRooms()
|
|
||||||
{
|
{
|
||||||
rooms.Clear();
|
rooms.Clear();
|
||||||
initialRoomsReceived.Value = false;
|
notifyRoomsUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
private void notifyRoomsUpdated() => Scheduler.AddOnce(() => RoomsUpdated?.Invoke());
|
||||||
/// Updates a local <see cref="Room"/> with a remote copy.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="local">The local <see cref="Room"/> to update.</param>
|
|
||||||
/// <param name="remote">The remote <see cref="Room"/> to update with.</param>
|
|
||||||
private void update(Room local, Room remote)
|
|
||||||
{
|
|
||||||
foreach (var pi in remote.Playlist)
|
|
||||||
pi.MapObjects(beatmaps, rulesets);
|
|
||||||
|
|
||||||
local.CopyFrom(remote);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds a <see cref="Room"/> to the list of available rooms.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="room">The <see cref="Room"/> to add.</param>
|
|
||||||
private void addRoom(Room room)
|
|
||||||
{
|
|
||||||
var existing = rooms.FirstOrDefault(e => e.RoomID.Value == room.RoomID.Value);
|
|
||||||
if (existing == null)
|
|
||||||
rooms.Add(room);
|
|
||||||
else
|
|
||||||
existing.CopyFrom(room);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract IEnumerable<RoomPollingComponent> CreatePollingComponents();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,18 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Game.Online;
|
using osu.Game.Online;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Rooms;
|
|
||||||
|
|
||||||
namespace osu.Game.Screens.OnlinePlay.Components
|
namespace osu.Game.Screens.OnlinePlay.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;
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
protected IAPIProvider API { get; private set; }
|
protected IAPIProvider API { get; private set; }
|
||||||
|
|
||||||
protected void NotifyRoomsReceived(List<Room> rooms) => RoomsReceived?.Invoke(rooms);
|
[Resolved]
|
||||||
|
protected IRoomManager RoomManager { get; private set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
@ -48,17 +46,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
|||||||
|
|
||||||
pollReq.Success += result =>
|
pollReq.Success += result =>
|
||||||
{
|
{
|
||||||
// existing rooms need to be ordered by their position because the received of NotifyRoomsReceives expects to be able to sort them based on this order.
|
RoomManager.AddOrUpdateRoom(result);
|
||||||
var rooms = new List<Room>(roomManager.Rooms.OrderBy(r => r.Position.Value));
|
|
||||||
|
|
||||||
int index = rooms.FindIndex(r => r.RoomID.Value == result.RoomID.Value);
|
|
||||||
|
|
||||||
if (index < 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
rooms[index] = result;
|
|
||||||
|
|
||||||
NotifyRoomsReceived(rooms);
|
|
||||||
tcs.SetResult(true);
|
tcs.SetResult(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,16 +18,29 @@ namespace osu.Game.Screens.OnlinePlay
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
event Action RoomsUpdated;
|
event Action RoomsUpdated;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Whether an initial listing of rooms has been received.
|
|
||||||
/// </summary>
|
|
||||||
IBindable<bool> InitialRoomsReceived { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// All the active <see cref="Room"/>s.
|
/// All the active <see cref="Room"/>s.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IBindableList<Room> Rooms { get; }
|
IBindableList<Room> Rooms { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a <see cref="Room"/> to this <see cref="IRoomManager"/>.
|
||||||
|
/// If already existing, the local room will be updated with the given one.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="room">The incoming <see cref="Room"/>.</param>
|
||||||
|
void AddOrUpdateRoom(Room room);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes a <see cref="Room"/> from this <see cref="IRoomManager"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="room">The <see cref="Room"/> to remove.</param>
|
||||||
|
void RemoveRoom(Room room);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Removes all <see cref="Room"/>s from this <see cref="IRoomManager"/>.
|
||||||
|
/// </summary>
|
||||||
|
void ClearRooms();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="Room"/>.
|
/// Creates a new <see cref="Room"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -30,8 +30,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
|||||||
|
|
||||||
public IReadOnlyList<DrawableRoom> Rooms => roomFlow.FlowingChildren.Cast<DrawableRoom>().ToArray();
|
public IReadOnlyList<DrawableRoom> Rooms => roomFlow.FlowingChildren.Cast<DrawableRoom>().ToArray();
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
public readonly Bindable<FilterCriteria> Filter = new Bindable<FilterCriteria>();
|
||||||
private Bindable<FilterCriteria> filter { get; set; }
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private Bindable<Room> selectedRoom { get; set; }
|
private Bindable<Room> selectedRoom { get; set; }
|
||||||
@ -74,7 +73,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
|||||||
|
|
||||||
rooms.BindTo(roomManager.Rooms);
|
rooms.BindTo(roomManager.Rooms);
|
||||||
|
|
||||||
filter?.BindValueChanged(criteria => Filter(criteria.NewValue));
|
Filter?.BindValueChanged(criteria => applyFilterCriteria(criteria.NewValue), true);
|
||||||
|
|
||||||
selectedRoom.BindValueChanged(selection =>
|
selectedRoom.BindValueChanged(selection =>
|
||||||
{
|
{
|
||||||
@ -85,7 +84,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
|||||||
private void updateSelection() =>
|
private void updateSelection() =>
|
||||||
roomFlow.Children.ForEach(r => r.State = r.Room == selectedRoom.Value ? SelectionState.Selected : SelectionState.NotSelected);
|
roomFlow.Children.ForEach(r => r.State = r.Room == selectedRoom.Value ? SelectionState.Selected : SelectionState.NotSelected);
|
||||||
|
|
||||||
public void Filter(FilterCriteria criteria)
|
private void applyFilterCriteria(FilterCriteria criteria)
|
||||||
{
|
{
|
||||||
roomFlow.Children.ForEach(r =>
|
roomFlow.Children.ForEach(r =>
|
||||||
{
|
{
|
||||||
@ -126,7 +125,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
|||||||
roomFlow.Add(new DrawableRoom(room));
|
roomFlow.Add(new DrawableRoom(room));
|
||||||
}
|
}
|
||||||
|
|
||||||
Filter(filter?.Value);
|
applyFilterCriteria(Filter?.Value);
|
||||||
|
|
||||||
updateSelection();
|
updateSelection();
|
||||||
}
|
}
|
||||||
|
@ -13,14 +13,17 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Input;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Screens.OnlinePlay.Components;
|
||||||
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
||||||
using osu.Game.Screens.OnlinePlay.Match;
|
using osu.Game.Screens.OnlinePlay.Match;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
@ -42,10 +45,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
|||||||
AutoSizeAxes = Axes.Both
|
AutoSizeAxes = Axes.Both
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly IBindable<bool> initialRoomsReceived = new Bindable<bool>();
|
protected ListingPollingComponent ListingPollingComponent { get; private set; }
|
||||||
private readonly IBindable<bool> operationInProgress = new Bindable<bool>();
|
|
||||||
|
|
||||||
private LoadingLayer loadingLayer;
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private Bindable<Room> selectedRoom { get; set; }
|
private Bindable<Room> selectedRoom { get; set; }
|
||||||
@ -56,31 +56,34 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
|||||||
[Resolved(CanBeNull = true)]
|
[Resolved(CanBeNull = true)]
|
||||||
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
|
||||||
private Bindable<FilterCriteria> filter { get; set; }
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private IBindable<RulesetInfo> ruleset { get; set; }
|
private IBindable<RulesetInfo> ruleset { get; set; }
|
||||||
|
|
||||||
[CanBeNull]
|
[CanBeNull]
|
||||||
private IDisposable joiningRoomOperation { get; set; }
|
private IDisposable joiningRoomOperation { get; set; }
|
||||||
|
|
||||||
|
[CanBeNull]
|
||||||
|
private LeasedBindable<Room> selectionLease;
|
||||||
|
|
||||||
|
private readonly Bindable<FilterCriteria> filter = new Bindable<FilterCriteria>(new FilterCriteria());
|
||||||
|
private readonly IBindable<bool> operationInProgress = new Bindable<bool>();
|
||||||
|
private readonly IBindable<bool> isIdle = new BindableBool();
|
||||||
|
private LoadingLayer loadingLayer;
|
||||||
private RoomsContainer roomsContainer;
|
private RoomsContainer roomsContainer;
|
||||||
private SearchTextBox searchTextBox;
|
private SearchTextBox searchTextBox;
|
||||||
private Dropdown<RoomStatusFilter> statusDropdown;
|
private Dropdown<RoomStatusFilter> statusDropdown;
|
||||||
|
|
||||||
[CanBeNull]
|
[BackgroundDependencyLoader(true)]
|
||||||
private LeasedBindable<Room> selectionLease;
|
private void load([CanBeNull] IdleTracker idleTracker)
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load()
|
|
||||||
{
|
{
|
||||||
filter ??= new Bindable<FilterCriteria>(new FilterCriteria());
|
if (idleTracker != null)
|
||||||
|
isIdle.BindTo(idleTracker.IsIdle);
|
||||||
|
|
||||||
OsuScrollContainer scrollContainer;
|
OsuScrollContainer scrollContainer;
|
||||||
|
|
||||||
InternalChildren = new[]
|
InternalChildren = new Drawable[]
|
||||||
{
|
{
|
||||||
|
ListingPollingComponent = CreatePollingComponent().With(c => c.Filter.BindTarget = filter),
|
||||||
loadingLayer = new LoadingLayer(true),
|
loadingLayer = new LoadingLayer(true),
|
||||||
new Container
|
new Container
|
||||||
{
|
{
|
||||||
@ -154,7 +157,10 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
|||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
ScrollbarOverlapsContent = false,
|
ScrollbarOverlapsContent = false,
|
||||||
Child = roomsContainer = new RoomsContainer()
|
Child = roomsContainer = new RoomsContainer
|
||||||
|
{
|
||||||
|
Filter = { BindTarget = filter }
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -180,21 +186,22 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
|||||||
searchTextBox.Current.BindValueChanged(_ => updateFilterDebounced());
|
searchTextBox.Current.BindValueChanged(_ => updateFilterDebounced());
|
||||||
ruleset.BindValueChanged(_ => UpdateFilter());
|
ruleset.BindValueChanged(_ => UpdateFilter());
|
||||||
|
|
||||||
initialRoomsReceived.BindTo(RoomManager.InitialRoomsReceived);
|
isIdle.BindValueChanged(_ => updatePollingRate(this.IsCurrentScreen()), true);
|
||||||
initialRoomsReceived.BindValueChanged(_ => updateLoadingLayer());
|
|
||||||
|
|
||||||
if (ongoingOperationTracker != null)
|
if (ongoingOperationTracker != null)
|
||||||
{
|
{
|
||||||
operationInProgress.BindTo(ongoingOperationTracker.InProgress);
|
operationInProgress.BindTo(ongoingOperationTracker.InProgress);
|
||||||
operationInProgress.BindValueChanged(_ => updateLoadingLayer(), true);
|
operationInProgress.BindValueChanged(_ => updateLoadingLayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ListingPollingComponent.InitialRoomsReceived.BindValueChanged(_ => updateLoadingLayer(), true);
|
||||||
|
|
||||||
updateFilter();
|
updateFilter();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Filtering
|
#region Filtering
|
||||||
|
|
||||||
protected void UpdateFilter() => Scheduler.AddOnce(updateFilter);
|
public void UpdateFilter() => Scheduler.AddOnce(updateFilter);
|
||||||
|
|
||||||
private ScheduledDelegate scheduledFilterUpdate;
|
private ScheduledDelegate scheduledFilterUpdate;
|
||||||
|
|
||||||
@ -235,7 +242,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
|||||||
public override void OnEntering(IScreen last)
|
public override void OnEntering(IScreen last)
|
||||||
{
|
{
|
||||||
base.OnEntering(last);
|
base.OnEntering(last);
|
||||||
|
|
||||||
onReturning();
|
onReturning();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,11 +281,13 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
|||||||
|
|
||||||
private void onReturning()
|
private void onReturning()
|
||||||
{
|
{
|
||||||
|
updatePollingRate(true);
|
||||||
searchTextBox.HoldFocus = true;
|
searchTextBox.HoldFocus = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onLeaving()
|
private void onLeaving()
|
||||||
{
|
{
|
||||||
|
updatePollingRate(false);
|
||||||
searchTextBox.HoldFocus = false;
|
searchTextBox.HoldFocus = false;
|
||||||
|
|
||||||
// ensure any password prompt is dismissed.
|
// ensure any password prompt is dismissed.
|
||||||
@ -327,6 +335,24 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
|||||||
this.Push(CreateRoomSubScreen(room));
|
this.Push(CreateRoomSubScreen(room));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateLoadingLayer()
|
||||||
|
{
|
||||||
|
if (operationInProgress.Value || !ListingPollingComponent.InitialRoomsReceived.Value)
|
||||||
|
loadingLayer.Show();
|
||||||
|
else
|
||||||
|
loadingLayer.Hide();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePollingRate(bool isCurrentScreen)
|
||||||
|
{
|
||||||
|
if (!isCurrentScreen)
|
||||||
|
ListingPollingComponent.TimeBetweenPolls.Value = 0;
|
||||||
|
else
|
||||||
|
ListingPollingComponent.TimeBetweenPolls.Value = isIdle.Value ? 120000 : 15000;
|
||||||
|
|
||||||
|
Logger.Log($"Polling adjusted (listing: {ListingPollingComponent.TimeBetweenPolls.Value})");
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract OsuButton CreateNewRoomButton();
|
protected abstract OsuButton CreateNewRoomButton();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -337,13 +363,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
|||||||
|
|
||||||
protected abstract RoomSubScreen CreateRoomSubScreen(Room room);
|
protected abstract RoomSubScreen CreateRoomSubScreen(Room room);
|
||||||
|
|
||||||
private void updateLoadingLayer()
|
protected abstract ListingPollingComponent CreatePollingComponent();
|
||||||
{
|
|
||||||
if (operationInProgress.Value || !initialRoomsReceived.Value)
|
|
||||||
loadingLayer.Show();
|
|
||||||
else
|
|
||||||
loadingLayer.Hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class LoungeSearchTextBox : SearchTextBox
|
private class LoungeSearchTextBox : SearchTextBox
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Logging;
|
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Screens.OnlinePlay.Components;
|
using osu.Game.Screens.OnlinePlay.Components;
|
||||||
@ -23,35 +22,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
client.ChangeState(MultiplayerUserState.Idle);
|
client.ChangeState(MultiplayerUserState.Idle);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdatePollingRate(bool isIdle)
|
|
||||||
{
|
|
||||||
var multiplayerRoomManager = (MultiplayerRoomManager)RoomManager;
|
|
||||||
|
|
||||||
if (!this.IsCurrentScreen())
|
|
||||||
{
|
|
||||||
multiplayerRoomManager.TimeBetweenListingPolls.Value = 0;
|
|
||||||
multiplayerRoomManager.TimeBetweenSelectionPolls.Value = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
switch (CurrentSubScreen)
|
|
||||||
{
|
|
||||||
case LoungeSubScreen _:
|
|
||||||
multiplayerRoomManager.TimeBetweenListingPolls.Value = isIdle ? 120000 : 15000;
|
|
||||||
multiplayerRoomManager.TimeBetweenSelectionPolls.Value = isIdle ? 120000 : 15000;
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Don't poll inside the match or anywhere else.
|
|
||||||
default:
|
|
||||||
multiplayerRoomManager.TimeBetweenListingPolls.Value = 0;
|
|
||||||
multiplayerRoomManager.TimeBetweenSelectionPolls.Value = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Log($"Polling adjusted (listing: {multiplayerRoomManager.TimeBetweenListingPolls.Value}, selection: {multiplayerRoomManager.TimeBetweenSelectionPolls.Value})");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string ScreenTitle => "Multiplayer";
|
protected override string ScreenTitle => "Multiplayer";
|
||||||
|
|
||||||
protected override RoomManager CreateRoomManager() => new MultiplayerRoomManager();
|
protected override RoomManager CreateRoomManager() => new MultiplayerRoomManager();
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
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.Framework.Screens;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
|
using osu.Game.Screens.OnlinePlay.Components;
|
||||||
using osu.Game.Screens.OnlinePlay.Lounge;
|
using osu.Game.Screens.OnlinePlay.Lounge;
|
||||||
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
||||||
using osu.Game.Screens.OnlinePlay.Match;
|
using osu.Game.Screens.OnlinePlay.Match;
|
||||||
@ -21,6 +25,19 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private MultiplayerClient client { get; set; }
|
private MultiplayerClient client { get; set; }
|
||||||
|
|
||||||
|
public override void OnResuming(IScreen last)
|
||||||
|
{
|
||||||
|
base.OnResuming(last);
|
||||||
|
|
||||||
|
// Upon having left a room, we don't know whether we were the only participant, and whether the room is now closed as a result of leaving it.
|
||||||
|
// To work around this, temporarily remove the room and trigger an immediate listing poll.
|
||||||
|
if (last is MultiplayerMatchSubScreen match)
|
||||||
|
{
|
||||||
|
RoomManager.RemoveRoom(match.Room);
|
||||||
|
ListingPollingComponent.PollImmediately();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override FilterCriteria CreateFilterCriteria()
|
protected override FilterCriteria CreateFilterCriteria()
|
||||||
{
|
{
|
||||||
var criteria = base.CreateFilterCriteria();
|
var criteria = base.CreateFilterCriteria();
|
||||||
@ -39,6 +56,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
|
|
||||||
protected override RoomSubScreen CreateRoomSubScreen(Room room) => new MultiplayerMatchSubScreen(room);
|
protected override RoomSubScreen CreateRoomSubScreen(Room room) => new MultiplayerMatchSubScreen(room);
|
||||||
|
|
||||||
|
protected override ListingPollingComponent CreatePollingComponent() => new MultiplayerListingPollingComponent();
|
||||||
|
|
||||||
protected override void OpenNewRoom(Room room)
|
protected override void OpenNewRoom(Room room)
|
||||||
{
|
{
|
||||||
if (client?.IsConnected.Value != true)
|
if (client?.IsConnected.Value != true)
|
||||||
@ -49,5 +68,32 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
|
|
||||||
base.OpenNewRoom(room);
|
base.OpenNewRoom(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class MultiplayerListingPollingComponent : ListingPollingComponent
|
||||||
|
{
|
||||||
|
[Resolved]
|
||||||
|
private MultiplayerClient client { get; set; }
|
||||||
|
|
||||||
|
private readonly IBindable<bool> isConnected = new Bindable<bool>();
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
|
{
|
||||||
|
isConnected.BindTo(client.IsConnected);
|
||||||
|
isConnected.BindValueChanged(c => Scheduler.AddOnce(() =>
|
||||||
|
{
|
||||||
|
if (isConnected.Value && IsLoaded)
|
||||||
|
PollImmediately();
|
||||||
|
}), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override Task Poll()
|
||||||
|
{
|
||||||
|
if (!isConnected.Value)
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
|
return base.Poll();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
|
|
||||||
public override string ShortTitle => "room";
|
public override string ShortTitle => "room";
|
||||||
|
|
||||||
|
public readonly Room Room;
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private MultiplayerClient client { get; set; }
|
private MultiplayerClient client { get; set; }
|
||||||
|
|
||||||
@ -49,9 +51,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private Bindable<Room> currentRoom { get; set; }
|
private Bindable<Room> currentRoom { get; set; } // Todo: This should not exist.
|
||||||
|
|
||||||
private MultiplayerMatchSettingsOverlay settingsOverlay;
|
|
||||||
|
|
||||||
private readonly IBindable<bool> isConnected = new Bindable<bool>();
|
private readonly IBindable<bool> isConnected = new Bindable<bool>();
|
||||||
|
|
||||||
@ -59,9 +59,12 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
private IDisposable readyClickOperation;
|
private IDisposable readyClickOperation;
|
||||||
|
|
||||||
private GridContainer mainContent;
|
private GridContainer mainContent;
|
||||||
|
private MultiplayerMatchSettingsOverlay settingsOverlay;
|
||||||
|
|
||||||
public MultiplayerMatchSubScreen(Room room)
|
public MultiplayerMatchSubScreen(Room room)
|
||||||
{
|
{
|
||||||
|
Room = room;
|
||||||
|
|
||||||
Title = room.RoomID.Value == null ? "New room" : room.Name.Value;
|
Title = room.RoomID.Value == null ? "New room" : room.Name.Value;
|
||||||
Activity.Value = new UserActivity.InLobby(room);
|
Activity.Value = new UserActivity.InLobby(room);
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,8 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Extensions.ExceptionExtensions;
|
using osu.Framework.Extensions.ExceptionExtensions;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
@ -21,22 +18,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private MultiplayerClient multiplayerClient { get; set; }
|
private MultiplayerClient 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>();
|
|
||||||
private readonly Bindable<bool> allowPolling = new Bindable<bool>();
|
|
||||||
|
|
||||||
private ListingPollingComponent listingPollingComponent;
|
|
||||||
|
|
||||||
protected override void LoadComplete()
|
|
||||||
{
|
|
||||||
base.LoadComplete();
|
|
||||||
|
|
||||||
isConnected.BindTo(multiplayerClient.IsConnected);
|
|
||||||
isConnected.BindValueChanged(_ => Scheduler.AddOnce(updatePolling));
|
|
||||||
JoinedRoom.BindValueChanged(_ => Scheduler.AddOnce(updatePolling), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
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, r.Password.Value, onSuccess, onError), onError);
|
=> base.CreateRoom(room, r => joinMultiplayerRoom(r, r.Password.Value, onSuccess, onError), onError);
|
||||||
|
|
||||||
@ -64,19 +45,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
if (JoinedRoom.Value == null)
|
if (JoinedRoom.Value == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var joinedRoom = JoinedRoom.Value;
|
|
||||||
|
|
||||||
base.PartRoom();
|
base.PartRoom();
|
||||||
|
|
||||||
multiplayerClient.LeaveRoom();
|
multiplayerClient.LeaveRoom();
|
||||||
|
|
||||||
// Todo: This is not the way to do this. Basically when we're the only participant and the room closes, there's no way to know if this is actually the case.
|
|
||||||
// This is delayed one frame because upon exiting the match subscreen, multiplayer updates the polling rate and messes with polling.
|
|
||||||
Schedule(() =>
|
|
||||||
{
|
|
||||||
RemoveRoom(joinedRoom);
|
|
||||||
listingPollingComponent.PollImmediately();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void joinMultiplayerRoom(Room room, string password, Action<Room> onSuccess = null, Action<string> onError = null)
|
private void joinMultiplayerRoom(Room room, string password, Action<Room> onSuccess = null, Action<string> onError = null)
|
||||||
@ -99,70 +69,5 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePolling()
|
|
||||||
{
|
|
||||||
if (!isConnected.Value)
|
|
||||||
ClearRooms();
|
|
||||||
|
|
||||||
// Don't poll when not connected or when a room has been joined.
|
|
||||||
allowPolling.Value = isConnected.Value && JoinedRoom.Value == null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override IEnumerable<RoomPollingComponent> CreatePollingComponents() => new RoomPollingComponent[]
|
|
||||||
{
|
|
||||||
listingPollingComponent = new MultiplayerListingPollingComponent
|
|
||||||
{
|
|
||||||
TimeBetweenPolls = { BindTarget = TimeBetweenListingPolls },
|
|
||||||
AllowPolling = { BindTarget = allowPolling }
|
|
||||||
},
|
|
||||||
new MultiplayerSelectionPollingComponent
|
|
||||||
{
|
|
||||||
TimeBetweenPolls = { BindTarget = TimeBetweenSelectionPolls },
|
|
||||||
AllowPolling = { BindTarget = allowPolling }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private class MultiplayerListingPollingComponent : ListingPollingComponent
|
|
||||||
{
|
|
||||||
public readonly IBindable<bool> AllowPolling = new Bindable<bool>();
|
|
||||||
|
|
||||||
protected override void LoadComplete()
|
|
||||||
{
|
|
||||||
base.LoadComplete();
|
|
||||||
|
|
||||||
AllowPolling.BindValueChanged(allowPolling =>
|
|
||||||
{
|
|
||||||
if (!allowPolling.NewValue)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (IsLoaded)
|
|
||||||
PollImmediately();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Task Poll() => !AllowPolling.Value ? Task.CompletedTask : base.Poll();
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MultiplayerSelectionPollingComponent : SelectionPollingComponent
|
|
||||||
{
|
|
||||||
public readonly IBindable<bool> AllowPolling = new Bindable<bool>();
|
|
||||||
|
|
||||||
protected override void LoadComplete()
|
|
||||||
{
|
|
||||||
base.LoadComplete();
|
|
||||||
|
|
||||||
AllowPolling.BindValueChanged(allowPolling =>
|
|
||||||
{
|
|
||||||
if (!allowPolling.NewValue)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (IsLoaded)
|
|
||||||
PollImmediately();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override Task Poll() => !AllowPolling.Value ? Task.CompletedTask : base.Poll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,14 +14,12 @@ using osu.Framework.Screens;
|
|||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.Drawables;
|
using osu.Game.Beatmaps.Drawables;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
using osu.Game.Input;
|
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Screens.Menu;
|
using osu.Game.Screens.Menu;
|
||||||
using osu.Game.Screens.OnlinePlay.Components;
|
using osu.Game.Screens.OnlinePlay.Components;
|
||||||
using osu.Game.Screens.OnlinePlay.Lounge;
|
using osu.Game.Screens.OnlinePlay.Lounge;
|
||||||
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
@ -44,17 +42,12 @@ namespace osu.Game.Screens.OnlinePlay
|
|||||||
private LoungeSubScreen loungeSubScreen;
|
private LoungeSubScreen loungeSubScreen;
|
||||||
private ScreenStack screenStack;
|
private ScreenStack screenStack;
|
||||||
|
|
||||||
private readonly IBindable<bool> isIdle = new BindableBool();
|
|
||||||
|
|
||||||
[Cached(Type = typeof(IRoomManager))]
|
[Cached(Type = typeof(IRoomManager))]
|
||||||
protected RoomManager RoomManager { get; private set; }
|
protected RoomManager RoomManager { get; private set; }
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
private readonly Bindable<Room> selectedRoom = new Bindable<Room>();
|
private readonly Bindable<Room> selectedRoom = new Bindable<Room>();
|
||||||
|
|
||||||
[Cached]
|
|
||||||
private readonly Bindable<FilterCriteria> currentFilter = new Bindable<FilterCriteria>(new FilterCriteria());
|
|
||||||
|
|
||||||
[Cached]
|
[Cached]
|
||||||
private readonly OngoingOperationTracker ongoingOperationTracker = new OngoingOperationTracker();
|
private readonly OngoingOperationTracker ongoingOperationTracker = new OngoingOperationTracker();
|
||||||
|
|
||||||
@ -67,9 +60,6 @@ namespace osu.Game.Screens.OnlinePlay
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
protected IAPIProvider API { get; private set; }
|
protected IAPIProvider API { get; private set; }
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
|
||||||
private IdleTracker idleTracker { get; set; }
|
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
[Resolved(CanBeNull = true)]
|
||||||
private OsuLogo logo { get; set; }
|
private OsuLogo logo { get; set; }
|
||||||
|
|
||||||
@ -147,12 +137,6 @@ namespace osu.Game.Screens.OnlinePlay
|
|||||||
|
|
||||||
apiState.BindTo(API.State);
|
apiState.BindTo(API.State);
|
||||||
apiState.BindValueChanged(onlineStateChanged, true);
|
apiState.BindValueChanged(onlineStateChanged, true);
|
||||||
|
|
||||||
if (idleTracker != null)
|
|
||||||
{
|
|
||||||
isIdle.BindTo(idleTracker.IsIdle);
|
|
||||||
isIdle.BindValueChanged(idle => UpdatePollingRate(idle.NewValue), true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||||
@ -162,8 +146,6 @@ namespace osu.Game.Screens.OnlinePlay
|
|||||||
return dependencies;
|
return dependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void UpdatePollingRate(bool isIdle);
|
|
||||||
|
|
||||||
private void forcefullyExit()
|
private void forcefullyExit()
|
||||||
{
|
{
|
||||||
// This is temporary since we don't currently have a way to force screens to be exited
|
// This is temporary since we don't currently have a way to force screens to be exited
|
||||||
@ -199,8 +181,6 @@ namespace osu.Game.Screens.OnlinePlay
|
|||||||
screenStack.CurrentScreen.OnResuming(last);
|
screenStack.CurrentScreen.OnResuming(last);
|
||||||
|
|
||||||
base.OnResuming(last);
|
base.OnResuming(last);
|
||||||
|
|
||||||
UpdatePollingRate(isIdle.Value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnSuspending(IScreen next)
|
public override void OnSuspending(IScreen next)
|
||||||
@ -210,8 +190,6 @@ namespace osu.Game.Screens.OnlinePlay
|
|||||||
|
|
||||||
Debug.Assert(screenStack.CurrentScreen != null);
|
Debug.Assert(screenStack.CurrentScreen != null);
|
||||||
screenStack.CurrentScreen.OnSuspending(next);
|
screenStack.CurrentScreen.OnSuspending(next);
|
||||||
|
|
||||||
UpdatePollingRate(isIdle.Value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool OnExiting(IScreen next)
|
public override bool OnExiting(IScreen next)
|
||||||
@ -275,15 +253,13 @@ namespace osu.Game.Screens.OnlinePlay
|
|||||||
|
|
||||||
if (newScreen is IOsuScreen newOsuScreen)
|
if (newScreen is IOsuScreen newOsuScreen)
|
||||||
((IBindable<UserActivity>)Activity).BindTo(newOsuScreen.Activity);
|
((IBindable<UserActivity>)Activity).BindTo(newOsuScreen.Activity);
|
||||||
|
|
||||||
UpdatePollingRate(isIdle.Value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IScreen CurrentSubScreen => screenStack.CurrentScreen;
|
protected IScreen CurrentSubScreen => screenStack.CurrentScreen;
|
||||||
|
|
||||||
protected abstract string ScreenTitle { get; }
|
protected abstract string ScreenTitle { get; }
|
||||||
|
|
||||||
protected abstract RoomManager CreateRoomManager();
|
protected virtual RoomManager CreateRoomManager() => new RoomManager();
|
||||||
|
|
||||||
protected abstract LoungeSubScreen CreateLounge();
|
protected abstract LoungeSubScreen CreateLounge();
|
||||||
|
|
||||||
|
@ -1,53 +1,14 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Logging;
|
|
||||||
using osu.Framework.Screens;
|
|
||||||
using osu.Game.Screens.OnlinePlay.Components;
|
|
||||||
using osu.Game.Screens.OnlinePlay.Lounge;
|
using osu.Game.Screens.OnlinePlay.Lounge;
|
||||||
using osu.Game.Screens.OnlinePlay.Match;
|
|
||||||
|
|
||||||
namespace osu.Game.Screens.OnlinePlay.Playlists
|
namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||||
{
|
{
|
||||||
public class Playlists : OnlinePlayScreen
|
public class Playlists : OnlinePlayScreen
|
||||||
{
|
{
|
||||||
protected override void UpdatePollingRate(bool isIdle)
|
|
||||||
{
|
|
||||||
var playlistsManager = (PlaylistsRoomManager)RoomManager;
|
|
||||||
|
|
||||||
if (!this.IsCurrentScreen())
|
|
||||||
{
|
|
||||||
playlistsManager.TimeBetweenListingPolls.Value = 0;
|
|
||||||
playlistsManager.TimeBetweenSelectionPolls.Value = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
switch (CurrentSubScreen)
|
|
||||||
{
|
|
||||||
case LoungeSubScreen _:
|
|
||||||
playlistsManager.TimeBetweenListingPolls.Value = isIdle ? 120000 : 15000;
|
|
||||||
playlistsManager.TimeBetweenSelectionPolls.Value = isIdle ? 120000 : 15000;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case RoomSubScreen _:
|
|
||||||
playlistsManager.TimeBetweenListingPolls.Value = 0;
|
|
||||||
playlistsManager.TimeBetweenSelectionPolls.Value = isIdle ? 30000 : 5000;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
playlistsManager.TimeBetweenListingPolls.Value = 0;
|
|
||||||
playlistsManager.TimeBetweenSelectionPolls.Value = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger.Log($"Polling adjusted (listing: {playlistsManager.TimeBetweenListingPolls.Value}, selection: {playlistsManager.TimeBetweenSelectionPolls.Value})");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override string ScreenTitle => "Playlists";
|
protected override string ScreenTitle => "Playlists";
|
||||||
|
|
||||||
protected override RoomManager CreateRoomManager() => new PlaylistsRoomManager();
|
|
||||||
|
|
||||||
protected override LoungeSubScreen CreateLounge() => new PlaylistsLoungeSubScreen();
|
protected override LoungeSubScreen CreateLounge() => new PlaylistsLoungeSubScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ using osu.Framework.Graphics.UserInterface;
|
|||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
|
using osu.Game.Screens.OnlinePlay.Components;
|
||||||
using osu.Game.Screens.OnlinePlay.Lounge;
|
using osu.Game.Screens.OnlinePlay.Lounge;
|
||||||
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
||||||
using osu.Game.Screens.OnlinePlay.Match;
|
using osu.Game.Screens.OnlinePlay.Match;
|
||||||
@ -66,6 +67,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
|||||||
|
|
||||||
protected override RoomSubScreen CreateRoomSubScreen(Room room) => new PlaylistsRoomSubScreen(room);
|
protected override RoomSubScreen CreateRoomSubScreen(Room room) => new PlaylistsRoomSubScreen(room);
|
||||||
|
|
||||||
|
protected override ListingPollingComponent CreatePollingComponent() => new ListingPollingComponent();
|
||||||
|
|
||||||
private enum PlaylistsCategory
|
private enum PlaylistsCategory
|
||||||
{
|
{
|
||||||
Any,
|
Any,
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Game.Screens.OnlinePlay.Components;
|
|
||||||
|
|
||||||
namespace osu.Game.Screens.OnlinePlay.Playlists
|
|
||||||
{
|
|
||||||
public class PlaylistsRoomManager : RoomManager
|
|
||||||
{
|
|
||||||
public readonly Bindable<double> TimeBetweenListingPolls = new Bindable<double>();
|
|
||||||
public readonly Bindable<double> TimeBetweenSelectionPolls = new Bindable<double>();
|
|
||||||
|
|
||||||
protected override IEnumerable<RoomPollingComponent> CreatePollingComponents() => new RoomPollingComponent[]
|
|
||||||
{
|
|
||||||
new ListingPollingComponent { TimeBetweenPolls = { BindTarget = TimeBetweenListingPolls } },
|
|
||||||
new SelectionPollingComponent { TimeBetweenPolls = { BindTarget = TimeBetweenSelectionPolls } }
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,11 +3,14 @@
|
|||||||
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
|
using osu.Game.Input;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Screens.OnlinePlay.Components;
|
using osu.Game.Screens.OnlinePlay.Components;
|
||||||
@ -33,12 +36,13 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
|||||||
[Resolved(typeof(Room), nameof(Room.Playlist))]
|
[Resolved(typeof(Room), nameof(Room.Playlist))]
|
||||||
private BindableList<PlaylistItem> playlist { get; set; }
|
private BindableList<PlaylistItem> playlist { get; set; }
|
||||||
|
|
||||||
|
private readonly IBindable<bool> isIdle = new BindableBool();
|
||||||
|
|
||||||
private MatchSettingsOverlay settingsOverlay;
|
private MatchSettingsOverlay settingsOverlay;
|
||||||
private MatchLeaderboard leaderboard;
|
private MatchLeaderboard leaderboard;
|
||||||
|
|
||||||
private OverlinedHeader participantsHeader;
|
private OverlinedHeader participantsHeader;
|
||||||
|
|
||||||
private GridContainer mainContent;
|
private GridContainer mainContent;
|
||||||
|
private SelectionPollingComponent selectionPollingComponent;
|
||||||
|
|
||||||
public PlaylistsRoomSubScreen(Room room)
|
public PlaylistsRoomSubScreen(Room room)
|
||||||
{
|
{
|
||||||
@ -46,11 +50,15 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
|||||||
Activity.Value = new UserActivity.InLobby(room);
|
Activity.Value = new UserActivity.InLobby(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader(true)]
|
||||||
private void load()
|
private void load([CanBeNull] IdleTracker idleTracker)
|
||||||
{
|
{
|
||||||
|
if (idleTracker != null)
|
||||||
|
isIdle.BindTo(idleTracker.IsIdle);
|
||||||
|
|
||||||
AddRangeInternal(new Drawable[]
|
AddRangeInternal(new Drawable[]
|
||||||
{
|
{
|
||||||
|
selectionPollingComponent = new SelectionPollingComponent(),
|
||||||
mainContent = new GridContainer
|
mainContent = new GridContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
@ -260,6 +268,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
|
isIdle.BindValueChanged(_ => updatePollingRate(), true);
|
||||||
|
|
||||||
roomId.BindValueChanged(id =>
|
roomId.BindValueChanged(id =>
|
||||||
{
|
{
|
||||||
if (id.NewValue == null)
|
if (id.NewValue == null)
|
||||||
@ -275,6 +285,12 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
|||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updatePollingRate()
|
||||||
|
{
|
||||||
|
selectionPollingComponent.TimeBetweenPolls.Value = isIdle.Value ? 30000 : 5000;
|
||||||
|
Logger.Log($"Polling adjusted (selection: {selectionPollingComponent.TimeBetweenPolls.Value})");
|
||||||
|
}
|
||||||
|
|
||||||
protected override Screen CreateGameplayScreen() => new PlayerLoader(() => new PlaylistsPlayer(SelectedItem.Value)
|
protected override Screen CreateGameplayScreen() => new PlayerLoader(() => new PlaylistsPlayer(SelectedItem.Value)
|
||||||
{
|
{
|
||||||
Exited = () => leaderboard.RefreshScores()
|
Exited = () => leaderboard.RefreshScores()
|
||||||
|
@ -127,7 +127,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
protected override Task<MultiplayerRoom> JoinRoom(long roomId, string? password = null)
|
protected override Task<MultiplayerRoom> JoinRoom(long roomId, string? password = null)
|
||||||
{
|
{
|
||||||
var apiRoom = roomManager.Rooms.Single(r => r.RoomID.Value == roomId);
|
var apiRoom = roomManager.ServerSideRooms.Single(r => r.RoomID.Value == roomId);
|
||||||
|
|
||||||
if (password != apiRoom.Password.Value)
|
if (password != apiRoom.Password.Value)
|
||||||
throw new InvalidOperationException("Invalid password.");
|
throw new InvalidOperationException("Invalid password.");
|
||||||
@ -260,7 +260,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
{
|
{
|
||||||
Debug.Assert(Room != null);
|
Debug.Assert(Room != null);
|
||||||
|
|
||||||
var apiRoom = roomManager.Rooms.Single(r => r.RoomID.Value == Room.RoomID);
|
var apiRoom = roomManager.ServerSideRooms.Single(r => r.RoomID.Value == Room.RoomID);
|
||||||
var set = apiRoom.Playlist.FirstOrDefault(p => p.BeatmapID == beatmapId)?.Beatmap.Value.BeatmapSet
|
var set = apiRoom.Playlist.FirstOrDefault(p => p.BeatmapID == beatmapId)?.Beatmap.Value.BeatmapSet
|
||||||
?? beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmapId)?.BeatmapSet;
|
?? beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmapId)?.BeatmapSet;
|
||||||
|
|
||||||
|
@ -5,14 +5,12 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Rulesets.Scoring;
|
using osu.Game.Rulesets.Scoring;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Screens.OnlinePlay.Components;
|
using osu.Game.Screens.OnlinePlay.Components;
|
||||||
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
|
||||||
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Multiplayer
|
namespace osu.Game.Tests.Visual.Multiplayer
|
||||||
@ -32,10 +30,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuGameBase game { get; set; }
|
private OsuGameBase game { get; set; }
|
||||||
|
|
||||||
[Cached]
|
public IReadOnlyList<Room> ServerSideRooms => serverSideRooms;
|
||||||
public readonly Bindable<FilterCriteria> Filter = new Bindable<FilterCriteria>(new FilterCriteria());
|
private readonly List<Room> serverSideRooms = new List<Room>();
|
||||||
|
|
||||||
public new readonly List<Room> Rooms = new List<Room>();
|
|
||||||
|
|
||||||
private int currentRoomId;
|
private int currentRoomId;
|
||||||
private int currentPlaylistItemId;
|
private int currentPlaylistItemId;
|
||||||
@ -60,7 +56,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
apiRoom.HasPassword.Value = !string.IsNullOrEmpty(createRoomRequest.Room.Password.Value);
|
apiRoom.HasPassword.Value = !string.IsNullOrEmpty(createRoomRequest.Room.Password.Value);
|
||||||
apiRoom.Password.Value = createRoomRequest.Room.Password.Value;
|
apiRoom.Password.Value = createRoomRequest.Room.Password.Value;
|
||||||
|
|
||||||
AddRoom(apiRoom);
|
AddServerSideRoom(apiRoom);
|
||||||
|
|
||||||
var responseRoom = new APICreatedRoom();
|
var responseRoom = new APICreatedRoom();
|
||||||
responseRoom.CopyFrom(createResponseRoom(apiRoom, false));
|
responseRoom.CopyFrom(createResponseRoom(apiRoom, false));
|
||||||
@ -70,7 +66,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
case JoinRoomRequest joinRoomRequest:
|
case JoinRoomRequest joinRoomRequest:
|
||||||
{
|
{
|
||||||
var room = Rooms.Single(r => r.RoomID.Value == joinRoomRequest.Room.RoomID.Value);
|
var room = ServerSideRooms.Single(r => r.RoomID.Value == joinRoomRequest.Room.RoomID.Value);
|
||||||
|
|
||||||
if (joinRoomRequest.Password != room.Password.Value)
|
if (joinRoomRequest.Password != room.Password.Value)
|
||||||
{
|
{
|
||||||
@ -89,14 +85,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
case GetRoomsRequest getRoomsRequest:
|
case GetRoomsRequest getRoomsRequest:
|
||||||
var roomsWithoutParticipants = new List<Room>();
|
var roomsWithoutParticipants = new List<Room>();
|
||||||
|
|
||||||
foreach (var r in Rooms)
|
foreach (var r in ServerSideRooms)
|
||||||
roomsWithoutParticipants.Add(createResponseRoom(r, false));
|
roomsWithoutParticipants.Add(createResponseRoom(r, false));
|
||||||
|
|
||||||
getRoomsRequest.TriggerSuccess(roomsWithoutParticipants);
|
getRoomsRequest.TriggerSuccess(roomsWithoutParticipants);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case GetRoomRequest getRoomRequest:
|
case GetRoomRequest getRoomRequest:
|
||||||
getRoomRequest.TriggerSuccess(createResponseRoom(Rooms.Single(r => r.RoomID.Value == getRoomRequest.RoomId), true));
|
getRoomRequest.TriggerSuccess(createResponseRoom(ServerSideRooms.Single(r => r.RoomID.Value == getRoomRequest.RoomId), true));
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case GetBeatmapSetRequest getBeatmapSetRequest:
|
case GetBeatmapSetRequest getBeatmapSetRequest:
|
||||||
@ -132,17 +128,15 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddRoom(Room room)
|
public void AddServerSideRoom(Room room)
|
||||||
{
|
{
|
||||||
room.RoomID.Value ??= currentRoomId++;
|
room.RoomID.Value ??= currentRoomId++;
|
||||||
for (int i = 0; i < room.Playlist.Count; i++)
|
for (int i = 0; i < room.Playlist.Count; i++)
|
||||||
room.Playlist[i].ID = currentPlaylistItemId++;
|
room.Playlist[i].ID = currentPlaylistItemId++;
|
||||||
|
|
||||||
Rooms.Add(room);
|
serverSideRooms.Add(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
public new void RemoveRoom(Room room) => base.RemoveRoom(room);
|
|
||||||
|
|
||||||
private Room createResponseRoom(Room room, bool withParticipants)
|
private Room createResponseRoom(Room room, bool withParticipants)
|
||||||
{
|
{
|
||||||
var responseRoom = new Room();
|
var responseRoom = new Room();
|
||||||
@ -152,9 +146,5 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
responseRoom.RecentParticipants.Clear();
|
responseRoom.RecentParticipants.Clear();
|
||||||
return responseRoom;
|
return responseRoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public new void ClearRooms() => base.ClearRooms();
|
|
||||||
|
|
||||||
public new void Schedule(Action action) => base.Schedule(action);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,17 +28,25 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
|||||||
|
|
||||||
IBindableList<Room> IRoomManager.Rooms => Rooms;
|
IBindableList<Room> IRoomManager.Rooms => Rooms;
|
||||||
|
|
||||||
|
private int currentRoomId;
|
||||||
|
|
||||||
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
|
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
|
||||||
{
|
{
|
||||||
room.RoomID.Value ??= Rooms.Select(r => r.RoomID.Value).Where(id => id != null).Select(id => id.Value).DefaultIfEmpty().Max() + 1;
|
room.RoomID.Value ??= Rooms.Select(r => r.RoomID.Value).Where(id => id != null).Select(id => id.Value).DefaultIfEmpty().Max() + 1;
|
||||||
onSuccess?.Invoke(room);
|
onSuccess?.Invoke(room);
|
||||||
|
|
||||||
AddRoom(room);
|
AddOrUpdateRoom(room);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddRoom(Room room)
|
public void AddOrUpdateRoom(Room room)
|
||||||
{
|
{
|
||||||
|
var existing = Rooms.FirstOrDefault(r => r.RoomID.Value != null && r.RoomID.Value == room.RoomID.Value);
|
||||||
|
|
||||||
|
if (existing != null)
|
||||||
|
existing.CopyFrom(room);
|
||||||
|
else
|
||||||
Rooms.Add(room);
|
Rooms.Add(room);
|
||||||
|
|
||||||
RoomsUpdated?.Invoke();
|
RoomsUpdated?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +56,12 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
|||||||
RoomsUpdated?.Invoke();
|
RoomsUpdated?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ClearRooms()
|
||||||
|
{
|
||||||
|
Rooms.Clear();
|
||||||
|
RoomsUpdated?.Invoke();
|
||||||
|
}
|
||||||
|
|
||||||
public void JoinRoom(Room room, string password, Action<Room> onSuccess = null, Action<string> onError = null)
|
public void JoinRoom(Room room, string password, Action<Room> onSuccess = null, Action<string> onError = null)
|
||||||
{
|
{
|
||||||
JoinRoomRequested?.Invoke(room, password);
|
JoinRoomRequested?.Invoke(room, password);
|
||||||
@ -64,9 +78,9 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
|||||||
{
|
{
|
||||||
var room = new Room
|
var room = new Room
|
||||||
{
|
{
|
||||||
RoomID = { Value = i },
|
RoomID = { Value = currentRoomId },
|
||||||
Position = { Value = i },
|
Position = { Value = currentRoomId },
|
||||||
Name = { Value = $"Room {i}" },
|
Name = { Value = $"Room {currentRoomId}" },
|
||||||
Host = { Value = new User { Username = "Host" } },
|
Host = { Value = new User { Username = "Host" } },
|
||||||
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) },
|
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) },
|
||||||
Category = { Value = i % 2 == 0 ? RoomCategory.Spotlight : RoomCategory.Normal },
|
Category = { Value = i % 2 == 0 ? RoomCategory.Spotlight : RoomCategory.Normal },
|
||||||
@ -89,6 +103,8 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
|||||||
}
|
}
|
||||||
|
|
||||||
CreateRoom(room);
|
CreateRoom(room);
|
||||||
|
|
||||||
|
currentRoomId++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Screens.OnlinePlay;
|
using osu.Game.Screens.OnlinePlay;
|
||||||
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.OnlinePlay
|
namespace osu.Game.Tests.Visual.OnlinePlay
|
||||||
{
|
{
|
||||||
@ -23,11 +22,6 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
IRoomManager RoomManager { get; }
|
IRoomManager RoomManager { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The cached <see cref="FilterCriteria"/>.
|
|
||||||
/// </summary>
|
|
||||||
Bindable<FilterCriteria> Filter { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The cached <see cref="OngoingOperationTracker"/>.
|
/// The cached <see cref="OngoingOperationTracker"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -9,7 +9,6 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Screens.OnlinePlay;
|
using osu.Game.Screens.OnlinePlay;
|
||||||
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.OnlinePlay
|
namespace osu.Game.Tests.Visual.OnlinePlay
|
||||||
{
|
{
|
||||||
@ -20,7 +19,6 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
|||||||
{
|
{
|
||||||
public Bindable<Room> SelectedRoom => OnlinePlayDependencies?.SelectedRoom;
|
public Bindable<Room> SelectedRoom => OnlinePlayDependencies?.SelectedRoom;
|
||||||
public IRoomManager RoomManager => OnlinePlayDependencies?.RoomManager;
|
public IRoomManager RoomManager => OnlinePlayDependencies?.RoomManager;
|
||||||
public Bindable<FilterCriteria> Filter => OnlinePlayDependencies?.Filter;
|
|
||||||
public OngoingOperationTracker OngoingOperationTracker => OnlinePlayDependencies?.OngoingOperationTracker;
|
public OngoingOperationTracker OngoingOperationTracker => OnlinePlayDependencies?.OngoingOperationTracker;
|
||||||
public OnlinePlayBeatmapAvailabilityTracker AvailabilityTracker => OnlinePlayDependencies?.AvailabilityTracker;
|
public OnlinePlayBeatmapAvailabilityTracker AvailabilityTracker => OnlinePlayDependencies?.AvailabilityTracker;
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Screens.OnlinePlay;
|
using osu.Game.Screens.OnlinePlay;
|
||||||
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.OnlinePlay
|
namespace osu.Game.Tests.Visual.OnlinePlay
|
||||||
{
|
{
|
||||||
@ -20,7 +19,6 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
|||||||
{
|
{
|
||||||
public Bindable<Room> SelectedRoom { get; }
|
public Bindable<Room> SelectedRoom { get; }
|
||||||
public IRoomManager RoomManager { get; }
|
public IRoomManager RoomManager { get; }
|
||||||
public Bindable<FilterCriteria> Filter { get; }
|
|
||||||
public OngoingOperationTracker OngoingOperationTracker { get; }
|
public OngoingOperationTracker OngoingOperationTracker { get; }
|
||||||
public OnlinePlayBeatmapAvailabilityTracker AvailabilityTracker { get; }
|
public OnlinePlayBeatmapAvailabilityTracker AvailabilityTracker { get; }
|
||||||
|
|
||||||
@ -36,7 +34,6 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
|||||||
{
|
{
|
||||||
SelectedRoom = new Bindable<Room>();
|
SelectedRoom = new Bindable<Room>();
|
||||||
RoomManager = CreateRoomManager();
|
RoomManager = CreateRoomManager();
|
||||||
Filter = new Bindable<FilterCriteria>(new FilterCriteria());
|
|
||||||
OngoingOperationTracker = new OngoingOperationTracker();
|
OngoingOperationTracker = new OngoingOperationTracker();
|
||||||
AvailabilityTracker = new OnlinePlayBeatmapAvailabilityTracker();
|
AvailabilityTracker = new OnlinePlayBeatmapAvailabilityTracker();
|
||||||
|
|
||||||
@ -44,7 +41,6 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
|||||||
|
|
||||||
CacheAs(SelectedRoom);
|
CacheAs(SelectedRoom);
|
||||||
CacheAs(RoomManager);
|
CacheAs(RoomManager);
|
||||||
CacheAs(Filter);
|
|
||||||
CacheAs(OngoingOperationTracker);
|
CacheAs(OngoingOperationTracker);
|
||||||
CacheAs(AvailabilityTracker);
|
CacheAs(AvailabilityTracker);
|
||||||
CacheAs(new OverlayColourProvider(OverlayColourScheme.Plum));
|
CacheAs(new OverlayColourProvider(OverlayColourScheme.Plum));
|
||||||
|
Loading…
Reference in New Issue
Block a user