1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-11 02:17:19 +08:00

Encapsulate RoomsContainer scroll a bit better

This commit is contained in:
Dan Balasescu 2025-02-12 21:57:18 +09:00
parent 1b07b6d16f
commit 74ccac37ae
No known key found for this signature in database
3 changed files with 30 additions and 35 deletions

View File

@ -32,13 +32,13 @@ namespace osu.Game.Tests.Visual.Multiplayer
rooms = new BindableList<Room>();
Child = new PopoverContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 0.5f,
Child = container = new RoomsContainer
{
RelativeSizeAxes = Axes.Both,
Rooms = { BindTarget = rooms },
SelectedRoom = { BindTarget = SelectedRoom }
}

View File

@ -13,6 +13,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
using osu.Game.Input.Bindings;
using osu.Game.Online.Rooms;
@ -28,6 +29,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
public IReadOnlyList<DrawableRoom> DrawableRooms => roomFlow.FlowingChildren.Cast<DrawableRoom>().ToArray();
private readonly ScrollContainer<Drawable> scroll;
private readonly FillFlowContainer<DrawableLoungeRoom> roomFlow;
// handle deselection
@ -35,28 +37,29 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
public RoomsContainer()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
// account for the fact we are in a scroll container and want a bit of spacing from the scroll bar.
Padding = new MarginPadding { Right = 5 };
InternalChild = new OsuContextMenuContainer
InternalChild = scroll = new OsuScrollContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Child = roomFlow = new FillFlowContainer<DrawableLoungeRoom>
RelativeSizeAxes = Axes.Both,
ScrollbarOverlapsContent = false,
Padding = new MarginPadding { Right = 5 },
Child = new OsuContextMenuContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(10),
Child = roomFlow = new FillFlowContainer<DrawableLoungeRoom>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(10),
}
}
};
}
protected override void LoadComplete()
{
SelectedRoom.BindValueChanged(onSelectedRoomChanged, true);
Rooms.BindCollectionChanged(roomsChanged, true);
Filter.BindValueChanged(criteria => applyFilterCriteria(criteria.NewValue), true);
}
@ -119,6 +122,14 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
}
}
private void onSelectedRoomChanged(ValueChangedEvent<Room?> room)
{
// scroll selected room into view on selection.
var drawable = DrawableRooms.FirstOrDefault(r => r.Room == room.NewValue);
if (drawable != null)
scroll.ScrollIntoView(drawable);
}
private void roomsChanged(object? sender, NotifyCollectionChangedEventArgs args)
{
switch (args.Action)

View File

@ -17,7 +17,6 @@ using osu.Framework.Logging;
using osu.Framework.Screens;
using osu.Framework.Threading;
using osu.Game.Configuration;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input;
using osu.Game.Online.API;
@ -82,7 +81,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
private ListingPollingComponent listingPollingComponent = null!;
private PopoverContainer popoverContainer = null!;
private LoadingLayer loadingLayer = null!;
private RoomsContainer roomsContainer = null!;
private SearchTextBox searchTextBox = null!;
protected Dropdown<RoomModeFilter> StatusDropdown { get; private set; } = null!;
@ -95,8 +93,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
if (idleTracker != null)
isIdle.BindTo(idleTracker.IsIdle);
OsuScrollContainer scrollContainer;
InternalChildren = new Drawable[]
{
listingPollingComponent = new ListingPollingComponent
@ -113,17 +109,13 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
Horizontal = WaveOverlayContainer.WIDTH_PADDING,
Top = Header.HEIGHT + controls_area_height + 20,
},
Child = scrollContainer = new OsuScrollContainer
Child = new RoomsContainer
{
RelativeSizeAxes = Axes.Both,
ScrollbarOverlapsContent = false,
Child = roomsContainer = new RoomsContainer
{
Rooms = { BindTarget = rooms },
SelectedRoom = { BindTarget = selectedRoom },
Filter = { BindTarget = filter },
}
},
Rooms = { BindTarget = rooms },
SelectedRoom = { BindTarget = selectedRoom },
Filter = { BindTarget = filter },
}
},
loadingLayer = new LoadingLayer(true),
new FillFlowContainer
@ -178,14 +170,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
},
},
};
// scroll selected room into view on selection.
selectedRoom.BindValueChanged(val =>
{
var drawable = roomsContainer.DrawableRooms.FirstOrDefault(r => r.Room == val.NewValue);
if (drawable != null)
scrollContainer.ScrollIntoView(drawable);
});
}
protected override void LoadComplete()