From c1720c128d1f591281194b4b76744ea7dcefd7cd Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 23 May 2022 21:00:21 +0900 Subject: [PATCH] Dim rows which are not part of the active control point (and offset centre) --- .../Edit/Timing/WaveformComparisonDisplay.cs | 55 ++++++++++++++++--- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/osu.Game/Screens/Edit/Timing/WaveformComparisonDisplay.cs b/osu.Game/Screens/Edit/Timing/WaveformComparisonDisplay.cs index e410d380d6..2667ae5396 100644 --- a/osu.Game/Screens/Edit/Timing/WaveformComparisonDisplay.cs +++ b/osu.Game/Screens/Edit/Timing/WaveformComparisonDisplay.cs @@ -33,6 +33,9 @@ namespace osu.Game.Screens.Edit.Timing [Resolved] private IBindable beatmap { get; set; } = null!; + [Resolved] + private EditorBeatmap editorBeatmap { get; set; } = null!; + [Resolved] private Bindable selectedGroup { get; set; } = null!; @@ -46,7 +49,10 @@ namespace osu.Game.Screens.Edit.Timing private int lastDisplayedBeatIndex; - private double offsetZeroTime => selectedGroup.Value?.Time ?? 0; + private double selectedGroupStartTime; + private double selectedGroupEndTime; + + private readonly BindableList controlPointGroups = new BindableList(); public WaveformComparisonDisplay() { @@ -88,20 +94,45 @@ namespace osu.Game.Screens.Edit.Timing AddInternal(beatIndexText = new OsuSpriteText { - Margin = new MarginPadding(5), + Anchor = Anchor.CentreLeft, + Margin = new MarginPadding(4), }); - selectedGroup.BindValueChanged(selectedGroupChanged, true); + selectedGroup.BindValueChanged(_ => updateTimingGroup(), true); + + ((IBindableList)controlPointGroups).BindTo(editorBeatmap.ControlPointInfo.Groups); + controlPointGroups.BindCollectionChanged((_, __) => updateTimingGroup()); + beatLength.BindValueChanged(_ => showFrom(lastDisplayedBeatIndex), true); } - private void selectedGroupChanged(ValueChangedEvent group) + private void updateTimingGroup() { - timingPoint = selectedGroup.Value?.ControlPoints.OfType().FirstOrDefault() - ?? new TimingControlPoint(); - beatLength.UnbindBindings(); + + selectedGroupStartTime = 0; + selectedGroupEndTime = beatmap.Value.Track.Length; + + var tcp = selectedGroup.Value?.ControlPoints.OfType().FirstOrDefault(); + + if (tcp == null) + { + timingPoint = new TimingControlPoint(); + return; + } + + timingPoint = tcp; beatLength.BindTo(timingPoint.BeatLengthBindable); + + selectedGroupStartTime = selectedGroup.Value?.Time ?? 0; + + var nextGroup = editorBeatmap.ControlPointInfo.TimingPoints + .SkipWhile(g => g != tcp) + .Skip(1) + .FirstOrDefault(); + + if (nextGroup != null) + selectedGroupEndTime = nextGroup.Time; } protected override bool OnHover(HoverEvent e) => true; @@ -122,7 +153,7 @@ namespace osu.Game.Screens.Edit.Timing if (!IsHovered) { - int beatOffset = (int)Math.Max(0, ((editorClock.CurrentTime - offsetZeroTime) / timingPoint.BeatLength)); + int beatOffset = (int)Math.Floor((editorClock.CurrentTimeAccurate - selectedGroupStartTime) / timingPoint.BeatLength); showFrom(beatOffset); } @@ -137,11 +168,17 @@ namespace osu.Game.Screens.Edit.Timing beatIndexText.Text = beatIndex.ToString(); + // Start displaying from before the current beat + beatIndex -= total_waveforms / 2; + foreach (var waveform in InternalChildren.OfType()) { // offset to the required beat index. - float offset = (float)(offsetZeroTime + (beatIndex * timingPoint.BeatLength - (visible_width / 2))) / trackLength * scale; + double time = selectedGroupStartTime + beatIndex * timingPoint.BeatLength; + float offset = (float)(time - visible_width / 2) / trackLength * scale; + + waveform.Alpha = time < selectedGroupStartTime || time > selectedGroupEndTime ? 0.2f : 1; waveform.X = -offset; waveform.Scale = new Vector2(scale, 1);