1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-10 22:17:20 +08:00

Rename RoomsContainer and scope down bindables

This commit is contained in:
Dean Herbert 2025-03-04 15:05:12 +09:00
parent 0696cfa4f2
commit 9e8a611728
No known key found for this signature in database
5 changed files with 39 additions and 26 deletions

View File

@ -21,7 +21,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
public partial class TestSceneLoungeRoomsContainer : OnlinePlayTestScene
{
private BindableList<Room> rooms = null!;
private RoomsContainer container = null!;
private RoomListing container = null!;
public override void SetUpSteps()
{
@ -36,7 +36,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 0.5f,
Child = container = new RoomsContainer
Child = container = new RoomListing
{
RelativeSizeAxes = Axes.Both,
Rooms = { BindTarget = rooms },

View File

@ -26,7 +26,7 @@ namespace osu.Game.Tests.Visual.Playlists
AddUntilStep("wait for present", () => loungeScreen.IsCurrentScreen());
}
private RoomsContainer roomsContainer => loungeScreen.ChildrenOfType<RoomsContainer>().First();
private RoomListing roomListing => loungeScreen.ChildrenOfType<RoomListing>().First();
[Test]
public void TestManyRooms()
@ -41,13 +41,13 @@ namespace osu.Game.Tests.Visual.Playlists
createRooms(GenerateRooms(30));
AddStep("move mouse to third room", () => InputManager.MoveMouseTo(roomsContainer.DrawableRooms[2]));
AddStep("move mouse to third room", () => InputManager.MoveMouseTo(roomListing.DrawableRooms[2]));
AddStep("hold down", () => InputManager.PressButton(MouseButton.Left));
AddStep("drag to top", () => InputManager.MoveMouseTo(roomsContainer.DrawableRooms[0]));
AddStep("drag to top", () => InputManager.MoveMouseTo(roomListing.DrawableRooms[0]));
AddAssert("first and second room masked", ()
=> !checkRoomVisible(roomsContainer.DrawableRooms[0]) &&
!checkRoomVisible(roomsContainer.DrawableRooms[1]));
=> !checkRoomVisible(roomListing.DrawableRooms[0]) &&
!checkRoomVisible(roomListing.DrawableRooms[1]));
}
[Test]
@ -55,10 +55,10 @@ namespace osu.Game.Tests.Visual.Playlists
{
createRooms(GenerateRooms(30));
AddStep("select last room", () => roomsContainer.DrawableRooms[^1].TriggerClick());
AddStep("select last room", () => roomListing.DrawableRooms[^1].TriggerClick());
AddUntilStep("first room is masked", () => !checkRoomVisible(roomsContainer.DrawableRooms[0]));
AddUntilStep("last room is not masked", () => checkRoomVisible(roomsContainer.DrawableRooms[^1]));
AddUntilStep("first room is masked", () => !checkRoomVisible(roomListing.DrawableRooms[0]));
AddUntilStep("last room is not masked", () => checkRoomVisible(roomListing.DrawableRooms[^1]));
}
private bool checkRoomVisible(DrawableRoom room) =>

View File

