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

Use bindable and disable button

This commit is contained in:
Andrei Zavatski 2019-07-22 14:35:18 +03:00
parent 2a17ed5e18
commit 3e95cb9145
2 changed files with 14 additions and 7 deletions

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,8 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
{
public class FavouriteButton : HeaderButton
{
public readonly Bindable<bool> Favourited = new Bindable<bool>();
private readonly Bindable<bool> favourited = new Bindable<bool>();
public readonly Bindable<BeatmapSetInfo> BeatmapSet = new Bindable<BeatmapSetInfo>();
[BackgroundDependencyLoader]
private void load()
@ -54,7 +56,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 +77,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,8 @@ 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,
@ -246,8 +247,6 @@ namespace osu.Game.Overlays.BeatmapSet
onlineStatusPill.Status = setInfo.NewValue.OnlineInfo.Status;
downloadButtonsContainer.FadeIn(transition_duration);
favouriteButton.Favourited.Value = setInfo.NewValue.OnlineInfo.HasFavourited;
favouriteButton.FadeIn(transition_duration);
updateDownloadButtons();