1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-13 20:07:25 +08:00
osu-lazer/osu.Game/Tests/Visual/EditorClockTestCase.cs
smoogipoo 4086ff7313 Merge remote-tracking branch 'origin/master' into disallow-beatmap-change
# Conflicts:
#	osu.Game.Tests/Visual/TestCaseBeatmapInfoWedge.cs
#	osu.Game/Screens/Menu/Intro.cs
#	osu.Game/Screens/Menu/MenuSideFlashes.cs
2018-06-06 18:26:51 +09:00

69 lines
2.2 KiB
C#

// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Input;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Screens.Compose;
namespace osu.Game.Tests.Visual
{
/// <summary>
/// Provides a clock, beat-divisor, and scrolling capability for test cases of editor components that
/// are preferrably tested within the presence of a clock and seek controls.
/// </summary>
public abstract class EditorClockTestCase : OsuTestCase
{
protected readonly BindableBeatDivisor BeatDivisor = new BindableBeatDivisor();
protected readonly EditorClock Clock;
private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
=> dependencies = new DependencyContainer(base.CreateLocalDependencies(parent));
protected EditorClockTestCase()
{
Clock = new EditorClock(new ControlPointInfo(), 5000, BeatDivisor) { IsCoupled = false };
}
[BackgroundDependencyLoader]
private void load()
{
dependencies.Cache(BeatDivisor);
dependencies.CacheAs<IFrameBasedClock>(Clock);
dependencies.CacheAs<IAdjustableClock>(Clock);
Beatmap.ValueChanged += beatmapChanged;
beatmapChanged(Beatmap.Value);
}
private void beatmapChanged(WorkingBeatmap working)
{
Clock.ControlPointInfo = working.Beatmap.ControlPointInfo;
Clock.ChangeSource((IAdjustableClock)working.Track ?? new StopwatchClock());
Clock.ProcessFrame();
}
protected override void Update()
{
base.Update();
Clock.ProcessFrame();
}
protected override bool OnScroll(InputState state)
{
if (state.Mouse.ScrollDelta.Y > 0)
Clock.SeekBackward(true);
else
Clock.SeekForward(true);
return true;
}
}
}