mirror of
https://github.com/ppy/osu.git
synced 2025-03-11 02:17:19 +08:00
Remove selected room leasing, make bindables private
I believe once upon a time the `SelectedRoom` bindable used to be bound to `RoomManager.JoinedRoom` or similar. But now it's effectively private to the lounge subscreen and so a lease is unnecessary.
This commit is contained in:
parent
f146a7d116
commit
1b07b6d16f
@ -3,7 +3,6 @@
|
||||
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Graphics.Containers;
|
||||
@ -17,13 +16,13 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
{
|
||||
public partial class TestScenePlaylistsLoungeSubScreen : OnlinePlayTestScene
|
||||
{
|
||||
private TestLoungeSubScreen loungeScreen = null!;
|
||||
private PlaylistsLoungeSubScreen loungeScreen = null!;
|
||||
|
||||
public override void SetUpSteps()
|
||||
{
|
||||
base.SetUpSteps();
|
||||
|
||||
AddStep("push screen", () => LoadScreen(loungeScreen = new TestLoungeSubScreen()));
|
||||
AddStep("push screen", () => LoadScreen(loungeScreen = new PlaylistsLoungeSubScreen()));
|
||||
AddUntilStep("wait for present", () => loungeScreen.IsCurrentScreen());
|
||||
}
|
||||
|
||||
@ -62,24 +61,6 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
AddUntilStep("last room is not masked", () => checkRoomVisible(roomsContainer.DrawableRooms[^1]));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEnteringRoomTakesLeaseOnSelection()
|
||||
{
|
||||
createRooms(GenerateRooms(1));
|
||||
|
||||
AddAssert("selected room is not disabled", () => !loungeScreen.SelectedRoom.Disabled);
|
||||
|
||||
AddStep("select room", () => roomsContainer.DrawableRooms[0].TriggerClick());
|
||||
AddAssert("selected room is non-null", () => loungeScreen.SelectedRoom.Value != null);
|
||||
|
||||
AddStep("enter room", () => roomsContainer.DrawableRooms[0].TriggerClick());
|
||||
|
||||
AddUntilStep("wait for match load", () => Stack.CurrentScreen is PlaylistsRoomSubScreen);
|
||||
|
||||
AddAssert("selected room is non-null", () => loungeScreen.SelectedRoom.Value != null);
|
||||
AddAssert("selected room is disabled", () => loungeScreen.SelectedRoom.Disabled);
|
||||
}
|
||||
|
||||
private bool checkRoomVisible(DrawableRoom room) =>
|
||||
loungeScreen.ChildrenOfType<OsuScrollContainer>().First().ScreenSpaceDrawQuad
|
||||
.Contains(room.ScreenSpaceDrawQuad.Centre);
|
||||
@ -94,10 +75,5 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
|
||||
AddStep("refresh lounge", () => loungeScreen.RefreshRooms());
|
||||
}
|
||||
|
||||
private partial class TestLoungeSubScreen : PlaylistsLoungeSubScreen
|
||||
{
|
||||
public new Bindable<Room?> SelectedRoom => base.SelectedRoom;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
|
||||
protected override BackgroundScreen CreateBackground() => new LoungeBackgroundScreen
|
||||
{
|
||||
SelectedRoom = { BindTarget = SelectedRoom }
|
||||
SelectedRoom = { BindTarget = selectedRoom }
|
||||
};
|
||||
|
||||
protected override UserActivity InitialActivity => new UserActivity.SearchingForLobby();
|
||||
@ -53,9 +53,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
AutoSizeAxes = Axes.Both
|
||||
};
|
||||
|
||||
protected readonly Bindable<Room?> SelectedRoom = new Bindable<Room?>();
|
||||
protected readonly BindableList<Room> Rooms = new BindableList<Room>();
|
||||
|
||||
[Resolved]
|
||||
private MusicController music { get; set; } = null!;
|
||||
|
||||
@ -75,8 +72,9 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
protected OsuConfigManager Config { get; private set; } = null!;
|
||||
|
||||
private IDisposable? joiningRoomOperation;
|
||||
private LeasedBindable<Room?>? selectionLease;
|
||||
|
||||
private readonly Bindable<Room?> selectedRoom = new Bindable<Room?>();
|
||||
private readonly BindableList<Room> rooms = new BindableList<Room>();
|
||||
private readonly Bindable<FilterCriteria?> filter = new Bindable<FilterCriteria?>();
|
||||
private readonly Bindable<bool> hasListingResults = new Bindable<bool>();
|
||||
private readonly IBindable<bool> operationInProgress = new Bindable<bool>();
|
||||
@ -121,8 +119,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
ScrollbarOverlapsContent = false,
|
||||
Child = roomsContainer = new RoomsContainer
|
||||
{
|
||||
Rooms = { BindTarget = Rooms },
|
||||
SelectedRoom = { BindTarget = SelectedRoom },
|
||||
Rooms = { BindTarget = rooms },
|
||||
SelectedRoom = { BindTarget = selectedRoom },
|
||||
Filter = { BindTarget = filter },
|
||||
}
|
||||
},
|
||||
@ -182,7 +180,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
};
|
||||
|
||||
// scroll selected room into view on selection.
|
||||
SelectedRoom.BindValueChanged(val =>
|
||||
selectedRoom.BindValueChanged(val =>
|
||||
{
|
||||
var drawable = roomsContainer.DrawableRooms.FirstOrDefault(r => r.Room == val.NewValue);
|
||||
if (drawable != null)
|
||||
@ -208,7 +206,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
|
||||
filter.BindValueChanged(_ =>
|
||||
{
|
||||
Rooms.Clear();
|
||||
rooms.Clear();
|
||||
hasListingResults.Value = false;
|
||||
listingPollingComponent.PollImmediately();
|
||||
});
|
||||
@ -218,11 +216,11 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
|
||||
private void onListingReceived(Room[] result)
|
||||
{
|
||||
Dictionary<long, Room> localRoomsById = Rooms.ToDictionary(r => r.RoomID!.Value);
|
||||
Dictionary<long, Room> localRoomsById = rooms.ToDictionary(r => r.RoomID!.Value);
|
||||
Dictionary<long, Room> resultRoomsById = result.ToDictionary(r => r.RoomID!.Value);
|
||||
|
||||
// Remove all local rooms no longer in the result set.
|
||||
Rooms.RemoveAll(r => !resultRoomsById.ContainsKey(r.RoomID!.Value));
|
||||
rooms.RemoveAll(r => !resultRoomsById.ContainsKey(r.RoomID!.Value));
|
||||
|
||||
// Add or update local rooms with the result set.
|
||||
foreach (var r in result)
|
||||
@ -230,7 +228,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
if (localRoomsById.TryGetValue(r.RoomID!.Value, out Room? existingRoom))
|
||||
existingRoom.CopyFrom(r);
|
||||
else
|
||||
Rooms.Add(r);
|
||||
rooms.Add(r);
|
||||
}
|
||||
|
||||
hasListingResults.Value = true;
|
||||
@ -286,14 +284,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
{
|
||||
base.OnResuming(e);
|
||||
|
||||
Debug.Assert(selectionLease != null);
|
||||
|
||||
selectionLease.Return();
|
||||
selectionLease = null;
|
||||
|
||||
if (SelectedRoom.Value?.RoomID == null)
|
||||
SelectedRoom.Value = new Room();
|
||||
|
||||
music.EnsurePlayingSomething();
|
||||
|
||||
onReturning();
|
||||
@ -415,14 +405,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
OpenNewRoom(room ?? CreateNewRoom());
|
||||
});
|
||||
|
||||
protected virtual void OpenNewRoom(Room room)
|
||||
{
|
||||
selectionLease = SelectedRoom.BeginLease(false);
|
||||
Debug.Assert(selectionLease != null);
|
||||
selectionLease.Value = room;
|
||||
|
||||
this.Push(CreateRoomSubScreen(room));
|
||||
}
|
||||
protected virtual void OpenNewRoom(Room room) => this.Push(CreateRoomSubScreen(room));
|
||||
|
||||
public void RefreshRooms() => listingPollingComponent.PollImmediately();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user