mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 09:07:25 +08:00
Merge pull request #8238 from voidedWarranties/editor-song-end
This commit is contained in:
commit
711d895a04
81
osu.Game.Tests/Visual/Editing/TestSceneEditorClock.cs
Normal file
81
osu.Game.Tests/Visual/Editing/TestSceneEditorClock.cs
Normal file
@ -0,0 +1,81 @@
|
||||
// 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 NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Screens.Edit.Components;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Editing
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestSceneEditorClock : EditorClockTestScene
|
||||
{
|
||||
public TestSceneEditorClock()
|
||||
{
|
||||
Add(new FillFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new TimeInfoContainer
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(200, 100)
|
||||
},
|
||||
new PlaybackControl
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
Size = new Vector2(200, 100)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
|
||||
// ensure that music controller does not change this beatmap due to it
|
||||
// completing naturally as part of the test.
|
||||
Beatmap.Disabled = true;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestStopAtTrackEnd()
|
||||
{
|
||||
AddStep("reset clock", () => Clock.Seek(0));
|
||||
|
||||
AddStep("start clock", Clock.Start);
|
||||
AddAssert("clock running", () => Clock.IsRunning);
|
||||
|
||||
AddStep("seek near end", () => Clock.Seek(Clock.TrackLength - 250));
|
||||
AddUntilStep("clock stops", () => !Clock.IsRunning);
|
||||
|
||||
AddAssert("clock stopped at end", () => Clock.CurrentTime == Clock.TrackLength);
|
||||
|
||||
AddStep("start clock again", Clock.Start);
|
||||
AddAssert("clock looped to start", () => Clock.IsRunning && Clock.CurrentTime < 500);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWrapWhenStoppedAtTrackEnd()
|
||||
{
|
||||
AddStep("reset clock", () => Clock.Seek(0));
|
||||
|
||||
AddStep("stop clock", Clock.Stop);
|
||||
AddAssert("clock stopped", () => !Clock.IsRunning);
|
||||
|
||||
AddStep("seek exactly to end", () => Clock.Seek(Clock.TrackLength));
|
||||
AddAssert("clock stopped at end", () => Clock.CurrentTime == Clock.TrackLength);
|
||||
|
||||
AddStep("start clock again", Clock.Start);
|
||||
AddAssert("clock looped to start", () => Clock.IsRunning && Clock.CurrentTime < 500);
|
||||
}
|
||||
}
|
||||
}
|
@ -110,8 +110,6 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
[Resolved]
|
||||
private EditorClock editorClock { get; set; }
|
||||
|
||||
private bool started;
|
||||
|
||||
public StartStopButton()
|
||||
{
|
||||
BackgroundColour = Color4.SlateGray;
|
||||
@ -123,18 +121,17 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
|
||||
private void onClick()
|
||||
{
|
||||
if (started)
|
||||
{
|
||||
if (editorClock.IsRunning)
|
||||
editorClock.Stop();
|
||||
Text = "Start";
|
||||
}
|
||||
else
|
||||
{
|
||||
editorClock.Start();
|
||||
Text = "Stop";
|
||||
}
|
||||
}
|
||||
|
||||
started = !started;
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
Text = editorClock.IsRunning ? "Stop" : "Start";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -177,7 +177,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
if (!track.IsLoaded)
|
||||
return;
|
||||
|
||||
editorClock.Seek(Current / Content.DrawWidth * track.Length);
|
||||
double target = Current / Content.DrawWidth * track.Length;
|
||||
editorClock.Seek(Math.Min(track.Length, target));
|
||||
}
|
||||
|
||||
private void scrollToTrackTime()
|
||||
|
@ -31,6 +31,8 @@ namespace osu.Game.Screens.Edit
|
||||
|
||||
private readonly DecoupleableInterpolatingFramedClock underlyingClock;
|
||||
|
||||
private bool playbackFinished;
|
||||
|
||||
public IBindable<bool> SeekingOrStopped => seekingOrStopped;
|
||||
|
||||
private readonly Bindable<bool> seekingOrStopped = new Bindable<bool>(true);
|
||||
@ -170,6 +172,10 @@ namespace osu.Game.Screens.Edit
|
||||
public void Start()
|
||||
{
|
||||
ClearTransforms();
|
||||
|
||||
if (playbackFinished)
|
||||
underlyingClock.Seek(0);
|
||||
|
||||
underlyingClock.Start();
|
||||
}
|
||||
|
||||
@ -216,7 +222,21 @@ namespace osu.Game.Screens.Edit
|
||||
|
||||
public bool IsRunning => underlyingClock.IsRunning;
|
||||
|
||||
public void ProcessFrame() => underlyingClock.ProcessFrame();
|
||||
public void ProcessFrame()
|
||||
{
|
||||
underlyingClock.ProcessFrame();
|
||||
|
||||
playbackFinished = CurrentTime >= TrackLength;
|
||||
|
||||
if (playbackFinished)
|
||||
{
|
||||
if (IsRunning)
|
||||
underlyingClock.Stop();
|
||||
|
||||
if (CurrentTime > TrackLength)
|
||||
underlyingClock.Seek(TrackLength);
|
||||
}
|
||||
}
|
||||
|
||||
public double ElapsedFrameTime => underlyingClock.ElapsedFrameTime;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user