1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-26 03:49:56 +08:00

Add simple tray

This commit is contained in:
Dan Balasescu
2025-11-18 17:26:34 +09:00
Unverified
parent 549cc08bfe
commit bb017ade64
3 changed files with 182 additions and 5 deletions
@@ -0,0 +1,38 @@
// 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.Linq;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Playlists;
using osu.Game.Tests.Visual.OnlinePlay;
namespace osu.Game.Tests.Visual.Playlists
{
public partial class TestScenePlaylistTray : OnlinePlayTestScene
{
private Room room = null!;
private PlaylistsSongSelectV2.PlaylistTray tray = null!;
public override void SetUpSteps()
{
base.SetUpSteps();
AddStep("add tray", () => Child = tray = new PlaylistsSongSelectV2.PlaylistTray(room = new Room())
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
});
}
[Test]
public void TestAddItem()
{
AddStep("add playlist item", () =>
{
room.Playlist = room.Playlist.Append(new PlaylistItem(CreateAPIBeatmap())).ToArray();
});
}
}
}
@@ -0,0 +1,128 @@
// 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.ComponentModel;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.Rooms;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.OnlinePlay.Playlists
{
public partial class PlaylistsSongSelectV2
{
public partial class PlaylistTray : CompositeDrawable
{
private readonly Room room;
private OsuScrollContainer scroll = null!;
private FillFlowContainer flow = null!;
public PlaylistTray(Room room)
{
this.room = room;
Size = new Vector2(400, 75);
}
[BackgroundDependencyLoader]
private void load()
{
Masking = true;
CornerRadius = 20;
InternalChildren = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
Alpha = 0.9f
},
new GridContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
Height = DrawableRoomPlaylistItem.HEIGHT,
Padding = new MarginPadding { Horizontal = 20 },
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension()
},
Content = new[]
{
new Drawable[]
{
new OsuSpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Text = "Playlist",
Font = OsuFont.Default.With(size: 20)
},
scroll = new OsuScrollContainer(Direction.Horizontal)
{
RelativeSizeAxes = Axes.Both,
Margin = new MarginPadding { Left = 10 },
ScrollbarVisible = false,
Child = flow = new FillFlowContainer
{
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Direction = FillDirection.Horizontal
}
}
},
}
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
room.PropertyChanged += onRoomPropertyChanged;
updateRoomPlaylist();
}
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Room.Playlist))
updateRoomPlaylist();
}
private void updateRoomPlaylist()
{
if (room.Playlist.Count > 0)
{
flow.Add(new DrawableRoomPlaylistItem(room.Playlist[^1], loadImmediately: true)
{
RelativeSizeAxes = Axes.None,
Width = 250,
AllowReordering = false,
});
}
scroll.ScrollToStart(animated: false);
this.FadeIn(200);
ScheduleAfterChildren(() => scroll.ScrollToEnd());
this.Delay(1000).FadeOut(200);
}
// Disallow the user from interacting with the scrolling elements.
public override bool PropagatePositionalInputSubTree => false;
public override bool PropagateNonPositionalInputSubTree => false;
}
}
}
@@ -61,10 +61,23 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
[BackgroundDependencyLoader]
private void load()
{
AddInternal(freeModSelect = new FreeModSelectOverlay
AddRangeInternal(new Drawable[]
{
SelectedMods = { BindTarget = freeMods },
IsValidMod = isValidAllowedMod,
freeModSelect = new FreeModSelectOverlay
{
SelectedMods = { BindTarget = freeMods },
IsValidMod = isValidAllowedMod,
},
new PlaylistTray(room)
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Margin = new MarginPadding
{
Bottom = ScreenFooterButton.HEIGHT,
Right = OsuGame.SCREEN_EDGE_MARGIN
}
}
});
}
@@ -195,8 +208,6 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
buttons.Single(i => i is FooterButtonMods).TooltipText = MultiplayerMatchStrings.RequiredModsButtonTooltip;
buttons.Insert(0, new FooterButtonPlaylistV2(room));
buttons.InsertRange(buttons.FindIndex(b => b is FooterButtonMods) + 1,
[
new FooterButtonFreeModsV2(freeModSelect)