1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-17 02:12:54 +08:00
osu-lazer/osu.Game/Screens/Play/PlayerSettings/PlaybackSettings.cs

188 lines
8.0 KiB
C#
Raw Normal View History

// 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 osu.Framework.Allocation;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2018-04-13 17:19:50 +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.Graphics;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics.Sprites;
2024-01-09 12:23:01 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osu.Game.Screens.Edit.Timing;
2024-01-09 12:23:01 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Play.PlayerSettings
{
2022-11-24 13:32:20 +08:00
public partial class PlaybackSettings : PlayerSettingsGroup
2018-04-13 17:19:50 +08:00
{
private const int padding = 10;
public readonly Bindable<double> UserPlaybackRate = new BindableDouble(1)
{
MinValue = 0.05,
MaxValue = 2,
Precision = 0.01,
};
2018-04-13 17:19:50 +08:00
private PlayerSliderBar<double> rateSlider = null!;
2018-04-13 17:19:50 +08:00
private OsuSpriteText multiplierText = null!;
private readonly IBindable<bool> isPaused = new BindableBool();
2024-01-09 12:23:01 +08:00
[Resolved]
private ReplayPlayer replayPlayer { get; set; } = null!;
2024-01-09 12:23:01 +08:00
[Resolved]
private GameplayClockContainer gameplayClock { get; set; } = null!;
private IconButton pausePlay = null!;
2024-01-09 12:23:01 +08:00
2018-04-13 17:19:50 +08:00
public PlaybackSettings()
: base("playback")
{
}
[BackgroundDependencyLoader]
private void load()
2018-04-13 17:19:50 +08:00
{
Children = new Drawable[]
{
2024-01-09 12:23:01 +08:00
new FillFlowContainer
2018-04-13 17:19:50 +08:00
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2024-01-09 12:23:01 +08:00
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, padding),
2018-04-13 17:19:50 +08:00
Children = new Drawable[]
{
2024-01-09 12:23:01 +08:00
new FillFlowContainer
2018-04-13 17:19:50 +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[]
{
new SeekButton
2024-01-09 12:23:01 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.FastBackward,
Action = () => replayPlayer.SeekInDirection(-10),
TooltipText = PlayerSettingsOverlayStrings.SeekBackwardSeconds(10 * ReplayPlayer.BASE_SEEK_AMOUNT / 1000),
2024-01-09 12:23:01 +08:00
},
new SeekButton
2024-01-09 12:23:01 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.Backward,
Action = () => replayPlayer.SeekInDirection(-1),
TooltipText = PlayerSettingsOverlayStrings.SeekBackwardSeconds(ReplayPlayer.BASE_SEEK_AMOUNT / 1000),
2024-01-09 12:23:01 +08:00
},
new SeekButton
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.StepBackward,
Action = () => replayPlayer.StepFrame(-1),
TooltipText = PlayerSettingsOverlayStrings.StepBackward,
},
pausePlay = new IconButton
2024-01-09 12:23:01 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(1.4f),
IconScale = new Vector2(1.4f),
Action = () =>
{
if (gameplayClock.IsRunning)
gameplayClock.Stop();
else
gameplayClock.Start();
},
2024-01-09 12:23:01 +08:00
},
new SeekButton
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.StepForward,
Action = () => replayPlayer.StepFrame(1),
TooltipText = PlayerSettingsOverlayStrings.StepForward,
},
new SeekButton
2024-01-09 12:23:01 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.Forward,
Action = () => replayPlayer.SeekInDirection(1),
TooltipText = PlayerSettingsOverlayStrings.SeekForwardSeconds(ReplayPlayer.BASE_SEEK_AMOUNT / 1000),
2024-01-09 12:23:01 +08:00
},
new SeekButton
2024-01-09 12:23:01 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.FastForward,
Action = () => replayPlayer.SeekInDirection(10),
TooltipText = PlayerSettingsOverlayStrings.SeekForwardSeconds(10 * ReplayPlayer.BASE_SEEK_AMOUNT / 1000),
2024-01-09 12:23:01 +08:00
},
},
2018-04-13 17:19:50 +08:00
},
2024-01-09 12:23:01 +08:00
new Container
2018-04-13 17:19:50 +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 },
}
},
},
2018-04-13 17:19:50 +08:00
},
},
};
}
protected override void LoadComplete()
{
base.LoadComplete();
rateSlider.Current.BindValueChanged(multiplier => multiplierText.Text = $"{multiplier.NewValue:0.00}x", true);
2024-01-09 12:23:01 +08:00
isPaused.BindTo(gameplayClock.IsPaused);
2024-01-17 14:12:33 +08:00
isPaused.BindValueChanged(paused =>
{
if (!paused.NewValue)
{
pausePlay.TooltipText = ToastStrings.PauseTrack;
pausePlay.Icon = FontAwesome.Regular.PauseCircle;
2024-01-17 14:12:33 +08:00
}
else
{
pausePlay.TooltipText = ToastStrings.PlayTrack;
pausePlay.Icon = FontAwesome.Regular.PlayCircle;
2024-01-17 14:12:33 +08:00
}
}, true);
2018-04-13 17:19:50 +08:00
}
private partial class SeekButton : IconButton
{
public SeekButton()
{
AddInternal(new RepeatingButtonBehaviour(this));
}
}
2018-04-13 17:19:50 +08:00
}
}