Initial animation pass on metronome

This commit is contained in:
Dean Herbert
2022-05-20 15:56:39 +09:00
parent ce7be940e2
commit 42179568f3
3 changed files with 117 additions and 47 deletions

View File

@ -36,10 +36,37 @@ namespace osu.Game.Tests.Visual.Editing
public TestSceneTapTimingControl() public TestSceneTapTimingControl()
{ {
editorBeatmap = new EditorBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo)); var playableBeatmap = CreateBeatmap(new OsuRuleset().RulesetInfo);
// Ensure time doesn't end while testing
playableBeatmap.BeatmapInfo.Length = 1200000;
editorBeatmap = new EditorBeatmap(playableBeatmap);
selectedGroup.Value = editorBeatmap.ControlPointInfo.Groups.First(); selectedGroup.Value = editorBeatmap.ControlPointInfo.Groups.First();
} }
protected override void LoadComplete()
{
base.LoadComplete();
Beatmap.Value = CreateWorkingBeatmap(editorBeatmap.PlayableBeatmap);
Beatmap.Disabled = true;
Children = new Drawable[]
{
new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.Y,
Width = 400,
Scale = new Vector2(1.5f),
Child = control = new TapTimingControl(),
}
};
}
[Test] [Test]
public void TestTapThenReset() public void TestTapThenReset()
{ {
@ -65,24 +92,19 @@ namespace osu.Game.Tests.Visual.Editing
[Test] [Test]
public void TestBasic() public void TestBasic()
{ {
} AddStep("set low bpm", () =>
protected override void LoadComplete()
{
base.LoadComplete();
Beatmap.Value = CreateWorkingBeatmap(editorBeatmap.PlayableBeatmap);
Beatmap.Disabled = true;
Child = new Container
{ {
Anchor = Anchor.Centre, editorBeatmap.ControlPointInfo.TimingPoints.First().BeatLength = 1000;
Origin = Anchor.Centre, });
AutoSizeAxes = Axes.Y,
Width = 400, AddStep("click tap button", () =>
Scale = new Vector2(1.5f), {
Child = control = new TapTimingControl(), control.ChildrenOfType<RoundedButton>()
}; .First(b => b.Text == "Tap to beat")
.TriggerClick();
});
AddSliderStep("BPM", 30, 400, 60, bpm => editorBeatmap.ControlPointInfo.TimingPoints.First().BeatLength = 60000f / bpm);
} }
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)

View File

@ -3,15 +3,19 @@
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Utils;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays; using osu.Game.Overlays;
using osuTK; using osuTK;
using osuTK.Graphics;
namespace osu.Game.Screens.Edit.Timing namespace osu.Game.Screens.Edit.Timing
{ {
@ -103,9 +107,13 @@ namespace osu.Game.Screens.Edit.Timing
private Container swing; private Container swing;
private Box weight; private Box weight;
private OsuSpriteText bpm; private OsuSpriteText bpm;
private Box stick;
[Resolved]
private OverlayColourProvider overlayColourProvider { get; set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OverlayColourProvider overlayColourProvider) private void load()
{ {
Margin = new MarginPadding(10); Margin = new MarginPadding(10);
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
@ -117,21 +125,13 @@ namespace osu.Game.Screens.Edit.Timing
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Size = new Vector2(80, 120), Size = new Vector2(80, 120),
Colour = overlayColourProvider.Background1, Colour = overlayColourProvider.Background2,
},
new Circle
{
Y = -25,
Anchor = Anchor.BottomCentre,
Origin = Anchor.Centre,
Colour = overlayColourProvider.Content2,
Size = new Vector2(10)
}, },
bpm = new OsuSpriteText bpm = new OsuSpriteText
{ {
Colour = overlayColourProvider.Content1, Colour = overlayColourProvider.Content1,
Anchor = Anchor.Centre, Anchor = Anchor.BottomCentre,
Origin = Anchor.Centre, Origin = Anchor.BottomCentre,
}, },
swing = new Container swing = new Container
{ {
@ -142,10 +142,10 @@ namespace osu.Game.Screens.Edit.Timing
Origin = Anchor.BottomCentre, Origin = Anchor.BottomCentre,
Children = new Drawable[] Children = new Drawable[]
{ {
new Box stick = new Box
{ {
Colour = overlayColourProvider.Content2,
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
Colour = overlayColourProvider.Colour2,
Anchor = Anchor.BottomCentre, Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre, Origin = Anchor.BottomCentre,
Width = 4, Width = 4,
@ -154,35 +154,84 @@ namespace osu.Game.Screens.Edit.Timing
{ {
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Colour = overlayColourProvider.Content2, Colour = overlayColourProvider.Colour1,
Size = new Vector2(15), Size = new Vector2(15),
RelativePositionAxes = Axes.Y, RelativePositionAxes = Axes.Y,
Y = -0.4f, Y = 0.4f,
}, },
} }
}, },
new Circle
{
Y = -25,
Anchor = Anchor.BottomCentre,
Origin = Anchor.Centre,
Colour = overlayColourProvider.Colour0,
Size = new Vector2(10)
},
}; };
} }
protected override void LoadComplete() private double beatLength;
{
base.LoadComplete(); private TimingControlPoint timingPoint;
swing
.RotateTo(20, 500, Easing.InOutQuad) private float bpmRatio;
.Then() private bool isSwinging;
.RotateTo(-20, 500, Easing.InOutQuad)
.Loop();
}
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
if (CurrentTimingPoint == null) timingPoint = Beatmap.Value.Beatmap.ControlPointInfo.TimingPointAt(BeatSyncClock.CurrentTime);
if (beatLength != timingPoint.BeatLength)
{
beatLength = timingPoint.BeatLength;
bpm.Text = $"{timingPoint.BPM:F0}";
EarlyActivationMilliseconds = timingPoint.BeatLength / 2;
bpmRatio = (float)Interpolation.ApplyEasing(Easing.OutQuad, Math.Clamp((timingPoint.BPM - 30) / 480, 0, 1));
weight.MoveToY((float)Interpolation.Lerp(0, 0.9f, bpmRatio), 600, Easing.OutQuint);
}
if (BeatSyncClock?.IsRunning != true && isSwinging)
{
swing.ClearTransforms(true);
using (swing.BeginDelayedSequence(350))
{
swing.RotateTo(0, 1000, Easing.OutQuint);
stick.FadeColour(overlayColourProvider.Colour2, 1000, Easing.OutQuint);
}
isSwinging = false;
}
}
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, ChannelAmplitudes amplitudes)
{
base.OnNewBeat(beatIndex, timingPoint, effectPoint, amplitudes);
float angle = (float)Interpolation.Lerp(25, 4, bpmRatio);
if (!IsBeatSyncedWithTrack)
return; return;
weight.Y = Math.Clamp((float)CurrentTimingPoint.BPM / 480, 0, 0.95f); isSwinging = true;
bpm.Text = $"{CurrentTimingPoint.BPM:F0}";
float currentAngle = swing.Rotation;
float targetAngle = currentAngle > 0 ? -angle : angle;
swing.RotateTo(targetAngle, beatLength, Easing.InOutQuad);
if (currentAngle != 0 && Math.Abs(currentAngle - targetAngle) > angle * 1.8f && isSwinging)
{
using (stick.BeginDelayedSequence(beatLength / 2))
stick.FlashColour(overlayColourProvider.Content1, beatLength, Easing.OutQuint);
}
} }
} }
} }

View File

@ -97,6 +97,5 @@ namespace osu.Game.Screens.Edit.Timing
} }
private static double beatLengthToBpm(double beatLength) => 60000 / beatLength; private static double beatLengthToBpm(double beatLength) => 60000 / beatLength;
} }
} }