mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 08:52:55 +08:00
Use bindable and disable button
This commit is contained in:
parent
2a17ed5e18
commit
3e95cb9145
@ -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,8 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
|
|||||||
{
|
{
|
||||||
public class FavouriteButton : HeaderButton
|
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]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
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)
|
if (favourited.NewValue)
|
||||||
{
|
{
|
||||||
@ -67,8 +77,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()
|
||||||
|
@ -161,7 +161,8 @@ 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,
|
||||||
@ -246,8 +247,6 @@ namespace osu.Game.Overlays.BeatmapSet
|
|||||||
onlineStatusPill.Status = setInfo.NewValue.OnlineInfo.Status;
|
onlineStatusPill.Status = setInfo.NewValue.OnlineInfo.Status;
|
||||||
|
|
||||||
downloadButtonsContainer.FadeIn(transition_duration);
|
downloadButtonsContainer.FadeIn(transition_duration);
|
||||||
|
|
||||||
favouriteButton.Favourited.Value = setInfo.NewValue.OnlineInfo.HasFavourited;
|
|
||||||
favouriteButton.FadeIn(transition_duration);
|
favouriteButton.FadeIn(transition_duration);
|
||||||
|
|
||||||
updateDownloadButtons();
|
updateDownloadButtons();
|
||||||
|
Loading…
Reference in New Issue
Block a user