mirror of
https://github.com/ppy/osu.git
synced 2025-01-11 04:25:06 +08:00
Moved HitObject adjustments to TimingControlPoint
This commit is contained in:
parent
2db55f9379
commit
559f94aa02
@ -2,9 +2,14 @@
|
|||||||
// 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;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Beatmaps.Timing;
|
using osu.Game.Beatmaps.Timing;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Rulesets.Objects;
|
||||||
|
using osu.Game.Rulesets.Objects.Types;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Beatmaps.ControlPoints
|
namespace osu.Game.Beatmaps.ControlPoints
|
||||||
@ -105,5 +110,35 @@ namespace osu.Game.Beatmaps.ControlPoints
|
|||||||
&& BeatLength.Equals(other.BeatLength);
|
&& BeatLength.Equals(other.BeatLength);
|
||||||
|
|
||||||
public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), TimeSignature, BeatLength, OmitFirstBarLine);
|
public override int GetHashCode() => HashCode.Combine(base.GetHashCode(), TimeSignature, BeatLength, OmitFirstBarLine);
|
||||||
|
|
||||||
|
public List<HitObject> HitObjectsInTimingRange(IBeatmap beatmap)
|
||||||
|
{
|
||||||
|
// If the first group, we grab all hitobjects prior to the next, if the last group, we grab all remaining hitobjects
|
||||||
|
double startTime = beatmap.ControlPointInfo.TimingPoints.Any(x => x.Time < Time) ? Time : double.MinValue;
|
||||||
|
double endTime = beatmap.ControlPointInfo.TimingPoints.FirstOrDefault(x => x.Time > Time)?.Time ?? double.MaxValue;
|
||||||
|
|
||||||
|
return beatmap.HitObjects.Where(x => Precision.AlmostBigger(x.StartTime, startTime) && Precision.DefinitelyBigger(endTime, x.StartTime)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AdjustHitObjectOffset(IBeatmap beatmap, double adjust)
|
||||||
|
{
|
||||||
|
foreach (HitObject hitObject in HitObjectsInTimingRange(beatmap))
|
||||||
|
{
|
||||||
|
hitObject.StartTime += adjust;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetHitObjectBPM(IBeatmap beatmap, double newBeatLength)
|
||||||
|
{
|
||||||
|
foreach (HitObject hitObject in HitObjectsInTimingRange(beatmap))
|
||||||
|
{
|
||||||
|
double beat = (hitObject.StartTime - Time) / BeatLength;
|
||||||
|
|
||||||
|
hitObject.StartTime = (beat * newBeatLength) + Time;
|
||||||
|
|
||||||
|
if (hitObject is not IHasRepeats && hitObject is IHasDuration hitObjectWithDuration)
|
||||||
|
hitObjectWithDuration.Duration *= newBeatLength / BeatLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -211,15 +211,6 @@ namespace osu.Game.Screens.Edit.Timing
|
|||||||
editorClock.Seek(selectedGroup.Value.Time);
|
editorClock.Seek(selectedGroup.Value.Time);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<HitObject> hitObjectsInTimingRange(EditorBeatmap beatmap, ControlPointGroup selectedGroup)
|
|
||||||
{
|
|
||||||
// If the first group, we grab all hitobjects prior to the next, if the last group, we grab all remaining hitobjects
|
|
||||||
double startTime = beatmap.ControlPointInfo.TimingPoints.Any(x => x.Time < selectedGroup.Time) ? selectedGroup.Time : double.MinValue;
|
|
||||||
double endTime = beatmap.ControlPointInfo.TimingPoints.FirstOrDefault(x => x.Time > selectedGroup.Time)?.Time ?? double.MaxValue;
|
|
||||||
|
|
||||||
return beatmap.HitObjects.Where(x => Precision.AlmostBigger(x.StartTime, startTime) && Precision.DefinitelyBigger(endTime, x.StartTime)).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void adjustOffset(double adjust)
|
private void adjustOffset(double adjust)
|
||||||
{
|
{
|
||||||
if (selectedGroup.Value == null)
|
if (selectedGroup.Value == null)
|
||||||
@ -227,8 +218,6 @@ namespace osu.Game.Screens.Edit.Timing
|
|||||||
|
|
||||||
bool wasAtStart = editorClock.CurrentTimeAccurate == selectedGroup.Value.Time;
|
bool wasAtStart = editorClock.CurrentTimeAccurate == selectedGroup.Value.Time;
|
||||||
|
|
||||||
List<HitObject> hitObjectsInRange = hitObjectsInTimingRange(beatmap, selectedGroup.Value);
|
|
||||||
|
|
||||||
// VERY TEMPORARY
|
// VERY TEMPORARY
|
||||||
var currentGroupItems = selectedGroup.Value.ControlPoints.ToArray();
|
var currentGroupItems = selectedGroup.Value.ControlPoints.ToArray();
|
||||||
|
|
||||||
@ -237,26 +226,22 @@ namespace osu.Game.Screens.Edit.Timing
|
|||||||
double newOffset = selectedGroup.Value.Time + adjust;
|
double newOffset = selectedGroup.Value.Time + adjust;
|
||||||
|
|
||||||
foreach (var cp in currentGroupItems)
|
foreach (var cp in currentGroupItems)
|
||||||
|
{
|
||||||
|
if (adjustPlacedNotes.Current.Value && cp is TimingControlPoint tp)
|
||||||
|
tp.AdjustHitObjectOffset(beatmap, adjust);
|
||||||
beatmap.ControlPointInfo.Add(newOffset, cp);
|
beatmap.ControlPointInfo.Add(newOffset, cp);
|
||||||
|
}
|
||||||
|
|
||||||
// the control point might not necessarily exist yet, if currentGroupItems was empty.
|
// the control point might not necessarily exist yet, if currentGroupItems was empty.
|
||||||
selectedGroup.Value = beatmap.ControlPointInfo.GroupAt(newOffset, true);
|
selectedGroup.Value = beatmap.ControlPointInfo.GroupAt(newOffset, true);
|
||||||
|
|
||||||
if (adjustPlacedNotes.Current.Value)
|
|
||||||
{
|
|
||||||
foreach (HitObject hitObject in hitObjectsInRange)
|
|
||||||
{
|
|
||||||
hitObject.StartTime += adjust;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!editorClock.IsRunning && wasAtStart)
|
if (!editorClock.IsRunning && wasAtStart)
|
||||||
editorClock.Seek(newOffset);
|
editorClock.Seek(newOffset);
|
||||||
|
|
||||||
foreach (HitObject hitObject in hitObjectsInRange)
|
beatmap.UpdateAllHitObjects();
|
||||||
beatmap.Update(hitObject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void adjustBpm(double adjust)
|
private void adjustBpm(double adjust)
|
||||||
{
|
{
|
||||||
var timing = selectedGroup.Value?.ControlPoints.OfType<TimingControlPoint>().FirstOrDefault();
|
var timing = selectedGroup.Value?.ControlPoints.OfType<TimingControlPoint>().FirstOrDefault();
|
||||||
@ -266,25 +251,12 @@ namespace osu.Game.Screens.Edit.Timing
|
|||||||
|
|
||||||
double newBeatLength = 60000 / (timing.BPM + adjust);
|
double newBeatLength = 60000 / (timing.BPM + adjust);
|
||||||
|
|
||||||
List<HitObject> hitObjectsInRange = hitObjectsInTimingRange(beatmap, selectedGroup.Value!);
|
|
||||||
|
|
||||||
if (adjustPlacedNotes.Current.Value)
|
if (adjustPlacedNotes.Current.Value)
|
||||||
{
|
timing.SetHitObjectBPM(beatmap, newBeatLength);
|
||||||
foreach (HitObject hitObject in hitObjectsInRange)
|
|
||||||
{
|
|
||||||
double beat = (hitObject.StartTime - selectedGroup.Value!.Time) / timing.BeatLength;
|
|
||||||
|
|
||||||
hitObject.StartTime = (beat * newBeatLength) + selectedGroup.Value.Time;
|
|
||||||
|
|
||||||
if (hitObject is not IHasRepeats && hitObject is IHasDuration hitObjectWithDuration)
|
|
||||||
hitObjectWithDuration.Duration *= newBeatLength / timing.BeatLength;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
timing.BeatLength = newBeatLength;
|
timing.BeatLength = newBeatLength;
|
||||||
|
|
||||||
foreach (HitObject hitObject in hitObjectsInRange)
|
beatmap.UpdateAllHitObjects();
|
||||||
beatmap.Update(hitObject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private partial class InlineButton : OsuButton
|
private partial class InlineButton : OsuButton
|
||||||
|
Loading…
Reference in New Issue
Block a user