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;
|
2022-05-20 15:45:01 +08:00
|
|
|
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-06-01 21:00:54 +08:00
|
|
|
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;
|
2022-06-01 21:00:54 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-05-20 13:34:33 +08:00
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
|
|
|
using osu.Game.Overlays;
|
2022-06-01 21:00:54 +08:00
|
|
|
using osuTK;
|
2022-05-20 13:34:33 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Timing
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class TapTimingControl : CompositeDrawable
|
2022-05-20 13:34:33 +08:00
|
|
|
{
|
|
|
|
[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
|
|
|
|
2022-05-20 16:12:35 +08:00
|
|
|
[Resolved]
|
2022-06-02 12:10:50 +08:00
|
|
|
private Bindable<ControlPointGroup> selectedGroup { get; set; } = null!;
|
2022-05-20 16:12:35 +08:00
|
|
|
|
2022-06-01 19:48:06 +08:00
|
|
|
private readonly BindableBool isHandlingTapping = new BindableBool();
|
|
|
|
|
2022-06-02 12:10:50 +08:00
|
|
|
private MetronomeDisplay metronome = null!;
|
2022-06-01 19:48:06 +08:00
|
|
|
|
2022-05-20 13:34:33 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2023-01-06 08:46:49 +08:00
|
|
|
private void load(OverlayColourProvider colourProvider, OsuColour colours)
|
2022-05-20 13:34:33 +08:00
|
|
|
{
|
2022-06-01 21:00:54 +08:00
|
|
|
const float padding = 10;
|
|
|
|
|
2022-05-20 13:34:33 +08:00
|
|
|
RelativeSizeAxes = Axes.X;
|
2022-05-23 18:52:01 +08:00
|
|
|
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
|
|
|
|
{
|
2022-05-23 18:52:01 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2022-05-20 13:34:33 +08:00
|
|
|
RowDimensions = new[]
|
|
|
|
{
|
2022-05-23 18:52:01 +08:00
|
|
|
new Dimension(GridSizeMode.Absolute, 200),
|
2022-06-01 21:00:54 +08:00
|
|
|
new Dimension(GridSizeMode.Absolute, 50),
|
|
|
|
new Dimension(GridSizeMode.Absolute, TapButton.SIZE + padding),
|
2022-05-20 13:34:33 +08:00
|
|
|
},
|
|
|
|
Content = new[]
|
|
|
|
{
|
|
|
|
new Drawable[]
|
|
|
|
{
|
2024-02-21 04:18:37 +08:00
|
|
|
new GridContainer
|
2022-05-20 16:12:35 +08:00
|
|
|
{
|
2022-05-23 18:52:01 +08:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-06-01 21:00:54 +08:00
|
|
|
Padding = new MarginPadding(padding),
|
2024-02-21 04:18:37 +08:00
|
|
|
ColumnDimensions = new[]
|
|
|
|
{
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
new Dimension()
|
|
|
|
},
|
|
|
|
Content = new[]
|
2022-05-23 18:52:01 +08:00
|
|
|
{
|
2024-02-21 04:18:37 +08:00
|
|
|
new Drawable[]
|
2022-05-23 18:52:01 +08:00
|
|
|
{
|
2024-02-21 04:18:37 +08:00
|
|
|
metronome = new MetronomeDisplay
|
2022-05-23 18:52:01 +08:00
|
|
|
{
|
2024-02-21 04:18:37 +08:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
2022-05-23 18:52:01 +08:00
|
|
|
},
|
2024-02-21 04:18:37 +08:00
|
|
|
new WaveformComparisonDisplay()
|
2022-05-23 18:52:01 +08:00
|
|
|
}
|
2024-02-21 04:18:37 +08:00
|
|
|
},
|
|
|
|
}
|
2022-05-31 20:10:02 +08:00
|
|
|
},
|
|
|
|
new Drawable[]
|
|
|
|
{
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2022-06-01 21:00:54 +08:00
|
|
|
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",
|
2022-06-01 21:00:54 +08:00
|
|
|
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",
|
2022-06-01 21:00:54 +08:00
|
|
|
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,
|
2022-06-01 21:00:54 +08:00
|
|
|
Padding = new MarginPadding { Bottom = padding, Horizontal = padding },
|
2022-05-20 13:34:33 +08:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2022-06-01 21:00:54 +08:00
|
|
|
new Container
|
2022-05-20 13:34:33 +08:00
|
|
|
{
|
2022-06-01 21:00:54 +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)
|
2022-06-01 21:00:54 +08:00
|
|
|
{
|
|
|
|
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)
|
2022-06-01 21:00:54 +08:00
|
|
|
{
|
|
|
|
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
|
|
|
},
|
2022-06-01 21:00:54 +08:00
|
|
|
new TapButton
|
2022-05-20 13:34:33 +08:00
|
|
|
{
|
2022-06-01 21:00:54 +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
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
2022-06-01 19:48:06 +08:00
|
|
|
|
|
|
|
isHandlingTapping.BindValueChanged(handling =>
|
|
|
|
{
|
|
|
|
metronome.EnableClicking = !handling.NewValue;
|
2022-06-01 19:57:16 +08:00
|
|
|
|
|
|
|
if (handling.NewValue)
|
2022-06-01 21:00:54 +08:00
|
|
|
start();
|
2022-06-01 19:48:06 +08:00
|
|
|
}, true);
|
2022-05-20 13:34:33 +08:00
|
|
|
}
|
|
|
|
|
2022-06-02 12:10:50 +08:00
|
|
|
private void start()
|
|
|
|
{
|
2022-11-23 14:39:56 +08:00
|
|
|
if (selectedGroup.Value == null)
|
|
|
|
return;
|
|
|
|
|
2022-06-02 12:10:50 +08:00
|
|
|
editorClock.Seek(selectedGroup.Value.Time);
|
|
|
|
editorClock.Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void reset()
|
|
|
|
{
|
2022-11-23 14:39:56 +08:00
|
|
|
if (selectedGroup.Value == null)
|
|
|
|
return;
|
|
|
|
|
2022-06-02 12:10:50 +08:00
|
|
|
editorClock.Stop();
|
|
|
|
editorClock.Seek(selectedGroup.Value.Time);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void adjustOffset(double adjust)
|
|
|
|
{
|
2022-11-24 00:22:40 +08:00
|
|
|
if (selectedGroup.Value == null)
|
|
|
|
return;
|
|
|
|
|
2022-06-19 00:34:58 +08:00
|
|
|
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)
|
2024-06-08 03:57:12 +08:00
|
|
|
{
|
2024-06-09 17:27:53 +08:00
|
|
|
if (beatmap.AdjustNotesOnOffsetBPMChange.Value && cp is TimingControlPoint tp)
|
2024-06-08 03:57:12 +08:00
|
|
|
tp.AdjustHitObjectOffset(beatmap, adjust);
|
2022-06-02 12:10:50 +08:00
|
|
|
beatmap.ControlPointInfo.Add(newOffset, cp);
|
2024-06-08 03:57:12 +08:00
|
|
|
}
|
2022-06-02 12:10:50 +08:00
|
|
|
|
|
|
|
// the control point might not necessarily exist yet, if currentGroupItems was empty.
|
|
|
|
selectedGroup.Value = beatmap.ControlPointInfo.GroupAt(newOffset, true);
|
|
|
|
|
2022-06-19 00:34:58 +08:00
|
|
|
if (!editorClock.IsRunning && wasAtStart)
|
2022-06-02 12:10:50 +08:00
|
|
|
editorClock.Seek(newOffset);
|
2024-06-05 23:57:44 +08:00
|
|
|
|
2024-06-08 03:57:12 +08:00
|
|
|
beatmap.UpdateAllHitObjects();
|
2022-06-02 12:10:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void adjustBpm(double adjust)
|
|
|
|
{
|
2022-11-24 00:22:40 +08:00
|
|
|
var timing = selectedGroup.Value?.ControlPoints.OfType<TimingControlPoint>().FirstOrDefault();
|
2022-06-02 12:10:50 +08:00
|
|
|
|
|
|
|
if (timing == null)
|
|
|
|
return;
|
|
|
|
|
2024-06-09 17:27:53 +08:00
|
|
|
timing.BeatLength = 60000 / (timing.BPM + adjust);
|
2024-06-02 22:38:58 +08:00
|
|
|
|
2024-06-09 17:27:53 +08:00
|
|
|
if (beatmap.AdjustNotesOnOffsetBPMChange.Value)
|
|
|
|
timing.SetHitObjectBPM(beatmap, 60000 / (timing.BPM - adjust));
|
2024-06-05 23:57:44 +08:00
|
|
|
|
2024-06-08 03:57:12 +08:00
|
|
|
beatmap.UpdateAllHitObjects();
|
2022-06-02 12:10:50 +08:00
|
|
|
}
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
private partial class InlineButton : OsuButton
|
2022-06-01 21:00:54 +08:00
|
|
|
{
|
|
|
|
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-01 21:00:54 +08:00
|
|
|
|
2022-06-02 12:10:50 +08:00
|
|
|
public InlineButton(IconUsage icon, Anchor anchor)
|
2022-06-01 21:00:54 +08:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|