1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 22:27:25 +08:00
osu-lazer/osu.Game/Screens/Edit/Timing/TapTimingControl.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

342 lines
13 KiB
C#
Raw Normal View History

2022-05-20 13:34:33 +08:00
// 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 osu.Framework.Allocation;
2022-05-20 14:56:39 +08:00
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
2022-05-20 13:34:33 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2022-05-20 14:56:39 +08:00
using osu.Framework.Utils;
using osu.Game.Beatmaps.ControlPoints;
2022-05-20 13:34:33 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays;
using osuTK;
namespace osu.Game.Screens.Edit.Timing
{
public class TapTimingControl : CompositeDrawable
{
[Resolved]
private EditorClock editorClock { get; set; }
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider, OsuColour colours)
{
Height = 200;
RelativeSizeAxes = Axes.X;
CornerRadius = LabelledDrawable<Drawable>.CORNER_RADIUS;
Masking = true;
InternalChildren = new Drawable[]
{
new Box
{
Colour = colourProvider.Background4,
RelativeSizeAxes = Axes.Both,
},
new GridContainer
{
RelativeSizeAxes = Axes.Both,
RowDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.Absolute, 60),
},
Content = new[]
{
new Drawable[]
{
new Metronome()
},
new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(10),
Children = new Drawable[]
{
new RoundedButton
{
Text = "Reset",
BackgroundColour = colours.Pink,
RelativeSizeAxes = Axes.X,
Width = 0.3f,
Action = reset,
},
new RoundedButton
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Text = "Tap to beat",
RelativeSizeAxes = Axes.X,
BackgroundColour = colourProvider.Background1,
Width = 0.68f,
Action = tap,
}
}
},
}
}
},
};
}
private void tap()
{
if (!editorClock.IsRunning)
{
editorClock.Seek(0);
editorClock.Start();
}
}
private void reset()
{
editorClock.Stop();
}
private class Metronome : BeatSyncedContainer
{
private Container swing;
private OsuSpriteText bpmText;
private Drawable weight;
private Drawable stick;
2022-05-20 14:56:39 +08:00
[Resolved]
private OverlayColourProvider overlayColourProvider { get; set; }
2022-05-20 13:34:33 +08:00
[BackgroundDependencyLoader]
2022-05-20 14:56:39 +08:00
private void load()
2022-05-20 13:34:33 +08:00
{
const float taper = 25;
2022-05-20 15:25:24 +08:00
const float swing_vertical_offset = -23;
2022-05-20 15:55:07 +08:00
const float lower_cover_height = 32;
2022-05-20 15:25:24 +08:00
var triangleSize = new Vector2(90, 120 + taper);
2022-05-20 15:25:24 +08:00
Margin = new MarginPadding(10);
2022-05-20 13:34:33 +08:00
AutoSizeAxes = Axes.Both;
InternalChildren = new Drawable[]
{
new Container
2022-05-20 13:34:33 +08:00
{
2022-05-20 15:25:24 +08:00
Name = @"Taper adjust",
Masking = true,
2022-05-20 14:56:39 +08:00
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
2022-05-20 15:33:27 +08:00
Size = new Vector2(triangleSize.X, triangleSize.Y - taper),
Children = new Drawable[]
{
2022-05-20 15:33:27 +08:00
new Triangle
{
Name = @"Main body",
EdgeSmoothness = new Vector2(1),
2022-05-20 15:33:27 +08:00
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Size = triangleSize,
Colour = overlayColourProvider.Background3,
},
},
2022-05-20 13:34:33 +08:00
},
2022-05-20 15:55:07 +08:00
new Circle
{
Name = "Centre marker",
Colour = overlayColourProvider.Background5,
RelativeSizeAxes = Axes.Y,
Width = 2,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Y = -(lower_cover_height + 3),
Height = 0.65f,
},
2022-05-20 13:34:33 +08:00
swing = new Container
{
2022-05-20 15:25:24 +08:00
Name = @"Swing",
2022-05-20 13:34:33 +08:00
RelativeSizeAxes = Axes.Both,
2022-05-20 15:25:24 +08:00
Y = swing_vertical_offset,
Height = 0.80f,
2022-05-20 13:34:33 +08:00
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Children = new[]
2022-05-20 13:34:33 +08:00
{
stick = new Circle
2022-05-20 13:34:33 +08:00
{
2022-05-20 15:25:24 +08:00
Name = @"Stick",
2022-05-20 13:34:33 +08:00
RelativeSizeAxes = Axes.Y,
2022-05-20 14:56:39 +08:00
Colour = overlayColourProvider.Colour2,
2022-05-20 13:34:33 +08:00
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Width = 4,
},
weight = new Container
2022-05-20 13:34:33 +08:00
{
2022-05-20 15:25:24 +08:00
Name = @"Weight",
2022-05-20 13:34:33 +08:00
Anchor = Anchor.TopCentre,
Origin = Anchor.Centre,
Colour = overlayColourProvider.Colour0,
Size = new Vector2(10),
Rotation = 180,
2022-05-20 13:34:33 +08:00
RelativePositionAxes = Axes.Y,
2022-05-20 14:56:39 +08:00
Y = 0.4f,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Shear = new Vector2(0.2f, 0),
EdgeSmoothness = new Vector2(1),
},
new Box
{
RelativeSizeAxes = Axes.Both,
Shear = new Vector2(-0.2f, 0),
EdgeSmoothness = new Vector2(1),
},
}
2022-05-20 13:34:33 +08:00
},
}
},
2022-05-20 15:33:27 +08:00
new Container
{
Name = @"Taper adjust",
Masking = true,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Size = new Vector2(triangleSize.X, triangleSize.Y - taper),
Children = new Drawable[]
{
new Circle
{
Name = @"Locking wedge",
Anchor = Anchor.TopCentre,
Origin = Anchor.Centre,
Colour = overlayColourProvider.Background1,
Size = new Vector2(8),
}
},
},
2022-05-20 14:56:39 +08:00
new Circle
{
2022-05-20 15:25:24 +08:00
Name = @"Swing connection point",
Y = swing_vertical_offset,
2022-05-20 14:56:39 +08:00
Anchor = Anchor.BottomCentre,
Origin = Anchor.Centre,
Colour = overlayColourProvider.Colour0,
Size = new Vector2(8)
},
new Container
{
2022-05-20 15:25:24 +08:00
Name = @"Lower cover",
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
2022-05-20 15:55:07 +08:00
RelativeSizeAxes = Axes.X,
Masking = true,
2022-05-20 15:55:07 +08:00
Height = lower_cover_height,
Children = new Drawable[]
{
new Triangle
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Size = triangleSize,
Colour = overlayColourProvider.Background2,
EdgeSmoothness = new Vector2(1),
Alpha = 0.8f
},
}
},
bpmText = new OsuSpriteText
{
2022-05-20 15:25:24 +08:00
Name = @"BPM display",
Colour = overlayColourProvider.Content1,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Y = -3,
2022-05-20 14:56:39 +08:00
},
2022-05-20 13:34:33 +08:00
};
}
2022-05-20 14:56:39 +08:00
private double beatLength;
private TimingControlPoint timingPoint;
private bool isSwinging;
2022-05-20 13:34:33 +08:00
private readonly BindableInt interpolatedBpm = new BindableInt();
protected override void LoadComplete()
{
base.LoadComplete();
interpolatedBpm.BindValueChanged(bpm => bpmText.Text = bpm.NewValue.ToString());
}
2022-05-20 13:34:33 +08:00
protected override void Update()
{
base.Update();
2022-05-20 14:56:39 +08:00
timingPoint = Beatmap.Value.Beatmap.ControlPointInfo.TimingPointAt(BeatSyncClock.CurrentTime);
if (beatLength != timingPoint.BeatLength)
{
beatLength = timingPoint.BeatLength;
EarlyActivationMilliseconds = timingPoint.BeatLength / 2;
float bpmRatio = (float)Interpolation.ApplyEasing(Easing.OutQuad, Math.Clamp((timingPoint.BPM - 30) / 480, 0, 1));
2022-05-20 14:56:39 +08:00
weight.MoveToY((float)Interpolation.Lerp(0.1f, 0.83f, bpmRatio), 600, Easing.OutQuint);
this.TransformBindableTo(interpolatedBpm, (int)timingPoint.BPM, 600, Easing.OutQuint);
2022-05-20 14:56:39 +08:00
}
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);
const float angle = 27.5f;
2022-05-20 14:56:39 +08:00
if (!IsBeatSyncedWithTrack)
2022-05-20 13:34:33 +08:00
return;
2022-05-20 14:56:39 +08:00
isSwinging = true;
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);
}
2022-05-20 13:34:33 +08:00
}
}
}
}