mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 15:05:34 +08:00
Tidy up implementation
This commit is contained in:
parent
61464c5c89
commit
5110ae82a1
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Diagnostics;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -20,7 +21,7 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
|
|||||||
{
|
{
|
||||||
public readonly Bindable<BeatmapSetInfo> BeatmapSet = new Bindable<BeatmapSetInfo>();
|
public readonly Bindable<BeatmapSetInfo> BeatmapSet = new Bindable<BeatmapSetInfo>();
|
||||||
|
|
||||||
private readonly Bindable<bool> favourited = new Bindable<bool>();
|
private readonly BindableBool favourited = new BindableBool();
|
||||||
|
|
||||||
private PostBeatmapFavouriteRequest request;
|
private PostBeatmapFavouriteRequest request;
|
||||||
private DimmedLoadingLayer loading;
|
private DimmedLoadingLayer loading;
|
||||||
@ -44,40 +45,45 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
|
|||||||
loading = new DimmedLoadingLayer(),
|
loading = new DimmedLoadingLayer(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
favourited.ValueChanged += favourited => icon.Icon = favourited.NewValue ? FontAwesome.Solid.Heart : FontAwesome.Regular.Heart;
|
||||||
|
|
||||||
BeatmapSet.BindValueChanged(setInfo =>
|
BeatmapSet.BindValueChanged(setInfo =>
|
||||||
{
|
{
|
||||||
if (setInfo.NewValue?.OnlineInfo?.HasFavourited == null)
|
Enabled.Value = BeatmapSet.Value?.OnlineBeatmapSetID > 0;
|
||||||
return;
|
favourited.Value = setInfo.NewValue?.OnlineInfo?.HasFavourited ?? false;
|
||||||
|
}, true);
|
||||||
favourited.Value = setInfo.NewValue.OnlineInfo.HasFavourited;
|
|
||||||
});
|
|
||||||
|
|
||||||
favourited.ValueChanged += favourited =>
|
|
||||||
{
|
|
||||||
loading.Hide();
|
|
||||||
|
|
||||||
icon.Icon = favourited.NewValue ? FontAwesome.Solid.Heart : FontAwesome.Regular.Heart;
|
|
||||||
};
|
|
||||||
|
|
||||||
Action = () =>
|
Action = () =>
|
||||||
{
|
{
|
||||||
if (loading.State.Value == Visibility.Visible)
|
if (loading.State.Value == Visibility.Visible)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// guaranteed by disabled state abvove.
|
||||||
|
Debug.Assert(BeatmapSet.Value.OnlineBeatmapSetID != null);
|
||||||
|
|
||||||
loading.Show();
|
loading.Show();
|
||||||
|
|
||||||
request?.Cancel();
|
request?.Cancel();
|
||||||
request = new PostBeatmapFavouriteRequest(BeatmapSet.Value?.OnlineBeatmapSetID ?? 0, favourited.Value ? BeatmapFavouriteAction.UnFavourite : BeatmapFavouriteAction.Favourite);
|
|
||||||
request.Success += () => favourited.Value = !favourited.Value;
|
request = new PostBeatmapFavouriteRequest(BeatmapSet.Value.OnlineBeatmapSetID.Value, favourited.Value ? BeatmapFavouriteAction.UnFavourite : BeatmapFavouriteAction.Favourite);
|
||||||
request.Failure += exception =>
|
|
||||||
|
request.Success += () =>
|
||||||
|
{
|
||||||
|
favourited.Toggle();
|
||||||
|
loading.Hide();
|
||||||
|
};
|
||||||
|
|
||||||
|
request.Failure += e =>
|
||||||
{
|
{
|
||||||
notifications.Post(new SimpleNotification
|
notifications.Post(new SimpleNotification
|
||||||
{
|
{
|
||||||
Text = exception.Message,
|
Text = e.Message,
|
||||||
Icon = FontAwesome.Solid.Times,
|
Icon = FontAwesome.Solid.Times,
|
||||||
});
|
});
|
||||||
|
|
||||||
loading.Hide();
|
loading.Hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
api.Queue(request);
|
api.Queue(request);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user