2019-01-24 08:43:03 +00:00
|
|
|
|
// 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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-03-27 10:29:27 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-05-09 11:52:46 +00:00
|
|
|
|
using osu.Game.Audio;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Direct
|
|
|
|
|
{
|
|
|
|
|
public class PlayButton : Container
|
|
|
|
|
{
|
2018-06-22 03:12:59 +00:00
|
|
|
|
public readonly BindableBool Playing = new BindableBool();
|
2018-05-24 21:37:53 +00:00
|
|
|
|
public PreviewTrack Preview { get; private set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
private BeatmapSetInfo beatmapSet;
|
|
|
|
|
|
|
|
|
|
public BeatmapSetInfo BeatmapSet
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => beatmapSet;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == beatmapSet) return;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
beatmapSet = value;
|
|
|
|
|
|
2018-06-22 03:12:59 +00:00
|
|
|
|
Preview?.Stop();
|
|
|
|
|
Preview?.Expire();
|
|
|
|
|
Preview = null;
|
2018-06-01 18:06:37 +00:00
|
|
|
|
|
2018-06-21 07:19:07 +00:00
|
|
|
|
Playing.Value = false;
|
2018-06-01 18:06:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private Color4 hoverColour;
|
|
|
|
|
private readonly SpriteIcon icon;
|
|
|
|
|
private readonly LoadingAnimation loadingAnimation;
|
|
|
|
|
|
|
|
|
|
private const float transition_duration = 500;
|
|
|
|
|
|
|
|
|
|
private bool loading
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value)
|
2018-06-22 05:27:36 +00:00
|
|
|
|
{
|
|
|
|
|
icon.FadeTo(0.5f, transition_duration, Easing.OutQuint);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
loadingAnimation.Show();
|
2018-06-22 05:27:36 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
else
|
2018-06-22 05:27:36 +00:00
|
|
|
|
{
|
|
|
|
|
icon.FadeTo(1, transition_duration, Easing.OutQuint);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
loadingAnimation.Hide();
|
2018-06-22 05:27:36 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PlayButton(BeatmapSetInfo setInfo = null)
|
|
|
|
|
{
|
|
|
|
|
BeatmapSet = setInfo;
|
|
|
|
|
AddRange(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
icon = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
FillMode = FillMode.Fit,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-04-02 10:55:24 +00:00
|
|
|
|
Icon = FontAwesome.Solid.Play,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
},
|
2018-06-22 05:27:36 +00:00
|
|
|
|
loadingAnimation = new LoadingAnimation
|
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(15),
|
|
|
|
|
},
|
2018-04-13 09:19:50 +00:00
|
|
|
|
});
|
|
|
|
|
|
2018-05-09 11:52:46 +00:00
|
|
|
|
Playing.ValueChanged += playingStateChanged;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-02-14 13:14:00 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private PreviewTrackManager previewTrackManager { get; set; }
|
2018-06-21 07:19:07 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
2020-02-14 13:14:00 +00:00
|
|
|
|
private void load(OsuColour colour)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
hoverColour = colour.Yellow;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-06-22 03:12:59 +00:00
|
|
|
|
Playing.Toggle();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
icon.FadeColour(hoverColour, 120, Easing.InOutQuint);
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnHover(e);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (!Playing.Value)
|
|
|
|
|
icon.FadeColour(Color4.White, 120, Easing.InOutQuint);
|
2018-10-02 03:02:47 +00:00
|
|
|
|
base.OnHoverLost(e);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
|
private void playingStateChanged(ValueChangedEvent<bool> e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-04-02 10:55:24 +00:00
|
|
|
|
icon.Icon = e.NewValue ? FontAwesome.Solid.Stop : FontAwesome.Solid.Play;
|
2019-02-21 09:56:34 +00:00
|
|
|
|
icon.FadeColour(e.NewValue || IsHovered ? hoverColour : Color4.White, 120, Easing.InOutQuint);
|
2018-04-18 07:04:02 +00:00
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
|
if (e.NewValue)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-06-22 03:12:59 +00:00
|
|
|
|
if (BeatmapSet == null)
|
|
|
|
|
{
|
|
|
|
|
Playing.Value = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Preview != null)
|
|
|
|
|
{
|
2019-05-23 03:07:22 +00:00
|
|
|
|
attemptStart();
|
2018-06-22 03:12:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loading = true;
|
|
|
|
|
|
|
|
|
|
LoadComponentAsync(Preview = previewTrackManager.Get(beatmapSet), preview =>
|
|
|
|
|
{
|
|
|
|
|
// beatmapset may have changed.
|
|
|
|
|
if (Preview != preview)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
AddInternal(preview);
|
|
|
|
|
loading = false;
|
|
|
|
|
preview.Stopped += () => Playing.Value = false;
|
|
|
|
|
|
|
|
|
|
// user may have changed their mind.
|
2019-02-21 09:56:34 +00:00
|
|
|
|
if (Playing.Value)
|
2019-05-23 03:07:22 +00:00
|
|
|
|
attemptStart();
|
2018-06-22 03:12:59 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Preview?.Stop();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
loading = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-23 03:07:22 +00:00
|
|
|
|
private void attemptStart()
|
|
|
|
|
{
|
|
|
|
|
if (Preview?.Start() != true)
|
|
|
|
|
Playing.Value = false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
Playing.Value = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|