1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-11 08:47:20 +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>(); rooms = new BindableList<Room>();
Child = new PopoverContainer Child = new PopoverContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.Both,
AutoSizeAxes = Axes.Y,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Width = 0.5f, Width = 0.5f,
Child = container = new RoomsContainer Child = container = new RoomsContainer
{ {
RelativeSizeAxes = Axes.Both,
Rooms = { BindTarget = rooms }, Rooms = { BindTarget = rooms },
SelectedRoom = { BindTarget = SelectedRoom } SelectedRoom = { BindTarget = SelectedRoom }
} }

View File

@ -13,6 +13,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor; using osu.Game.Graphics.Cursor;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osu.Game.Online.Rooms; 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(); public IReadOnlyList<DrawableRoom> DrawableRooms => roomFlow.FlowingChildren.Cast<DrawableRoom>().ToArray();
private readonly ScrollContainer<Drawable> scroll;
private readonly FillFlowContainer<DrawableLoungeRoom> roomFlow; private readonly FillFlowContainer<DrawableLoungeRoom> roomFlow;
// handle deselection // handle deselection
@ -35,28 +37,29 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
public RoomsContainer() public RoomsContainer()
{ {
RelativeSizeAxes = Axes.X; InternalChild = scroll = new OsuScrollContainer
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
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.Both,
AutoSizeAxes = Axes.Y, ScrollbarOverlapsContent = false,
Child = roomFlow = new FillFlowContainer<DrawableLoungeRoom> Padding = new MarginPadding { Right = 5 },
Child = new OsuContextMenuContainer
{ {
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical, Child = roomFlow = new FillFlowContainer<DrawableLoungeRoom>
Spacing = new Vector2(10), {
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Spacing = new Vector2(10),
}
} }
}; };
} }
protected override void LoadComplete() protected override void LoadComplete()
{ {
SelectedRoom.BindValueChanged(onSelectedRoomChanged, true);
Rooms.BindCollectionChanged(roomsChanged, true); Rooms.BindCollectionChanged(roomsChanged, true);
Filter.BindValueChanged(criteria => applyFilterCriteria(criteria.NewValue), 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) private void roomsChanged(object? sender, NotifyCollectionChangedEventArgs args)
{ {
switch (args.Action) switch (args.Action)

View File

@ -17,7 +17,6 @@ using osu.Framework.Logging;
using osu.Framework.Screens; using osu.Framework.Screens;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Input; using osu.Game.Input;
using osu.Game.Online.API; using osu.Game.Online.API;
@ -82,7 +81,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
private ListingPollingComponent listingPollingComponent = null!; private ListingPollingComponent listingPollingComponent = null!;
private PopoverContainer popoverContainer = null!; private PopoverContainer popoverContainer = null!;
private LoadingLayer loadingLayer = null!; private LoadingLayer loadingLayer = null!;
private RoomsContainer roomsContainer = null!;
private SearchTextBox searchTextBox = null!; private SearchTextBox searchTextBox = null!;
protected Dropdown<RoomModeFilter> StatusDropdown { get; private set; } = null!; protected Dropdown<RoomModeFilter> StatusDropdown { get; private set; } = null!;
@ -95,8 +93,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
if (idleTracker != null) if (idleTracker != null)
isIdle.BindTo(idleTracker.IsIdle); isIdle.BindTo(idleTracker.IsIdle);
OsuScrollContainer scrollContainer;
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
listingPollingComponent = new ListingPollingComponent listingPollingComponent = new ListingPollingComponent
@ -113,17 +109,13 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
Horizontal = WaveOverlayContainer.WIDTH_PADDING, Horizontal = WaveOverlayContainer.WIDTH_PADDING,
Top = Header.HEIGHT + controls_area_height + 20, Top = Header.HEIGHT + controls_area_height + 20,
}, },
Child = scrollContainer = new OsuScrollContainer Child = new RoomsContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
ScrollbarOverlapsContent = false, Rooms = { BindTarget = rooms },
Child = roomsContainer = new RoomsContainer SelectedRoom = { BindTarget = selectedRoom },
{ Filter = { BindTarget = filter },
Rooms = { BindTarget = rooms }, }
SelectedRoom = { BindTarget = selectedRoom },
Filter = { BindTarget = filter },
}
},
}, },
loadingLayer = new LoadingLayer(true), loadingLayer = new LoadingLayer(true),
new FillFlowContainer 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() protected override void LoadComplete()