2021-07-12 14:11:53 +08: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-02-22 14:15:57 +08:00
|
|
|
|
using System.Linq;
|
2021-08-05 19:56:14 +08:00
|
|
|
|
using Humanizer;
|
2021-10-31 00:50:34 +08:00
|
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
2021-07-12 14:11:53 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
|
2021-07-13 15:02:18 +08:00
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
2021-07-12 14:11:53 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A pill that displays the playlist item count.
|
|
|
|
|
/// </summary>
|
2023-05-16 15:53:11 +08:00
|
|
|
|
public partial class PlaylistCountPill : OnlinePlayPill
|
2021-07-12 14:11:53 +08:00
|
|
|
|
{
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2022-02-23 12:42:47 +08:00
|
|
|
|
PlaylistItemStats.BindValueChanged(_ => updateCount());
|
2022-06-24 20:25:23 +08:00
|
|
|
|
Playlist.BindCollectionChanged((_, _) => updateCount(), true);
|
2021-07-12 14:11:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-21 18:37:36 +08:00
|
|
|
|
private void updateCount()
|
2021-07-12 14:11:53 +08:00
|
|
|
|
{
|
2022-02-22 14:15:57 +08: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 18:02:21 +08:00
|
|
|
|
|
2023-05-16 16:06:48 +08:00
|
|
|
|
TextFlow.Clear();
|
|
|
|
|
TextFlow.AddText(activeItems.ToLocalisableString(), s => s.Font = s.Font.With(weight: FontWeight.Bold));
|
|
|
|
|
TextFlow.AddText(" ");
|
|
|
|
|
TextFlow.AddText("Beatmap".ToQuantity(activeItems, ShowQuantityAs.None));
|
2021-07-12 14:11:53 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|