@ -204,7 +204,7 @@ namespace osu.Game.Screens.OnlinePlay
ScrollContainer.ScrollIntoView(drawableItem);
}
#region Key selection logic (shared with BeatmapCarousel and RoomsContainer)
#region Key selection logic (shared with BeatmapCarousel and RoomListing)
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{

View File

@ -21,12 +21,25 @@ using osuTK;
namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{
public partial class RoomsContainer : CompositeDrawable, IKeyBindingHandler<GlobalAction>
public partial class RoomListing : CompositeDrawable, IKeyBindingHandler<GlobalAction>
{
/// <summary>
/// Rooms which should be displayed. Should be managed externally.
/// </summary>
public readonly BindableList<Room> Rooms = new BindableList<Room>();
public readonly Bindable<Room?> SelectedRoom = new Bindable<Room?>();
/// <summary>
/// The current filter criteria. Should be managed externally.
/// </summary>
public readonly Bindable<FilterCriteria?> Filter = new Bindable<FilterCriteria?>();
/// <summary>
/// The currently user-selected room.
/// </summary>
public IBindable<Room?> SelectedRoom => selectedRoom;
private readonly Bindable<Room?> selectedRoom = new Bindable<Room?>();
public IReadOnlyList<DrawableRoom> DrawableRooms => roomFlow.FlowingChildren.Cast<DrawableRoom>().ToArray();
private readonly ScrollContainer<Drawable> scroll;
@ -35,7 +48,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
// handle deselection
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
public RoomsContainer()
public RoomListing()
{
InternalChild = scroll = new OsuScrollContainer
{
@ -158,7 +171,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
{
foreach (var room in rooms)
{
var drawableRoom = new DrawableLoungeRoom(room) { SelectedRoom = SelectedRoom };
var drawableRoom = new DrawableLoungeRoom(room) { SelectedRoom = selectedRoom };
roomFlow.Add(drawableRoom);
@ -177,7 +190,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
// selection may have a lease due to being in a sub screen.
if (SelectedRoom.Value == r && !SelectedRoom.Disabled)
SelectedRoom.Value = null;
selectedRoom.Value = null;
}
}
@ -187,13 +200,13 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
// selection may have a lease due to being in a sub screen.
if (!SelectedRoom.Disabled)
SelectedRoom.Value = null;
selectedRoom.Value = null;
}
protected override bool OnClick(ClickEvent e)
{
if (!SelectedRoom.Disabled)
SelectedRoom.Value = null;
selectedRoom.Value = null;
return base.OnClick(e);
}
@ -240,7 +253,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
// we already have a valid selection only change selection if we still have a room to switch to.
if (room != null)
SelectedRoom.Value = room;
selectedRoom.Value = room;
}
#endregion

View File

@ -38,7 +38,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
protected override BackgroundScreen CreateBackground() => new LoungeBackgroundScreen
{
SelectedRoom = { BindTarget = roomsContainer.SelectedRoom }
SelectedRoom = { BindTarget = roomListing.SelectedRoom }
};
protected override UserActivity InitialActivity => new UserActivity.SearchingForLobby();
@ -74,7 +74,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
private readonly Bindable<bool> hasListingResults = new Bindable<bool>();
private readonly IBindable<bool> operationInProgress = new Bindable<bool>();
private readonly IBindable<bool> isIdle = new BindableBool();
private RoomsContainer roomsContainer = null!;
private RoomListing roomListing = null!;
private LoungeListingPoller listingPoller = null!;
private PopoverContainer popoverContainer = null!;
private LoadingLayer loadingLayer = null!;
@ -106,7 +106,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
Horizontal = WaveOverlayContainer.WIDTH_PADDING,
Top = Header.HEIGHT + controls_area_height + 20,
},
Child = roomsContainer = new RoomsContainer
Child = roomListing = new RoomListing
{
RelativeSizeAxes = Axes.Both,
Filter = { BindTarget = filter },
@ -185,7 +185,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
filter.BindValueChanged(_ =>
{
roomsContainer.Rooms.Clear();
roomListing.Rooms.Clear();
hasListingResults.Value = false;
listingPoller.PollImmediately();
});
@ -195,11 +195,11 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
private void onListingReceived(Room[] result)
{
Dictionary<long, Room> localRoomsById = roomsContainer.Rooms.ToDictionary(r => r.RoomID!.Value);
Dictionary<long, Room> localRoomsById = roomListing.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.
roomsContainer.Rooms.RemoveAll(r => !resultRoomsById.ContainsKey(r.RoomID!.Value));
roomListing.Rooms.RemoveAll(r => !resultRoomsById.ContainsKey(r.RoomID!.Value));
// Add or update local rooms with the result set.
foreach (var r in result)
@ -207,7 +207,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
if (localRoomsById.TryGetValue(r.RoomID!.Value, out Room? existingRoom))
existingRoom.CopyFrom(r);
else
roomsContainer.Rooms.Add(r);
roomListing.Rooms.Add(r);
}
hasListingResults.Value = true;