2021-07-12 15:11:53 +09:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 16:37:17 +09:00
|
|
|
#nullable disable
|
|
|
|
|
2022-02-22 15:15:57 +09:00
|
|
|
using System.Linq;
|
2021-08-05 20:56:14 +09:00
|
|
|
using Humanizer;
|
2021-07-12 15:18:38 +09:00
|
|
|
using osu.Framework.Allocation;
|
2021-10-30 18:50:34 +02:00
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
2021-07-12 15:11:53 +09:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
2021-07-13 16:02:18 +09:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
2021-07-12 15:11:53 +09:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A pill that displays the playlist item count.
|
|
|
|
/// </summary>
|
2021-07-12 15:18:38 +09:00
|
|
|
public class PlaylistCountPill : OnlinePlayComposite
|
2021-07-12 15:11:53 +09:00
|
|
|
{
|
|
|
|
private OsuTextFlowContainer count;
|
|
|
|
|
2021-07-12 15:18:38 +09:00
|
|
|
public PlaylistCountPill()
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
InternalChild = new PillContainer
|
|
|
|
{
|
|
|
|
Child = count = new OsuTextFlowContainer(s => s.Font = OsuFont.GetFont(size: 12))
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-07-12 15:11:53 +09:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-02-23 13:42:47 +09:00
|
|
|
PlaylistItemStats.BindValueChanged(_ => updateCount());
|
2022-06-24 21:25:23 +09:00
|
|
|
Playlist.BindCollectionChanged((_, _) => updateCount(), true);
|
2021-07-12 15:11:53 +09:00
|
|
|
}
|
|
|
|
|
2022-02-21 19:37:36 +09:00
|
|
|
private void updateCount()
|
2021-07-12 15:11:53 +09:00
|
|
|
{
|
2022-02-22 15:15:57 +09:00
|
|
|
int activeItems = Playlist.Count > 0 || PlaylistItemStats.Value == null
|
|
|
|
// For now, use the playlist as the source of truth if it has any items.
|
|
|
|
// This allows the count to display correctly on the room screen (after joining a room).
|
|
|
|
? Playlist.Count(i => !i.Expired)
|
|
|
|
: PlaylistItemStats.Value.CountActive;
|
2022-02-21 19:02:21 +09:00
|
|
|
|
2021-07-12 15:11:53 +09:00
|
|
|
count.Clear();
|
2022-02-21 19:02:21 +09:00
|
|
|
count.AddText(activeItems.ToLocalisableString(), s => s.Font = s.Font.With(weight: FontWeight.Bold));
|
2021-08-05 20:56:14 +09:00
|
|
|
count.AddText(" ");
|
2022-02-21 19:02:21 +09:00
|
|
|
count.AddText("Beatmap".ToQuantity(activeItems, ShowQuantityAs.None));
|
2021-07-12 15:11:53 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|