Implement basic behaviour of play button

This commit is contained in:
Bartłomiej Dach
2021-10-23 18:41:31 +02:00
parent 5d13686cdf
commit 9164f006aa
3 changed files with 83 additions and 12 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Graphics;
@ -12,17 +13,30 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
{
public class PlayButton : OsuHoverContainer
{
public PlayButton()
public BindableBool Playing { get; } = new BindableBool();
private readonly BeatmapSetInfo beatmapSetInfo;
private readonly SpriteIcon icon;
public PlayButton(BeatmapSetInfo beatmapSetInfo)
{
this.beatmapSetInfo = beatmapSetInfo;
Anchor = Origin = Anchor.Centre;
Child = new SpriteIcon
Children = new Drawable[]
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.Play,
Size = new Vector2(14)
icon = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.Play,
Size = new Vector2(14)
},
};
Action = () => Playing.Toggle();
}
[BackgroundDependencyLoader]
@ -30,5 +44,17 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
{
HoverColour = colours.Yellow;
}
protected override void LoadComplete()
{
base.LoadComplete();
Playing.BindValueChanged(_ => updateState(), true);
}
private void updateState()
{
icon.Icon = Playing.Value ? FontAwesome.Solid.Stop : FontAwesome.Solid.Play;
}
}
}