2019-01-24 17:43:03 +09: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 18:19:50 +09:00
|
|
|
|
|
2017-09-12 21:24:43 -03:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 19:04:31 +09:00
|
|
|
|
using osu.Framework.Bindables;
|
2017-09-12 21:24:43 -03:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-10-02 12:02:47 +09:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-05-25 00:37:53 +03:00
|
|
|
|
using osu.Game.Audio;
|
2024-05-27 17:09:35 +09:00
|
|
|
|
using osu.Game.Beatmaps;
|
2017-09-12 21:24:43 -03:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-11-20 16:51:59 +09:00
|
|
|
|
using osuTK;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-04-18 16:04:02 +09:00
|
|
|
|
namespace osu.Game.Overlays.BeatmapSet.Buttons
|
2017-09-12 21:24:43 -03:00
|
|
|
|
{
|
|
|
|
|
public partial class PreviewButton : OsuClickableContainer
|
|
|
|
|
{
|
2020-02-04 19:52:32 +01:00
|
|
|
|
private readonly Box background, progress;
|
2017-09-29 23:08:30 +02:00
|
|
|
|
private readonly PlayButton playButton;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2023-06-24 00:59:36 +09:00
|
|
|
|
private PreviewTrack? preview => playButton.Preview;
|
2021-01-11 01:47:04 +09:00
|
|
|
|
|
|
|
|
|
public IBindable<bool> Playing => playButton.Playing;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2024-05-27 17:09:35 +09:00
|
|
|
|
public IBeatmapSetInfo BeatmapSet
|
2017-09-13 18:25:23 -03:00
|
|
|
|
{
|
2019-02-28 13:58:19 +09:00
|
|
|
|
get => playButton.BeatmapSet;
|
|
|
|
|
set => playButton.BeatmapSet = value;
|
2017-09-13 18:25:23 -03:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-09-13 18:25:23 -03:00
|
|
|
|
public PreviewButton()
|
2017-09-12 21:24:43 -03:00
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2020-02-04 19:52:32 +01:00
|
|
|
|
background = new Box
|
2017-09-12 21:24:43 -03:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-02-04 19:52:32 +01:00
|
|
|
|
Alpha = 0.5f
|
2017-09-12 21:24:43 -03:00
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 3,
|
|
|
|
|
Child = progress = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Width = 0f,
|
|
|
|
|
Alpha = 0f,
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-10-06 21:06:37 +02:00
|
|
|
|
playButton = new PlayButton
|
2017-09-12 21:24:43 -03:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(18),
|
2017-09-15 13:47:03 -03:00
|
|
|
|
},
|
2017-09-12 21:24:43 -03:00
|
|
|
|
};
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2021-08-04 17:27:44 +09:00
|
|
|
|
Action = () => playButton.TriggerClick();
|
2019-02-22 17:51:39 +09:00
|
|
|
|
Playing.ValueChanged += playing => progress.FadeTo(playing.NewValue ? 1 : 0, 100);
|
2017-09-12 21:24:43 -03:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-09-12 21:24:43 -03:00
|
|
|
|
[BackgroundDependencyLoader]
|
2020-02-04 21:01:02 +01:00
|
|
|
|
private void load(OsuColour colours, OverlayColourProvider colourProvider)
|
2017-09-12 21:24:43 -03:00
|
|
|
|
{
|
|
|
|
|
progress.Colour = colours.Yellow;
|
2020-02-04 21:01:02 +01:00
|
|
|
|
background.Colour = colourProvider.Background6;
|
2017-09-12 21:24:43 -03:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-09-12 21:24:43 -03:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-10-14 05:58:06 +03:00
|
|
|
|
if (Playing.Value && preview != null)
|
2017-09-12 21:24:43 -03:00
|
|
|
|
{
|
2018-01-17 20:35:28 +01:00
|
|
|
|
// prevent negative (potential infinite) width if a track without length was loaded
|
2018-06-21 16:19:07 +09:00
|
|
|
|
progress.Width = preview.Length > 0 ? (float)(preview.CurrentTime / preview.Length) : 0f;
|
2017-09-12 21:24:43 -03:00
|
|
|
|
}
|
2018-04-18 16:04:02 +09:00
|
|
|
|
else
|
|
|
|
|
progress.Width = 0;
|
2017-09-12 21:24:43 -03:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-10-02 12:02:47 +09:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2017-09-12 21:24:43 -03:00
|
|
|
|
{
|
2020-02-04 19:52:32 +01:00
|
|
|
|
background.FadeTo(0.75f, 80);
|
2018-10-02 12:02:47 +09:00
|
|
|
|
return base.OnHover(e);
|
2017-09-12 21:24:43 -03:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-10-02 12:02:47 +09:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2017-09-12 21:24:43 -03:00
|
|
|
|
{
|
2020-02-04 19:52:32 +01:00
|
|
|
|
background.FadeTo(0.5f, 80);
|
2018-10-02 12:02:47 +09:00
|
|
|
|
base.OnHoverLost(e);
|
2017-09-12 21:24:43 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|