2017-09-13 00:24:43 +00:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio.Track;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
2017-09-25 09:26:27 +00:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2017-09-29 21:08:30 +00:00
|
|
|
|
using osu.Game.Overlays.Direct;
|
|
|
|
|
using osu.Framework.Configuration;
|
2017-09-13 00:24:43 +00:00
|
|
|
|
|
2017-09-25 09:26:27 +00:00
|
|
|
|
namespace osu.Game.Overlays.BeatmapSet
|
2017-09-13 00:24:43 +00:00
|
|
|
|
{
|
|
|
|
|
public class PreviewButton : OsuClickableContainer
|
|
|
|
|
{
|
2017-09-15 16:47:03 +00:00
|
|
|
|
private const float transition_duration = 500;
|
|
|
|
|
|
2017-09-13 00:24:43 +00:00
|
|
|
|
private readonly Box bg, progress;
|
2017-09-29 21:08:30 +00:00
|
|
|
|
private readonly PlayButton playButton;
|
2017-09-13 00:24:43 +00:00
|
|
|
|
|
2017-10-06 19:00:23 +00:00
|
|
|
|
private Track preview => playButton.Preview;
|
2017-10-14 02:58:06 +00:00
|
|
|
|
public Bindable<bool> Playing => playButton.Playing;
|
2017-09-15 16:47:03 +00:00
|
|
|
|
|
2017-09-13 21:25:23 +00:00
|
|
|
|
public BeatmapSetInfo BeatmapSet
|
|
|
|
|
{
|
2017-10-13 05:06:34 +00:00
|
|
|
|
get { return playButton.BeatmapSet; }
|
|
|
|
|
set { playButton.BeatmapSet = value; }
|
2017-09-13 21:25:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PreviewButton()
|
2017-09-13 00:24:43 +00:00
|
|
|
|
{
|
|
|
|
|
Height = 42;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
bg = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.25f),
|
|
|
|
|
},
|
|
|
|
|
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 19:06:37 +00:00
|
|
|
|
playButton = new PlayButton
|
2017-09-13 00:24:43 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Size = new Vector2(18),
|
2017-09-15 16:47:03 +00:00
|
|
|
|
},
|
2017-09-13 00:24:43 +00:00
|
|
|
|
};
|
|
|
|
|
|
2017-10-14 02:58:06 +00:00
|
|
|
|
Action = () => Playing.Value = !Playing.Value;
|
|
|
|
|
Playing.ValueChanged += newValue => progress.FadeTo(newValue ? 1 : 0, 100);
|
2017-09-13 00:24:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2017-09-15 16:47:03 +00:00
|
|
|
|
private void load(OsuColour colours)
|
2017-09-13 00:24:43 +00:00
|
|
|
|
{
|
|
|
|
|
progress.Colour = colours.Yellow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2017-10-14 02:58:06 +00:00
|
|
|
|
if (Playing.Value && preview != null)
|
2017-09-13 00:24:43 +00:00
|
|
|
|
{
|
|
|
|
|
progress.Width = (float)(preview.CurrentTime / preview.Length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
2017-10-14 02:58:06 +00:00
|
|
|
|
Playing.Value = false;
|
2017-09-13 00:24:43 +00:00
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
|
|
|
|
bg.FadeColour(Color4.Black.Opacity(0.5f), 100);
|
|
|
|
|
return base.OnHover(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
|
|
|
|
bg.FadeColour(Color4.Black.Opacity(0.25f), 100);
|
|
|
|
|
base.OnHoverLost(state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|