1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-19 04:42:55 +08:00
osu-lazer/osu.Game/Screens/Edit/Components/PlaybackControl.cs

161 lines
5.6 KiB
C#
Raw Normal View History

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