1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 17:57:29 +08:00

shift alt seek to open next sample edit popover

This commit is contained in:
OliBomby 2024-07-05 14:16:51 +02:00
parent 98610f4f6d
commit 7d6ade7e84
3 changed files with 84 additions and 9 deletions

View File

@ -2,9 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Extensions;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Audio; using osu.Game.Audio;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
@ -24,12 +22,10 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
NodeIndex = nodeIndex; NodeIndex = nodeIndex;
} }
protected override bool OnDoubleClick(DoubleClickEvent e) protected override double GetTime()
{ {
var hasRepeats = (IHasRepeats)HitObject; var hasRepeats = (IHasRepeats)HitObject;
EditorClock?.SeekSmoothlyTo(HitObject.StartTime + hasRepeats.Duration * NodeIndex / hasRepeats.SpanCount()); return HitObject.StartTime + hasRepeats.Duration * NodeIndex / hasRepeats.SpanCount();
this.ShowPopover();
return true;
} }
protected override IList<HitSampleInfo> GetSamples() protected override IList<HitSampleInfo> GetSamples()

View File

@ -21,6 +21,7 @@ using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Screens.Edit.Components.TernaryButtons; using osu.Game.Screens.Edit.Components.TernaryButtons;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Screens.Edit.Timing; using osu.Game.Screens.Edit.Timing;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -33,7 +34,10 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
public readonly HitObject HitObject; public readonly HitObject HitObject;
[Resolved] [Resolved]
protected EditorClock? EditorClock { get; private set; } private EditorClock? editorClock { get; set; }
[Resolved]
private Editor? editor { get; set; }
public SamplePointPiece(HitObject hitObject) public SamplePointPiece(HitObject hitObject)
{ {
@ -44,11 +48,30 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
protected override Color4 GetRepresentingColour(OsuColour colours) => AlternativeColor ? colours.Pink2 : colours.Pink1; protected override Color4 GetRepresentingColour(OsuColour colours) => AlternativeColor ? colours.Pink2 : colours.Pink1;
protected virtual double GetTime() => HitObject is IHasRepeats r ? HitObject.StartTime + r.Duration / r.SpanCount() / 2 : HitObject.StartTime;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
HitObject.DefaultsApplied += _ => updateText(); HitObject.DefaultsApplied += _ => updateText();
updateText(); updateText();
if (editor != null)
editor.ShowSampleEditPopoverRequested += OnShowSampleEditPopoverRequested;
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (editor != null)
editor.ShowSampleEditPopoverRequested -= OnShowSampleEditPopoverRequested;
}
private void OnShowSampleEditPopoverRequested(double time)
{
if (time == GetTime())
this.ShowPopover();
} }
protected override bool OnClick(ClickEvent e) protected override bool OnClick(ClickEvent e)
@ -59,7 +82,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
protected override bool OnDoubleClick(DoubleClickEvent e) protected override bool OnDoubleClick(DoubleClickEvent e)
{ {
EditorClock?.SeekSmoothlyTo(HitObject.StartTime); editorClock?.SeekSmoothlyTo(GetTime());
this.ShowPopover(); this.ShowPopover();
return true; return true;
} }

View File

@ -43,6 +43,7 @@ using osu.Game.Overlays.OSD;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Screens.Edit.Components.Menus; using osu.Game.Screens.Edit.Components.Menus;
using osu.Game.Screens.Edit.Compose; using osu.Game.Screens.Edit.Compose;
using osu.Game.Screens.Edit.Compose.Components.Timeline; using osu.Game.Screens.Edit.Compose.Components.Timeline;
@ -1074,11 +1075,66 @@ namespace osu.Game.Screens.Edit
clock.SeekSmoothlyTo(found.StartTime); clock.SeekSmoothlyTo(found.StartTime);
} }
[CanBeNull]
public event Action<double> ShowSampleEditPopoverRequested;
private void seekSamplePoint(int direction)
{
double currentTime = clock.CurrentTimeAccurate;
var current = direction < 1
? editorBeatmap.HitObjects.LastOrDefault(p => p is IHasRepeats r && p.StartTime < currentTime && r.EndTime >= currentTime)
: editorBeatmap.HitObjects.LastOrDefault(p => p is IHasRepeats r && p.StartTime <= currentTime && r.EndTime > currentTime);
if (current == null)
{
if (direction < 1)
{
current = editorBeatmap.HitObjects.LastOrDefault(p => p.StartTime < currentTime);
if (current != null)
clock.SeekSmoothlyTo(current is IHasRepeats r ? r.EndTime : current.StartTime);
}
else
{
current = editorBeatmap.HitObjects.FirstOrDefault(p => p.StartTime > currentTime);
if (current != null)
clock.SeekSmoothlyTo(current.StartTime);
}
}
else
{
// Find the next node sample point
var r = (IHasRepeats)current;
double[] nodeSamplePointTimes = new double[r.RepeatCount + 3];
nodeSamplePointTimes[0] = current.StartTime;
// The sample point for the main samples is sandwiched between the head and the first repeat
nodeSamplePointTimes[1] = current.StartTime + r.Duration / r.SpanCount() / 2;
for (int i = 0; i < r.SpanCount(); i++)
{
nodeSamplePointTimes[i + 2] = current.StartTime + r.Duration / r.SpanCount() * (i + 1);
}
double found = direction < 1
? nodeSamplePointTimes.Last(p => p < currentTime)
: nodeSamplePointTimes.First(p => p > currentTime);
clock.SeekSmoothlyTo(found);
}
// Show the sample edit popover at the current time
ShowSampleEditPopoverRequested?.Invoke(clock.CurrentTimeAccurate);
}
private void seek(UIEvent e, int direction) private void seek(UIEvent e, int direction)
{ {
if (e.AltPressed) if (e.AltPressed)
{ {
seekHitObject(direction); if (e.ShiftPressed)
seekSamplePoint(direction);
else
seekHitObject(direction);
return; return;
} }