1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-01 20:25:34 +08:00

Expose as IBindable for added safety

This commit is contained in:
Dean Herbert 2021-01-11 01:47:04 +09:00
parent e4eb44df6e
commit bd37723788
3 changed files with 15 additions and 11 deletions

View File

@ -38,7 +38,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels
private Container content; private Container content;
public PreviewTrack Preview => PlayButton.Preview; public PreviewTrack Preview => PlayButton.Preview;
public Bindable<bool> PreviewPlaying => PlayButton?.Playing; public IBindable<bool> PreviewPlaying => PlayButton?.Playing;
protected abstract PlayButton PlayButton { get; } protected abstract PlayButton PlayButton { get; }
protected abstract Box PreviewBar { get; } protected abstract Box PreviewBar { get; }

View File

@ -18,7 +18,10 @@ namespace osu.Game.Overlays.BeatmapListing.Panels
{ {
public class PlayButton : Container public class PlayButton : Container
{ {
public readonly BindableBool Playing = new BindableBool(); public IBindable<bool> Playing => playing;
private readonly BindableBool playing = new BindableBool();
public PreviewTrack Preview { get; private set; } public PreviewTrack Preview { get; private set; }
private BeatmapSetInfo beatmapSet; private BeatmapSetInfo beatmapSet;
@ -36,7 +39,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels
Preview?.Expire(); Preview?.Expire();
Preview = null; Preview = null;
Playing.Value = false; playing.Value = false;
} }
} }
@ -82,7 +85,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels
}, },
}); });
Playing.ValueChanged += playingStateChanged; playing.ValueChanged += playingStateChanged;
} }
[Resolved] [Resolved]
@ -96,7 +99,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels
protected override bool OnClick(ClickEvent e) protected override bool OnClick(ClickEvent e)
{ {
Playing.Toggle(); playing.Toggle();
return true; return true;
} }
@ -108,7 +111,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels
protected override void OnHoverLost(HoverLostEvent e) protected override void OnHoverLost(HoverLostEvent e)
{ {
if (!Playing.Value) if (!playing.Value)
icon.FadeColour(Color4.White, 120, Easing.InOutQuint); icon.FadeColour(Color4.White, 120, Easing.InOutQuint);
base.OnHoverLost(e); base.OnHoverLost(e);
} }
@ -122,7 +125,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels
{ {
if (BeatmapSet == null) if (BeatmapSet == null)
{ {
Playing.Value = false; playing.Value = false;
return; return;
} }
@ -144,10 +147,10 @@ namespace osu.Game.Overlays.BeatmapListing.Panels
loading = false; loading = false;
// make sure that the update of value of Playing (and the ensuing value change callbacks) // make sure that the update of value of Playing (and the ensuing value change callbacks)
// are marshaled back to the update thread. // are marshaled back to the update thread.
preview.Stopped += () => Schedule(() => Playing.Value = false); preview.Stopped += () => Schedule(() => playing.Value = false);
// user may have changed their mind. // user may have changed their mind.
if (Playing.Value) if (playing.Value)
attemptStart(); attemptStart();
}); });
} }
@ -161,7 +164,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels
private void attemptStart() private void attemptStart()
{ {
if (Preview?.Start() != true) if (Preview?.Start() != true)
Playing.Value = false; playing.Value = false;
} }
} }
} }

View File

@ -24,7 +24,8 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
private readonly PlayButton playButton; private readonly PlayButton playButton;
private PreviewTrack preview => playButton.Preview; private PreviewTrack preview => playButton.Preview;
public Bindable<bool> Playing => playButton.Playing;
public IBindable<bool> Playing => playButton.Playing;
public BeatmapSetInfo BeatmapSet public BeatmapSetInfo BeatmapSet
{ {