mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 14:42:56 +08:00
Move seek/step logic into ReplayPlayer
This commit is contained in:
parent
8c4af58109
commit
c50534c819
@ -1,14 +1,11 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
@ -36,10 +33,10 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
||||
private readonly IBindable<bool> isPaused = new BindableBool();
|
||||
|
||||
[Resolved]
|
||||
private GameplayClockContainer gameplayClock { get; set; } = null!;
|
||||
private ReplayPlayer replayPlayer { get; set; } = null!;
|
||||
|
||||
[Resolved]
|
||||
private GameplayState gameplayState { get; set; } = null!;
|
||||
private GameplayClockContainer gameplayClock { get; set; } = null!;
|
||||
|
||||
private IconButton pausePlay = null!;
|
||||
|
||||
@ -51,9 +48,6 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
const double seek_amount = 5000;
|
||||
const double seek_fast_amount = 10000;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new FillFlowContainer
|
||||
@ -77,23 +71,23 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Icon = FontAwesome.Solid.FastBackward,
|
||||
Action = () => seek(-1, seek_fast_amount),
|
||||
TooltipText = PlayerSettingsOverlayStrings.SeekBackwardSeconds(seek_fast_amount / 1000),
|
||||
Action = () => replayPlayer.SeekInDirection(-10),
|
||||
TooltipText = PlayerSettingsOverlayStrings.SeekBackwardSeconds(10 * ReplayPlayer.BASE_SEEK_AMOUNT / 1000),
|
||||
},
|
||||
new SeekButton
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Icon = FontAwesome.Solid.Backward,
|
||||
Action = () => seek(-1, seek_amount),
|
||||
TooltipText = PlayerSettingsOverlayStrings.SeekBackwardSeconds(seek_amount / 1000),
|
||||
Action = () => replayPlayer.SeekInDirection(-1),
|
||||
TooltipText = PlayerSettingsOverlayStrings.SeekBackwardSeconds(ReplayPlayer.BASE_SEEK_AMOUNT / 1000),
|
||||
},
|
||||
new SeekButton
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Icon = FontAwesome.Solid.StepBackward,
|
||||
Action = () => seekFrame(-1),
|
||||
Action = () => replayPlayer.StepFrame(-1),
|
||||
TooltipText = PlayerSettingsOverlayStrings.StepBackward,
|
||||
},
|
||||
pausePlay = new IconButton
|
||||
@ -115,7 +109,7 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Icon = FontAwesome.Solid.StepForward,
|
||||
Action = () => seekFrame(1),
|
||||
Action = () => replayPlayer.StepFrame(1),
|
||||
TooltipText = PlayerSettingsOverlayStrings.StepForward,
|
||||
},
|
||||
new SeekButton
|
||||
@ -123,16 +117,16 @@ namespace osu.Game.Screens.Play.PlayerSettings
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Icon = FontAwesome.Solid.Forward,
|
||||
Action = () => seek(1, seek_amount),
|
||||
TooltipText = PlayerSettingsOverlayStrings.SeekForwardSeconds(seek_amount / 1000),
|
||||
Action = () => replayPlayer.SeekInDirection(1),
|
||||
TooltipText = PlayerSettingsOverlayStrings.SeekForwardSeconds(ReplayPlayer.BASE_SEEK_AMOUNT / 1000),
|
||||
},
|
||||
new SeekButton
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Icon = FontAwesome.Solid.FastForward,
|
||||
Action = () => seek(1, seek_fast_amount),
|
||||
TooltipText = PlayerSettingsOverlayStrings.SeekForwardSeconds(seek_fast_amount / 1000),
|
||||
Action = () => replayPlayer.SeekInDirection(10),
|
||||
TooltipText = PlayerSettingsOverlayStrings.SeekForwardSeconds(10 * ReplayPlayer.BASE_SEEK_AMOUNT / 1000),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -182,27 +176,6 @@ 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());
|
||||
gameplayClock.Seek(target);
|
||||
}
|
||||
|
||||
private partial class SeekButton : IconButton
|
||||
{
|
||||
public SeekButton()
|
||||
|
@ -23,8 +23,11 @@ using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Screens.Play
|
||||
{
|
||||
[Cached]
|
||||
public partial class ReplayPlayer : Player, IKeyBindingHandler<GlobalAction>
|
||||
{
|
||||
public const double BASE_SEEK_AMOUNT = 1000;
|
||||
|
||||
private readonly Func<IBeatmap, IReadOnlyList<Mod>, Score> createScore;
|
||||
|
||||
private readonly bool replayIsFailedScore;
|
||||
@ -93,16 +96,22 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
||||
{
|
||||
const double keyboard_seek_amount = 5000;
|
||||
|
||||
switch (e.Action)
|
||||
{
|
||||
case GlobalAction.StepReplayBackward:
|
||||
StepFrame(-1);
|
||||
return true;
|
||||
|
||||
case GlobalAction.StepReplayForward:
|
||||
StepFrame(1);
|
||||
return true;
|
||||
|
||||
case GlobalAction.SeekReplayBackward:
|
||||
keyboardSeek(-1);
|
||||
SeekInDirection(-1);
|
||||
return true;
|
||||
|
||||
case GlobalAction.SeekReplayForward:
|
||||
keyboardSeek(1);
|
||||
SeekInDirection(1);
|
||||
return true;
|
||||
|
||||
case GlobalAction.TogglePauseReplay:
|
||||
@ -114,13 +123,28 @@ namespace osu.Game.Screens.Play
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void keyboardSeek(int direction)
|
||||
{
|
||||
double target = Math.Clamp(GameplayClockContainer.CurrentTime + direction * keyboard_seek_amount, 0, GameplayState.Beatmap.GetLastObjectTime());
|
||||
public void StepFrame(int direction)
|
||||
{
|
||||
GameplayClockContainer.Stop();
|
||||
|
||||
Seek(target);
|
||||
}
|
||||
var frames = GameplayState.Score.Replay.Frames;
|
||||
|
||||
if (frames.Count == 0)
|
||||
return;
|
||||
|
||||
GameplayClockContainer.Seek(direction < 0
|
||||
? (frames.LastOrDefault(f => f.Time < GameplayClockContainer.CurrentTime) ?? frames.First()).Time
|
||||
: (frames.FirstOrDefault(f => f.Time > GameplayClockContainer.CurrentTime) ?? frames.Last()).Time
|
||||
);
|
||||
}
|
||||
|
||||
public void SeekInDirection(float amount)
|
||||
{
|
||||
double target = Math.Clamp(GameplayClockContainer.CurrentTime + amount * BASE_SEEK_AMOUNT, 0, GameplayState.Beatmap.GetLastObjectTime());
|
||||
|
||||
Seek(target);
|
||||
}
|
||||
|
||||
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
||||
|
Loading…
Reference in New Issue
Block a user