1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 16:07:24 +08:00

Add ability to step forward/backwards single frames

This commit is contained in:
Dean Herbert 2024-01-18 14:59:35 +09:00
parent dafff26d0e
commit 60e972cd15
No known key found for this signature in database
2 changed files with 42 additions and 1 deletions

View File

@ -9,6 +9,16 @@ namespace osu.Game.Localisation
{
private const string prefix = @"osu.Game.Resources.Localisation.PlaybackSettings";
/// <summary>
/// "Step backward one frame"
/// </summary>
public static LocalisableString StepBackward => new TranslatableString(getKey(@"step_backward_frame"), @"Step backward one frame");
/// <summary>
/// "Step forward one frame"
/// </summary>
public static LocalisableString StepForward => new TranslatableString(getKey(@"step_forward_frame"), @"Step forward one frame");
/// <summary>
/// "Seek backward {0} seconds"
/// </summary>

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -87,13 +88,20 @@ namespace osu.Game.Screens.Play.PlayerSettings
Action = () => seek(-1, seek_amount),
TooltipText = PlayerSettingsOverlayStrings.SeekBackwardSeconds(seek_amount / 1000),
},
new SeekButton
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.StepBackward,
Action = () => seekFrame(-1),
TooltipText = PlayerSettingsOverlayStrings.StepBackward,
},
pausePlay = 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.IsRunning)
@ -103,6 +111,14 @@ namespace osu.Game.Screens.Play.PlayerSettings
},
},
new SeekButton
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Icon = FontAwesome.Solid.StepForward,
Action = () => seekFrame(1),
TooltipText = PlayerSettingsOverlayStrings.StepForward,
},
new SeekButton
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
@ -166,6 +182,21 @@ namespace osu.Game.Screens.Play.PlayerSettings
}, true);
}
private void seekFrame(int direction)
{
gameplayClock.Stop();
var frames = gameplayState.Score.Replay.Frames;
if (frames.Count == 0)
return;
gameplayClock.Seek(direction < 0
? (frames.LastOrDefault(f => f.Time < gameplayClock.CurrentTime) ?? frames.First()).Time
: (frames.FirstOrDefault(f => f.Time > gameplayClock.CurrentTime) ?? frames.Last()).Time
);
}
private void seek(int direction, double amount)
{
double target = Math.Clamp(gameplayClock.CurrentTime + (direction * amount), 0, gameplayState.Beatmap.GetLastObjectTime());