2018-01-05 11:21:19 +00:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-11-17 09:26:13 +00:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-11-17 10:35:41 +00:00
|
|
|
|
using OpenTK;
|
2017-11-22 02:34:54 +00:00
|
|
|
|
using OpenTK.Graphics;
|
2017-11-17 10:35:41 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-11-22 02:21:48 +00:00
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2017-11-17 10:35:41 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Input;
|
2018-03-15 09:08:37 +00:00
|
|
|
|
using osu.Framework.Timing;
|
2017-11-17 10:35:41 +00:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
|
2017-11-17 09:26:13 +00:00
|
|
|
|
namespace osu.Game.Screens.Edit.Components
|
|
|
|
|
{
|
2017-11-22 02:22:46 +00:00
|
|
|
|
public class PlaybackControl : BottomBarContainer
|
2017-11-17 09:26:13 +00:00
|
|
|
|
{
|
2017-11-17 10:35:41 +00:00
|
|
|
|
private readonly IconButton playButton;
|
|
|
|
|
|
2018-03-15 09:08:37 +00:00
|
|
|
|
private readonly IAdjustableClock adjustableClock;
|
|
|
|
|
|
|
|
|
|
public PlaybackControl(IAdjustableClock adjustableClock)
|
2017-11-17 10:35:41 +00:00
|
|
|
|
{
|
2018-03-15 09:08:37 +00:00
|
|
|
|
this.adjustableClock = adjustableClock;
|
|
|
|
|
|
2017-11-17 10:35:41 +00:00
|
|
|
|
PlaybackTabControl tabs;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
playButton = new IconButton
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Scale = new Vector2(1.4f),
|
|
|
|
|
IconScale = new Vector2(1.4f),
|
|
|
|
|
Icon = FontAwesome.fa_play_circle_o,
|
2017-11-22 01:59:31 +00:00
|
|
|
|
Action = togglePause,
|
2017-11-17 10:35:41 +00:00
|
|
|
|
Padding = new MarginPadding { Left = 20 }
|
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Text = "Playback Speed",
|
|
|
|
|
RelativePositionAxes = Axes.Y,
|
|
|
|
|
Y = 0.5f,
|
|
|
|
|
Padding = new MarginPadding { Left = 45 }
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Height = 0.5f,
|
|
|
|
|
Padding = new MarginPadding { Left = 45 },
|
|
|
|
|
Child = tabs = new PlaybackTabControl(),
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-03-15 09:08:37 +00:00
|
|
|
|
tabs.Current.ValueChanged += newValue => Beatmap.Value.Track.Tempo.Value = newValue;
|
2017-11-17 10:35:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-22 01:59:31 +00:00
|
|
|
|
private void togglePause()
|
2017-11-17 10:35:41 +00:00
|
|
|
|
{
|
2018-03-15 09:08:37 +00:00
|
|
|
|
if (adjustableClock.IsRunning)
|
|
|
|
|
adjustableClock.Stop();
|
2017-11-17 10:35:41 +00:00
|
|
|
|
else
|
2018-03-15 09:08:37 +00:00
|
|
|
|
adjustableClock.Start();
|
2017-11-17 10:35:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2018-03-15 09:08:37 +00:00
|
|
|
|
playButton.Icon = adjustableClock.IsRunning ? FontAwesome.fa_pause_circle_o : FontAwesome.fa_play_circle_o;
|
2017-11-17 10:35:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class PlaybackTabControl : OsuTabControl<double>
|
|
|
|
|
{
|
2017-11-22 02:36:29 +00:00
|
|
|
|
private static readonly double[] tempo_values = { 0.5, 0.75, 1 };
|
2017-11-22 02:21:48 +00:00
|
|
|
|
|
2017-11-17 10:35:41 +00:00
|
|
|
|
protected override TabItem<double> CreateTabItem(double value) => new PlaybackTabItem(value);
|
|
|
|
|
|
|
|
|
|
protected override Dropdown<double> CreateDropdown() => null;
|
|
|
|
|
|
|
|
|
|
public PlaybackTabControl()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2017-11-22 02:21:48 +00:00
|
|
|
|
TabContainer.Spacing = Vector2.Zero;
|
|
|
|
|
|
|
|
|
|
tempo_values.ForEach(AddItem);
|
2017-11-17 10:35:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class PlaybackTabItem : TabItem<double>
|
|
|
|
|
{
|
2017-11-22 02:34:54 +00:00
|
|
|
|
private const float fade_duration = 200;
|
2017-11-17 10:35:41 +00:00
|
|
|
|
|
|
|
|
|
private readonly OsuSpriteText text;
|
|
|
|
|
private readonly OsuSpriteText textBold;
|
|
|
|
|
|
|
|
|
|
public PlaybackTabItem(double value) : base(value)
|
|
|
|
|
{
|
2017-11-22 02:21:48 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Width = 1f / tempo_values.Length;
|
2017-11-17 10:35:41 +00:00
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
text = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
2017-11-22 02:17:10 +00:00
|
|
|
|
Text = $"{value:0%}",
|
2017-11-17 10:35:41 +00:00
|
|
|
|
TextSize = 14,
|
|
|
|
|
},
|
|
|
|
|
textBold = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
2017-11-22 02:17:10 +00:00
|
|
|
|
Text = $"{value:0%}",
|
2017-11-17 10:35:41 +00:00
|
|
|
|
TextSize = 14,
|
|
|
|
|
Font = @"Exo2.0-Bold",
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-22 02:34:54 +00:00
|
|
|
|
private Color4 hoveredColour;
|
|
|
|
|
private Color4 normalColour;
|
|
|
|
|
|
2017-11-17 10:35:41 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
2017-11-22 02:34:54 +00:00
|
|
|
|
text.Colour = normalColour = colours.YellowDarker;
|
|
|
|
|
textBold.Colour = hoveredColour = colours.Yellow;
|
2017-11-17 10:35:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
2017-11-22 01:55:06 +00:00
|
|
|
|
updateState();
|
2017-11-17 10:35:41 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-22 02:57:09 +00:00
|
|
|
|
protected override void OnHoverLost(InputState state) => updateState();
|
|
|
|
|
protected override void OnActivated() => updateState();
|
|
|
|
|
protected override void OnDeactivated() => updateState();
|
2017-11-17 10:35:41 +00:00
|
|
|
|
|
2017-11-22 01:55:06 +00:00
|
|
|
|
private void updateState()
|
2017-11-17 10:35:41 +00:00
|
|
|
|
{
|
2017-11-22 02:34:54 +00:00
|
|
|
|
text.FadeColour(Active || IsHovered ? hoveredColour : normalColour, fade_duration, Easing.OutQuint);
|
|
|
|
|
text.FadeTo(Active ? 0 : 1, fade_duration, Easing.OutQuint);
|
|
|
|
|
textBold.FadeTo(Active ? 1 : 0, fade_duration, Easing.OutQuint);
|
2017-11-17 10:35:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-17 09:26:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|