1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 05:32:54 +08:00

Retrieve the actual favourite value for beatmaps (#5426)

Retrieve the actual favourite value for beatmaps

Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
Dean Herbert 2019-07-22 22:32:49 +09:00 committed by GitHub
commit 0330c3e14e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 5 deletions

View File

@ -66,6 +66,11 @@ namespace osu.Game.Beatmaps
/// </summary>
public int FavouriteCount { get; set; }
/// <summary>
/// Whether this beatmap set has been favourited by the current user.
/// </summary>
public bool HasFavourited { get; set; }
/// <summary>
/// The availability of this beatmap set.
/// </summary>

View File

@ -30,6 +30,9 @@ namespace osu.Game.Online.API.Requests.Responses
[JsonProperty(@"preview_url")]
private string preview { get; set; }
[JsonProperty(@"has_favourited")]
private bool hasFavourited { get; set; }
[JsonProperty(@"play_count")]
private int playCount { get; set; }
@ -91,6 +94,7 @@ namespace osu.Game.Online.API.Requests.Responses
Ranked = ranked,
LastUpdated = lastUpdated,
Availability = availability,
HasFavourited = hasFavourited,
},
Beatmaps = beatmaps?.Select(b => b.ToBeatmap(rulesets)).ToList(),
};

View File

@ -7,6 +7,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using osuTK;
@ -15,7 +16,9 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
{
public class FavouriteButton : HeaderButton
{
public readonly Bindable<bool> Favourited = new Bindable<bool>();
public readonly Bindable<BeatmapSetInfo> BeatmapSet = new Bindable<BeatmapSetInfo>();
private readonly Bindable<bool> favourited = new Bindable<bool>();
[BackgroundDependencyLoader]
private void load()
@ -54,7 +57,15 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
},
});
Favourited.ValueChanged += favourited =>
BeatmapSet.BindValueChanged(setInfo =>
{
if (setInfo.NewValue?.OnlineInfo?.HasFavourited == null)
return;
favourited.Value = setInfo.NewValue.OnlineInfo.HasFavourited;
});
favourited.ValueChanged += favourited =>
{
if (favourited.NewValue)
{
@ -67,8 +78,6 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
icon.Icon = FontAwesome.Regular.Heart;
}
};
Action = () => Favourited.Value = !Favourited.Value;
}
protected override void UpdateAfterChildren()

View File

@ -161,7 +161,10 @@ namespace osu.Game.Overlays.BeatmapSet
Margin = new MarginPadding { Top = 10 },
Children = new Drawable[]
{
favouriteButton = new FavouriteButton(),
favouriteButton = new FavouriteButton
{
BeatmapSet = { BindTarget = BeatmapSet }
},
downloadButtonsContainer = new FillFlowContainer
{
RelativeSizeAxes = Axes.Both,