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> /// </summary>
public int FavouriteCount { get; set; } public int FavouriteCount { get; set; }
/// <summary>
/// Whether this beatmap set has been favourited by the current user.
/// </summary>
public bool HasFavourited { get; set; }
/// <summary> /// <summary>
/// The availability of this beatmap set. /// The availability of this beatmap set.
/// </summary> /// </summary>

View File

@ -30,6 +30,9 @@ namespace osu.Game.Online.API.Requests.Responses
[JsonProperty(@"preview_url")] [JsonProperty(@"preview_url")]
private string preview { get; set; } private string preview { get; set; }
[JsonProperty(@"has_favourited")]
private bool hasFavourited { get; set; }
[JsonProperty(@"play_count")] [JsonProperty(@"play_count")]
private int playCount { get; set; } private int playCount { get; set; }
@ -91,6 +94,7 @@ namespace osu.Game.Online.API.Requests.Responses
Ranked = ranked, Ranked = ranked,
LastUpdated = lastUpdated, LastUpdated = lastUpdated,
Availability = availability, Availability = availability,
HasFavourited = hasFavourited,
}, },
Beatmaps = beatmaps?.Select(b => b.ToBeatmap(rulesets)).ToList(), 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.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Backgrounds;
using osuTK; using osuTK;
@ -15,7 +16,9 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
{ {
public class FavouriteButton : HeaderButton 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] [BackgroundDependencyLoader]
private void load() 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) if (favourited.NewValue)
{ {
@ -67,8 +78,6 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
icon.Icon = FontAwesome.Regular.Heart; icon.Icon = FontAwesome.Regular.Heart;
} }
}; };
Action = () => Favourited.Value = !Favourited.Value;
} }
protected override void UpdateAfterChildren() protected override void UpdateAfterChildren()

View File

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