From 2dac3a6efe89934faa8cc354e5581a83bd182bd3 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 16 Oct 2019 13:58:29 +0300 Subject: [PATCH] Handle hitting the maximum allowed number of favourited beatmaps --- .../BeatmapSet/Buttons/FavouriteButton.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/BeatmapSet/Buttons/FavouriteButton.cs b/osu.Game/Overlays/BeatmapSet/Buttons/FavouriteButton.cs index fcea20ef11..e2bc1ee008 100644 --- a/osu.Game/Overlays/BeatmapSet/Buttons/FavouriteButton.cs +++ b/osu.Game/Overlays/BeatmapSet/Buttons/FavouriteButton.cs @@ -11,6 +11,7 @@ using osu.Game.Beatmaps; using osu.Game.Graphics.UserInterface; using osu.Game.Online.API; using osu.Game.Online.API.Requests; +using osu.Game.Overlays.Notifications; using osuTK; namespace osu.Game.Overlays.BeatmapSet.Buttons @@ -26,8 +27,8 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons public string TooltipText => (favourited.Value ? "Unfavourite" : "Favourite") + " this beatmapset"; - [BackgroundDependencyLoader] - private void load(IAPIProvider api) + [BackgroundDependencyLoader(true)] + private void load(IAPIProvider api, NotificationOverlay notifications) { SpriteIcon icon; AddRange(new Drawable[] @@ -68,6 +69,18 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons request?.Cancel(); request = new PostBeatmapFavouriteRequest(BeatmapSet.Value?.OnlineBeatmapSetID ?? 0, favourited.Value ? BeatmapFavouriteAction.UnFavourite : BeatmapFavouriteAction.Favourite); request.Success += () => favourited.Value = !favourited.Value; + request.Failure += exception => + { + if (exception.Message == "UnprocessableEntity") + { + notifications.Post(new SimpleNotification + { + Text = @"You have too many favourited beatmaps! Please unfavourite some before trying again.", + Icon = FontAwesome.Solid.Times, + }); + loading.Hide(); + } + }; api.Queue(request); }; }