2019-01-24 16:43:03 +08: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 17:19:50 +08:00
|
|
|
|
|
2024-01-09 12:23:01 +08:00
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2017-11-13 10:04:21 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2024-01-09 12:23:01 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Beatmaps;
|
2019-02-12 12:04:46 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2017-11-13 10:04:21 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2024-01-09 12:23:01 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2024-01-09 16:08:29 +08:00
|
|
|
|
using osu.Game.Screens.Edit.Timing;
|
2024-01-09 12:23:01 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-01-14 03:25:09 +08:00
|
|
|
|
namespace osu.Game.Screens.Play.PlayerSettings
|
2017-05-18 12:09:36 +08:00
|
|
|
|
{
|
2018-01-16 01:52:52 +08:00
|
|
|
|
public partial class PlaybackSettings : PlayerSettingsGroup
|
2017-05-18 12:09:36 +08:00
|
|
|
|
{
|
2017-11-13 10:52:05 +08:00
|
|
|
|
private const int padding = 10;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-03-06 19:30:14 +08:00
|
|
|
|
public readonly Bindable<double> UserPlaybackRate = new BindableDouble(1)
|
|
|
|
|
{
|
2024-01-17 13:53:49 +08:00
|
|
|
|
MinValue = 0.05,
|
2019-03-06 19:30:14 +08:00
|
|
|
|
MaxValue = 2,
|
2024-01-17 13:53:49 +08:00
|
|
|
|
Precision = 0.01,
|
2019-03-06 19:30:14 +08:00
|
|
|
|
};
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-02-22 16:51:39 +08:00
|
|
|
|
private readonly PlayerSliderBar<double> rateSlider;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-01-22 10:40:57 +08:00
|
|
|
|
private readonly OsuSpriteText multiplierText;
|
|
|
|
|
|
2024-01-09 15:18:21 +08:00
|
|
|
|
private readonly BindableBool isPaused = new BindableBool();
|
|
|
|
|
|
2024-01-09 12:23:01 +08:00
|
|
|
|
[Resolved]
|
2024-01-09 12:48:11 +08:00
|
|
|
|
private GameplayClockContainer? gameplayClock { get; set; }
|
2024-01-09 12:23:01 +08:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
2024-01-09 12:48:11 +08:00
|
|
|
|
private GameplayState? gameplayState { get; set; }
|
2024-01-09 12:23:01 +08:00
|
|
|
|
|
2017-10-02 23:09:00 +08:00
|
|
|
|
public PlaybackSettings()
|
2020-09-09 17:48:02 +08:00
|
|
|
|
: base("playback")
|
2017-05-18 12:09:36 +08:00
|
|
|
|
{
|
2024-01-09 12:23:01 +08:00
|
|
|
|
const double seek_amount = 5000;
|
|
|
|
|
const double seek_fast_amount = 10000;
|
|
|
|
|
|
2024-01-09 16:30:48 +08:00
|
|
|
|
IconButton play;
|
|
|
|
|
|
2017-11-13 10:04:21 +08:00
|
|
|
|
Children = new Drawable[]
|
2017-05-18 12:09:36 +08:00
|
|
|
|
{
|
2024-01-09 12:23:01 +08:00
|
|
|
|
new FillFlowContainer
|
2017-10-02 23:19:55 +08:00
|
|
|
|
{
|
2017-11-13 10:04:21 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2024-01-09 12:23:01 +08:00
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Spacing = new Vector2(0, padding),
|
2017-11-13 10:04:21 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2024-01-09 12:23:01 +08:00
|
|
|
|
new FillFlowContainer
|
2017-11-13 10:04:21 +08:00
|
|
|
|
{
|
2024-01-09 12:23:01 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(5, 0),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2024-01-09 16:08:29 +08:00
|
|
|
|
new SeekButton
|
2024-01-09 12:23:01 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Icon = FontAwesome.Solid.FastBackward,
|
|
|
|
|
Action = () => seek(-1, seek_fast_amount),
|
|
|
|
|
},
|
2024-01-09 16:08:29 +08:00
|
|
|
|
new SeekButton
|
2024-01-09 12:23:01 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Icon = FontAwesome.Solid.Backward,
|
|
|
|
|
Action = () => seek(-1, seek_amount),
|
|
|
|
|
},
|
|
|
|
|
play = new IconButton
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Scale = new Vector2(1.4f),
|
|
|
|
|
IconScale = new Vector2(1.4f),
|
|
|
|
|
Icon = FontAwesome.Regular.PlayCircle,
|
|
|
|
|
Action = () =>
|
|
|
|
|
{
|
|
|
|
|
if (gameplayClock != null)
|
|
|
|
|
{
|
|
|
|
|
if (gameplayClock.IsRunning)
|
|
|
|
|
gameplayClock.Stop();
|
|
|
|
|
else
|
|
|
|
|
gameplayClock.Start();
|
|
|
|
|
}
|
2024-01-09 22:09:20 +08:00
|
|
|
|
},
|
2024-01-09 12:23:01 +08:00
|
|
|
|
},
|
2024-01-09 16:08:29 +08:00
|
|
|
|
new SeekButton
|
2024-01-09 12:23:01 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Icon = FontAwesome.Solid.Forward,
|
|
|
|
|
Action = () => seek(1, seek_amount),
|
|
|
|
|
},
|
2024-01-09 16:08:29 +08:00
|
|
|
|
new SeekButton
|
2024-01-09 12:23:01 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Icon = FontAwesome.Solid.FastForward,
|
|
|
|
|
Action = () => seek(1, seek_fast_amount),
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-11-13 10:04:21 +08:00
|
|
|
|
},
|
2024-01-09 12:23:01 +08:00
|
|
|
|
new Container
|
2017-11-13 10:04:21 +08:00
|
|
|
|
{
|
2024-01-09 12:23:01 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
rateSlider = new PlayerSliderBar<double>
|
|
|
|
|
{
|
|
|
|
|
LabelText = "Playback speed",
|
|
|
|
|
Current = UserPlaybackRate,
|
|
|
|
|
},
|
|
|
|
|
multiplierText = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
Font = OsuFont.GetFont(weight: FontWeight.Bold),
|
|
|
|
|
Margin = new MarginPadding { Right = 20 },
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-11-13 10:04:21 +08:00
|
|
|
|
},
|
2017-10-02 23:19:55 +08:00
|
|
|
|
},
|
2017-05-30 00:00:29 +08:00
|
|
|
|
};
|
2024-01-09 12:23:01 +08:00
|
|
|
|
|
2024-01-09 15:19:54 +08:00
|
|
|
|
isPaused.BindValueChanged(e => play.Icon = !e.NewValue ? FontAwesome.Regular.PauseCircle : FontAwesome.Regular.PlayCircle, true);
|
2024-01-09 15:18:21 +08:00
|
|
|
|
|
2024-01-09 12:23:01 +08:00
|
|
|
|
void seek(int direction, double amount)
|
|
|
|
|
{
|
2024-01-09 12:24:09 +08:00
|
|
|
|
double target = Math.Clamp((gameplayClock?.CurrentTime ?? 0) + (direction * amount), 0, gameplayState?.Beatmap.GetLastObjectTime() ?? 0);
|
2024-01-09 12:23:01 +08:00
|
|
|
|
gameplayClock?.Seek(target);
|
|
|
|
|
}
|
2017-05-18 12:09:36 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-10-04 01:05:50 +08:00
|
|
|
|
protected override void LoadComplete()
|
2017-10-02 09:42:38 +08:00
|
|
|
|
{
|
2017-10-04 01:05:50 +08:00
|
|
|
|
base.LoadComplete();
|
2024-01-17 13:53:49 +08:00
|
|
|
|
rateSlider.Current.BindValueChanged(multiplier => multiplierText.Text = $"{multiplier.NewValue:0.00}x", true);
|
2024-01-09 22:09:20 +08:00
|
|
|
|
|
|
|
|
|
if (gameplayClock != null)
|
|
|
|
|
isPaused.BindTarget = gameplayClock.IsPaused;
|
2024-01-09 12:23:01 +08:00
|
|
|
|
}
|
2024-01-09 16:08:29 +08:00
|
|
|
|
|
|
|
|
|
private partial class SeekButton : IconButton
|
|
|
|
|
{
|
|
|
|
|
public SeekButton()
|
|
|
|
|
{
|
|
|
|
|
AddInternal(new RepeatingButtonBehaviour(this));
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-18 12:09:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|