Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent user from scrolling outside the timeline in the editor #2499

Merged
merged 7 commits into from May 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions osu.Game.Tests/Visual/TestCaseQuitButton.cs
Expand Up @@ -44,13 +44,13 @@ private void load()
{
exitAction = false;
InputManager.MoveMouseTo(quitButton);
InputManager.ButtonDown(MouseButton.Left);
InputManager.PressButton(MouseButton.Left);
});

AddStep("Early release", () => InputManager.ButtonUp(MouseButton.Left));
AddStep("Early release", () => InputManager.ReleaseButton(MouseButton.Left));
AddAssert("action not triggered", () => !exitAction);

AddStep("Trigger exit action", () => InputManager.ButtonDown(MouseButton.Left));
AddStep("Trigger exit action", () => InputManager.PressButton(MouseButton.Left));
AddUntilStep(() => exitAction, $"{nameof(quitButton.Action)} was triggered");
}
}
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Edit/Editor.cs
Expand Up @@ -48,7 +48,7 @@ private void load(OsuColour colours)
{
// TODO: should probably be done at a RulesetContainer level to share logic with Player.
var sourceClock = (IAdjustableClock)Beatmap.Value.Track ?? new StopwatchClock();
clock = new EditorClock(Beatmap.Value.Beatmap.ControlPointInfo, beatDivisor) { IsCoupled = false };
clock = new EditorClock(Beatmap, beatDivisor) { IsCoupled = false };
clock.ChangeSource(sourceClock);

dependencies.CacheAs<IFrameBasedClock>(clock);
Expand Down
18 changes: 17 additions & 1 deletion osu.Game/Screens/Edit/EditorClock.cs
Expand Up @@ -3,10 +3,13 @@

using System;
using System.Linq;
using osu.Framework.Configuration;
using osu.Framework.MathUtils;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Screens.Edit.Screens.Compose;
using OpenTK;

namespace osu.Game.Screens.Edit
{
Expand All @@ -15,15 +18,26 @@ namespace osu.Game.Screens.Edit
/// </summary>
public class EditorClock : DecoupleableInterpolatingFramedClock
{
public readonly double TrackLength;

public ControlPointInfo ControlPointInfo;

private readonly BindableBeatDivisor beatDivisor;

public EditorClock(ControlPointInfo controlPointInfo, BindableBeatDivisor beatDivisor)
public EditorClock(Bindable<WorkingBeatmap> beatmap, BindableBeatDivisor beatDivisor)
{
this.beatDivisor = beatDivisor;

ControlPointInfo = beatmap.Value.Beatmap.ControlPointInfo;
TrackLength = beatmap.Value.Track.Length;
}

This comment was marked as off-topic.


public EditorClock(ControlPointInfo controlPointInfo, double trackLength, BindableBeatDivisor beatDivisor)
{
this.beatDivisor = beatDivisor;

ControlPointInfo = controlPointInfo;
TrackLength = trackLength;
}

/// <summary>
Expand Down Expand Up @@ -111,6 +125,8 @@ private void seek(int direction, bool snapped)
if (seekTime > nextTimingPoint?.Time)
seekTime = nextTimingPoint.Time;

// Ensure the sought point is within the boundaries
seekTime = MathHelper.Clamp(seekTime, 0, TrackLength);
Seek(seekTime);
}
}
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Tests/Visual/EditorClockTestCase.cs
Expand Up @@ -29,7 +29,7 @@ protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnl

protected EditorClockTestCase()
{
Clock = new EditorClock(new ControlPointInfo(), BeatDivisor) { IsCoupled = false };
Clock = new EditorClock(new ControlPointInfo(), 5000, BeatDivisor) { IsCoupled = false };
}

[BackgroundDependencyLoader]
Expand Down