1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 12:42:54 +08:00

Add ability to lock the WaveformComparison display to a current location

This commit is contained in:
Dean Herbert 2022-05-31 16:15:53 +09:00
parent 79a17fc86a
commit 6bc68ada43

View File

@ -14,6 +14,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays;
@ -26,6 +27,8 @@ namespace osu.Game.Screens.Edit.Timing
{
private const int total_waveforms = 8;
private const float corner_radius = LabelledDrawable<Drawable>.CORNER_RADIUS;
private readonly BindableNumber<double> beatLength = new BindableDouble();
[Resolved]
@ -49,11 +52,18 @@ namespace osu.Game.Screens.Edit.Timing
private readonly IBindableList<ControlPointGroup> controlPointGroups = new BindableList<ControlPointGroup>();
private readonly BindableBool displayLocked = new BindableBool();
private LockedOverlay lockedOverlay = null!;
[Resolved]
private OsuColour colours { get; set; } = null!;
public WaveformComparisonDisplay()
{
RelativeSizeAxes = Axes.Both;
CornerRadius = LabelledDrawable<Drawable>.CORNER_RADIUS;
CornerRadius = corner_radius;
Masking = true;
}
@ -81,12 +91,19 @@ namespace osu.Game.Screens.Edit.Timing
Width = 3,
});
AddInternal(lockedOverlay = new LockedOverlay());
selectedGroup.BindValueChanged(_ => updateTimingGroup(), true);
controlPointGroups.BindTo(editorBeatmap.ControlPointInfo.Groups);
controlPointGroups.BindCollectionChanged((_, __) => updateTimingGroup());
beatLength.BindValueChanged(_ => showFrom(lastDisplayedBeatIndex), true);
displayLocked.BindValueChanged(locked =>
{
lockedOverlay.FadeTo(locked.NewValue ? 1 : 0, 200, Easing.OutQuint);
}, true);
}
private void updateTimingGroup()
@ -130,6 +147,12 @@ namespace osu.Game.Screens.Edit.Timing
return base.OnMouseMove(e);
}
protected override bool OnClick(ClickEvent e)
{
displayLocked.Toggle();
return true;
}
protected override void Update()
{
base.Update();
@ -147,6 +170,9 @@ namespace osu.Game.Screens.Edit.Timing
if (lastDisplayedBeatIndex == beatIndex)
return;
if (displayLocked.Value)
return;
// Chosen as a pretty usable number across all BPMs.
// Optimally we'd want this to scale with the BPM in question, but performing
// scaling of the display is both expensive in resampling, and decreases usability
@ -175,6 +201,64 @@ namespace osu.Game.Screens.Edit.Timing
lastDisplayedBeatIndex = beatIndex;
}
internal class LockedOverlay : CompositeDrawable
{
private OsuSpriteText text = null!;
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
RelativeSizeAxes = Axes.Both;
Masking = true;
CornerRadius = corner_radius;
BorderColour = colours.Red;
BorderThickness = 3;
Alpha = 0;
InternalChildren = new Drawable[]
{
new Box
{
AlwaysPresent = true,
RelativeSizeAxes = Axes.Both,
Alpha = 0,
},
new Container
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
{
Colour = colours.Red,
RelativeSizeAxes = Axes.Both,
},
text = new OsuSpriteText
{
Colour = colours.GrayF,
Text = "Locked",
Margin = new MarginPadding(5),
Shadow = false,
Font = OsuFont.Default.With(size: 12, weight: FontWeight.SemiBold),
}
}
},
};
}
protected override void LoadComplete()
{
base.LoadComplete();
text
.FadeIn().Then().Delay(500)
.FadeOut().Then().Delay(500)
.Loop();
}
}
internal class WaveformRow : CompositeDrawable
{
private OsuSpriteText beatIndexText = null!;