2021-10-18 02:50:44 +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 Humanizer;
|
2021-11-08 00:42:32 +08:00
|
|
|
using osu.Framework.Bindables;
|
2021-10-18 02:50:44 +08:00
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2021-11-08 00:42:32 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2021-10-18 02:50:44 +08:00
|
|
|
using osu.Game.Resources.Localisation.Web;
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables.Cards.Statistics
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Shows the number of favourites that a beatmap set has received.
|
|
|
|
/// </summary>
|
2021-11-08 00:42:32 +08:00
|
|
|
public class FavouritesStatistic : BeatmapCardStatistic, IHasCurrentValue<BeatmapSetFavouriteState>
|
2021-10-18 02:50:44 +08:00
|
|
|
{
|
2021-11-08 00:42:32 +08:00
|
|
|
private readonly BindableWithCurrent<BeatmapSetFavouriteState> current;
|
|
|
|
|
|
|
|
public Bindable<BeatmapSetFavouriteState> Current
|
|
|
|
{
|
|
|
|
get => current.Current;
|
|
|
|
set => current.Current = value;
|
|
|
|
}
|
|
|
|
|
2021-10-18 02:50:44 +08:00
|
|
|
public FavouritesStatistic(IBeatmapSetOnlineInfo onlineInfo)
|
|
|
|
{
|
2021-11-08 00:42:32 +08:00
|
|
|
current = new BindableWithCurrent<BeatmapSetFavouriteState>(new BeatmapSetFavouriteState(onlineInfo.HasFavourited, onlineInfo.FavouriteCount));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
current.BindValueChanged(_ => updateState(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateState()
|
|
|
|
{
|
|
|
|
Icon = current.Value.Favourited ? FontAwesome.Solid.Heart : FontAwesome.Regular.Heart;
|
|
|
|
Text = current.Value.FavouriteCount.ToMetric(decimals: 1);
|
|
|
|
TooltipText = BeatmapsStrings.PanelFavourites(current.Value.FavouriteCount.ToLocalisableString(@"N0"));
|
2021-10-18 02:50:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|