1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-17 23:42:55 +08:00
osu-lazer/osu.Game/Overlays/BeatmapSet/Buttons/PreviewButton.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

100 lines
3.0 KiB
C#
Raw Normal View History

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