1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-20 19:42:55 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Lounge/Components/PlaylistCountPill.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

65 lines
2.0 KiB
C#
Raw Normal View History

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.
using System.ComponentModel;
using System.Linq;
2021-08-05 19:56:14 +08:00
using Humanizer;
using osu.Framework.Extensions.LocalisationExtensions;
2021-07-12 14:11:53 +08:00
using osu.Game.Graphics;
using osu.Game.Online.Rooms;
2021-07-12 14:11:53 +08:00
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>
public partial class PlaylistCountPill : OnlinePlayPill
2021-07-12 14:11:53 +08:00
{
private readonly Room room;
public PlaylistCountPill(Room room)
{
this.room = room;
}
2021-07-12 14:11:53 +08:00
protected override void LoadComplete()
{
base.LoadComplete();
room.PropertyChanged += onRoomPropertyChanged;
updateCount();
}
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
2024-11-14 16:57:32 +08:00
switch (e.PropertyName)
{
case nameof(Room.Playlist):
case nameof(Room.PlaylistItemStats):
updateCount();
break;
}
2021-07-12 14:11:53 +08:00
}
private void updateCount()
2021-07-12 14:11:53 +08:00
{
2024-11-14 16:57:32 +08:00
int activeItems = room.Playlist.Count > 0 || room.PlaylistItemStats == 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).
2024-11-14 16:57:32 +08:00
? room.Playlist.Count(i => !i.Expired)
: room.PlaylistItemStats.CountActive;
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
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
room.PropertyChanged -= onRoomPropertyChanged;
}
2021-07-12 14:11:53 +08:00
}
}