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
|
|
|
|
|
2019-10-08 03:27:51 +00:00
|
|
|
|
using System.Linq;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2017-11-17 10:35:41 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2020-01-24 04:10:02 +00:00
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Bindables;
|
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;
|
2019-03-27 10:29:27 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2017-11-17 10:35:41 +00:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2017-11-17 10:35:41 +00:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-05-25 14:17:52 +00:00
|
|
|
|
using osu.Game.Overlays;
|
2018-11-30 05:41:17 +00:00
|
|
|
|
using osuTK.Input;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
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
|
|
|
|
{
|
2018-03-19 07:27:52 +00:00
|
|
|
|
private IconButton playButton;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-02-14 13:14:00 +00:00
|
|
|
|
[Resolved]
|
2020-05-22 07:37:28 +00:00
|
|
|
|
private EditorClock editorClock { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-03-19 11:01:45 +00:00
|
|
|
|
private readonly BindableNumber<double> freqAdjust = new BindableDouble(1);
|
2020-01-24 04:10:02 +00:00
|
|
|
|
|
2018-03-19 07:27:52 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
2020-02-14 13:14:00 +00:00
|
|
|
|
private void load()
|
2017-11-17 10:35:41 +00:00
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
playButton = new IconButton
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
2019-06-15 18:05:58 +00:00
|
|
|
|
Origin = Anchor.CentreLeft,
|
2017-11-17 10:35:41 +00:00
|
|
|
|
Scale = new Vector2(1.4f),
|
|
|
|
|
IconScale = new Vector2(1.4f),
|
2019-04-02 10:55:24 +00:00
|
|
|
|
Icon = FontAwesome.Regular.PlayCircle,
|
2017-11-22 01:59:31 +00:00
|
|
|
|
Action = togglePause,
|
2017-11-17 10:35:41 +00:00
|
|
|
|
},
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
2018-09-15 14:30:11 +00:00
|
|
|
|
Text = "Playback speed",
|
2017-11-17 10:35:41 +00:00
|
|
|
|
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 },
|
2021-03-19 11:01:45 +00:00
|
|
|
|
Child = new PlaybackTabControl { Current = freqAdjust },
|
2017-11-17 10:35:41 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-03-19 11:01:45 +00:00
|
|
|
|
Track.BindValueChanged(tr => tr.NewValue?.AddAdjustment(AdjustableProperty.Frequency, freqAdjust), true);
|
2020-01-24 04:10:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
2021-03-19 11:01:45 +00:00
|
|
|
|
Track.Value?.RemoveAdjustment(AdjustableProperty.Frequency, freqAdjust);
|
2020-01-24 04:10:02 +00:00
|
|
|
|
|
|
|
|
|
base.Dispose(isDisposing);
|
2017-11-17 10:35:41 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-30 05:41:17 +00:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
|
|
|
|
{
|
|
|
|
|
switch (e.Key)
|
|
|
|
|
{
|
|
|
|
|
case Key.Space:
|
|
|
|
|
togglePause();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.OnKeyDown(e);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-22 01:59:31 +00:00
|
|
|
|
private void togglePause()
|
2017-11-17 10:35:41 +00:00
|
|
|
|
{
|
2020-05-22 07:37:28 +00:00
|
|
|
|
if (editorClock.IsRunning)
|
|
|
|
|
editorClock.Stop();
|
2017-11-17 10:35:41 +00:00
|
|
|
|
else
|
2020-05-22 07:37:28 +00:00
|
|
|
|
editorClock.Start();
|
2017-11-17 10:35:41 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-17 10:35:41 +00:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-05-22 07:37:28 +00:00
|
|
|
|
playButton.Icon = editorClock.IsRunning ? FontAwesome.Regular.PauseCircle : FontAwesome.Regular.PlayCircle;
|
2017-11-17 10:35:41 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-17 10:35:41 +00:00
|
|
|
|
private class PlaybackTabControl : OsuTabControl<double>
|
|
|
|
|
{
|
2021-03-19 11:01:45 +00:00
|
|
|
|
private static readonly double[] tempo_values = { 0.25, 0.5, 0.75, 1 };
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-17 10:35:41 +00:00
|
|
|
|
protected override TabItem<double> CreateTabItem(double value) => new PlaybackTabItem(value);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-17 10:35:41 +00:00
|
|
|
|
protected override Dropdown<double> CreateDropdown() => null;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-17 10:35:41 +00:00
|
|
|
|
public PlaybackTabControl()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2017-11-22 02:21:48 +00:00
|
|
|
|
TabContainer.Spacing = Vector2.Zero;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-22 02:21:48 +00:00
|
|
|
|
tempo_values.ForEach(AddItem);
|
2019-10-08 03:27:51 +00:00
|
|
|
|
|
|
|
|
|
Current.Value = tempo_values.Last();
|
2017-11-17 10:35:41 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
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;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-17 10:35:41 +00:00
|
|
|
|
private readonly OsuSpriteText text;
|
|
|
|
|
private readonly OsuSpriteText textBold;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-02-28 04:31:40 +00:00
|
|
|
|
public PlaybackTabItem(double value)
|
|
|
|
|
: base(value)
|
2017-11-17 10:35:41 +00:00
|
|
|
|
{
|
2017-11-22 02:21:48 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-22 02:21:48 +00:00
|
|
|
|
Width = 1f / tempo_values.Length;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
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%}",
|
2019-02-12 04:04:46 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 14)
|
2017-11-17 10:35:41 +00:00
|
|
|
|
},
|
|
|
|
|
textBold = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
2017-11-22 02:17:10 +00:00
|
|
|
|
Text = $"{value:0%}",
|
2019-02-12 04:04:46 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold),
|
2017-11-17 10:35:41 +00:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-22 02:34:54 +00:00
|
|
|
|
private Color4 hoveredColour;
|
|
|
|
|
private Color4 normalColour;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-17 10:35:41 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
2022-05-25 14:17:52 +00:00
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
2017-11-17 10:35:41 +00:00
|
|
|
|
{
|
2022-05-25 14:17:52 +00:00
|
|
|
|
text.Colour = normalColour = colourProvider.Light3;
|
|
|
|
|
textBold.Colour = hoveredColour = colourProvider.Content1;
|
2017-11-17 10:35:41 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2017-11-17 10:35:41 +00:00
|
|
|
|
{
|
2017-11-22 01:55:06 +00:00
|
|
|
|
updateState();
|
2017-11-17 10:35:41 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e) => updateState();
|
2017-11-22 02:57:09 +00:00
|
|
|
|
protected override void OnActivated() => updateState();
|
|
|
|
|
protected override void OnDeactivated() => updateState();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-11-22 01:55:06 +00:00
|
|
|
|
private void updateState()
|
2017-11-17 10:35:41 +00:00
|
|
|
|
{
|
2019-02-21 09:56:34 +00:00
|
|
|
|
text.FadeColour(Active.Value || IsHovered ? hoveredColour : normalColour, fade_duration, Easing.OutQuint);
|
|
|
|
|
text.FadeTo(Active.Value ? 0 : 1, fade_duration, Easing.OutQuint);
|
|
|
|
|
textBold.FadeTo(Active.Value ? 1 : 0, fade_duration, Easing.OutQuint);
|
2017-11-17 10:35:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-17 09:26:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|