1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-26 10:12:54 +08:00
osu-lazer/osu.Game/Screens/Edit/Timing/TapTimingControl.cs

290 lines
11 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.
2022-05-31 20:10:02 +08:00
using System.Linq;
2022-05-20 13:34:33 +08:00
using osu.Framework.Allocation;
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;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
2022-05-20 14:56:39 +08:00
using osu.Game.Beatmaps.ControlPoints;
2022-05-20 13:34:33 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
2022-05-20 13:34:33 +08:00
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays;
using osuTK;
2022-05-20 13:34:33 +08:00
namespace osu.Game.Screens.Edit.Timing
{
public class TapTimingControl : CompositeDrawable
{
[Resolved]
2022-06-02 12:10:50 +08:00
private EditorClock editorClock { get; set; } = null!;
2022-05-20 13:34:33 +08:00
2022-05-31 20:10:02 +08:00
[Resolved]
2022-06-02 12:10:50 +08:00
private EditorBeatmap beatmap { get; set; } = null!;
2022-05-31 20:10:02 +08:00
[Resolved]
2022-06-02 12:10:50 +08:00
private Bindable<ControlPointGroup> selectedGroup { get; set; } = null!;
private readonly BindableBool isHandlingTapping = new BindableBool();
2022-06-02 12:10:50 +08:00
private MetronomeDisplay metronome = null!;
2022-05-20 13:34:33 +08:00
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider, OsuColour colours)
{
const float padding = 10;
2022-05-20 13:34:33 +08:00
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
2022-05-20 13:34:33 +08:00
CornerRadius = LabelledDrawable<Drawable>.CORNER_RADIUS;
Masking = true;
InternalChildren = new Drawable[]
{
new Box
{
Colour = colourProvider.Background4,
RelativeSizeAxes = Axes.Both,
},
new GridContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2022-05-20 13:34:33 +08:00
RowDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, 200),
new Dimension(GridSizeMode.Absolute, 50),
new Dimension(GridSizeMode.Absolute, TapButton.SIZE + padding),
2022-05-20 13:34:33 +08:00
},
Content = new[]
{
new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(padding),
Children = new Drawable[]
{
new GridContainer
{
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension()
},
Content = new[]
{
new Drawable[]
{
metronome = new MetronomeDisplay
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
new WaveformComparisonDisplay(),
}
},
}
}
2022-05-31 20:10:02 +08:00
},
},
new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Bottom = padding, Horizontal = padding },
2022-05-31 20:10:02 +08:00
Children = new Drawable[]
{
2022-06-01 16:46:05 +08:00
new TimingAdjustButton(1)
2022-05-31 20:10:02 +08:00
{
Text = "Offset",
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.48f, 1),
2022-05-31 20:10:02 +08:00
Action = adjustOffset,
},
2022-06-01 16:46:05 +08:00
new TimingAdjustButton(0.1)
2022-05-31 20:10:02 +08:00
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Text = "BPM",
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.48f, 1),
2022-05-31 20:10:02 +08:00
Action = adjustBpm,
}
}
},
2022-05-20 13:34:33 +08:00
},
new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Bottom = padding, Horizontal = padding },
2022-05-20 13:34:33 +08:00
Children = new Drawable[]
{
new Container
2022-05-20 13:34:33 +08:00
{
RelativeSizeAxes = Axes.Y,
Anchor = Anchor.Centre,
Origin = Anchor.CentreRight,
Height = 0.98f,
Width = TapButton.SIZE / 1.3f,
Masking = true,
CornerRadius = 15,
Children = new Drawable[]
{
2022-06-02 12:10:50 +08:00
new InlineButton(FontAwesome.Solid.Stop, Anchor.TopLeft)
{
BackgroundColour = colourProvider.Background1,
RelativeSizeAxes = Axes.Both,
Height = 0.49f,
Action = reset,
},
2022-06-02 12:10:50 +08:00
new InlineButton(FontAwesome.Solid.Play, Anchor.BottomLeft)
{
BackgroundColour = colourProvider.Background1,
RelativeSizeAxes = Axes.Both,
Height = 0.49f,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Action = start,
},
},
2022-05-20 13:34:33 +08:00
},
new TapButton
2022-05-20 13:34:33 +08:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
IsHandlingTapping = { BindTarget = isHandlingTapping }
2022-05-20 13:34:33 +08:00
}
}
},
2022-06-01 17:53:35 +08:00
},
2022-05-20 13:34:33 +08:00
}
},
};
isHandlingTapping.BindValueChanged(handling =>
{
metronome.EnableClicking = !handling.NewValue;
if (handling.NewValue)
start();
}, true);
2022-05-20 13:34:33 +08:00
}
2022-06-02 12:10:50 +08:00
private void start()
{
editorClock.Seek(selectedGroup.Value.Time);
editorClock.Start();
}
private void reset()
{
editorClock.Stop();
editorClock.Seek(selectedGroup.Value.Time);
}
private void adjustOffset(double adjust)
{
bool wasAtStart = editorClock.CurrentTimeAccurate == selectedGroup.Value.Time;
2022-06-02 12:10:50 +08:00
// VERY TEMPORARY
var currentGroupItems = selectedGroup.Value.ControlPoints.ToArray();
beatmap.ControlPointInfo.RemoveGroup(selectedGroup.Value);
double newOffset = selectedGroup.Value.Time + adjust;
foreach (var cp in currentGroupItems)
beatmap.ControlPointInfo.Add(newOffset, cp);
// the control point might not necessarily exist yet, if currentGroupItems was empty.
selectedGroup.Value = beatmap.ControlPointInfo.GroupAt(newOffset, true);
if (!editorClock.IsRunning && wasAtStart)
2022-06-02 12:10:50 +08:00
editorClock.Seek(newOffset);
}
private void adjustBpm(double adjust)
{
var timing = selectedGroup.Value.ControlPoints.OfType<TimingControlPoint>().FirstOrDefault();
if (timing == null)
return;
timing.BeatLength = 60000 / (timing.BPM + adjust);
}
private class InlineButton : OsuButton
{
private readonly IconUsage icon;
private readonly Anchor anchor;
2022-06-02 12:10:50 +08:00
private SpriteIcon spriteIcon = null!;
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
2022-06-02 12:10:50 +08:00
public InlineButton(IconUsage icon, Anchor anchor)
{
this.icon = icon;
this.anchor = anchor;
}
protected override void LoadComplete()
{
base.LoadComplete();
Content.CornerRadius = 0;
Content.Masking = false;
BackgroundColour = colourProvider.Background2;
Content.Add(new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding(15),
Children = new Drawable[]
{
spriteIcon = new SpriteIcon
{
Icon = icon,
Size = new Vector2(22),
Anchor = anchor,
Origin = anchor,
Colour = colourProvider.Background1,
},
}
});
}
protected override bool OnMouseDown(MouseDownEvent e)
{
// scale looks bad so don't call base.
return false;
}
protected override bool OnHover(HoverEvent e)
{
spriteIcon.FadeColour(colourProvider.Content2, 200, Easing.OutQuint);
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
spriteIcon.FadeColour(colourProvider.Background1, 200, Easing.OutQuint);
base.OnHoverLost(e);
}
}
2022-05-20 13:34:33 +08:00
}
}