mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:17:23 +08:00
Cleanup handling of hitobject updates
This commit is contained in:
parent
4bfc738f5b
commit
ee6ea08cf8
@ -15,6 +15,7 @@ using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
||||
using osu.Game.Screens.Edit;
|
||||
using osu.Game.Screens.Edit.Compose;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
@ -34,6 +35,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
|
||||
[Resolved(CanBeNull = true)]
|
||||
private IPlacementHandler placementHandler { get; set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private EditorBeatmap editorBeatmap { get; set; }
|
||||
|
||||
public SliderSelectionBlueprint(DrawableSlider slider)
|
||||
: base(slider)
|
||||
{
|
||||
@ -162,7 +166,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
|
||||
private void updatePath()
|
||||
{
|
||||
HitObject.Path.ExpectedDistance.Value = composer?.GetSnappedDistanceFromDistance(HitObject.StartTime, (float)HitObject.Path.CalculatedDistance) ?? (float)HitObject.Path.CalculatedDistance;
|
||||
UpdateHitObject();
|
||||
editorBeatmap?.UpdateHitObject(HitObject);
|
||||
}
|
||||
|
||||
public override MenuItem[] ContextMenuItems => new MenuItem[]
|
||||
|
@ -58,7 +58,7 @@ namespace osu.Game.Tests.Beatmaps
|
||||
var editorBeatmap = new EditorBeatmap(new OsuBeatmap { HitObjects = { hitCircle } });
|
||||
|
||||
HitObject changedObject = null;
|
||||
editorBeatmap.StartTimeChanged += h => changedObject = h;
|
||||
editorBeatmap.HitObjectUpdated += h => changedObject = h;
|
||||
|
||||
hitCircle.StartTime = 1000;
|
||||
Assert.That(changedObject, Is.EqualTo(hitCircle));
|
||||
@ -74,7 +74,7 @@ namespace osu.Game.Tests.Beatmaps
|
||||
var editorBeatmap = new EditorBeatmap(new OsuBeatmap());
|
||||
|
||||
HitObject changedObject = null;
|
||||
editorBeatmap.StartTimeChanged += h => changedObject = h;
|
||||
editorBeatmap.HitObjectUpdated += h => changedObject = h;
|
||||
|
||||
var hitCircle = new HitCircle();
|
||||
|
||||
@ -95,7 +95,7 @@ namespace osu.Game.Tests.Beatmaps
|
||||
var editorBeatmap = new EditorBeatmap(new OsuBeatmap { HitObjects = { hitCircle } });
|
||||
|
||||
HitObject changedObject = null;
|
||||
editorBeatmap.StartTimeChanged += h => changedObject = h;
|
||||
editorBeatmap.HitObjectUpdated += h => changedObject = h;
|
||||
|
||||
editorBeatmap.Remove(hitCircle);
|
||||
Assert.That(changedObject, Is.Null);
|
||||
|
@ -69,10 +69,6 @@ namespace osu.Game.Rulesets.Edit
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(IFrameBasedClock framedClock)
|
||||
{
|
||||
EditorBeatmap.HitObjectAdded += addHitObject;
|
||||
EditorBeatmap.HitObjectRemoved += removeHitObject;
|
||||
EditorBeatmap.StartTimeChanged += UpdateHitObject;
|
||||
|
||||
Config = Dependencies.Get<RulesetConfigCache>().GetConfigFor(Ruleset);
|
||||
|
||||
try
|
||||
@ -236,10 +232,6 @@ namespace osu.Game.Rulesets.Edit
|
||||
lastGridUpdateTime = EditorClock.CurrentTime;
|
||||
}
|
||||
|
||||
private void addHitObject(HitObject hitObject) => UpdateHitObject(hitObject);
|
||||
|
||||
private void removeHitObject(HitObject hitObject) => UpdateHitObject(null);
|
||||
|
||||
public override IEnumerable<DrawableHitObject> HitObjects => drawableRulesetWrapper.Playfield.AllHitObjects;
|
||||
public override bool CursorInPlacementArea => drawableRulesetWrapper.Playfield.ReceivePositionalInputAt(inputManager.CurrentState.Mouse.Position);
|
||||
|
||||
@ -302,19 +294,6 @@ namespace osu.Game.Rulesets.Edit
|
||||
|
||||
return DurationToDistance(referenceTime, snappedEndTime - referenceTime);
|
||||
}
|
||||
|
||||
public override void UpdateHitObject(HitObject hitObject) => EditorBeatmap.UpdateHitObject(hitObject);
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (EditorBeatmap != null)
|
||||
{
|
||||
EditorBeatmap.HitObjectAdded -= addHitObject;
|
||||
EditorBeatmap.HitObjectRemoved -= removeHitObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Cached(typeof(HitObjectComposer))]
|
||||
@ -344,12 +323,6 @@ namespace osu.Game.Rulesets.Edit
|
||||
[CanBeNull]
|
||||
protected virtual DistanceSnapGrid CreateDistanceSnapGrid([NotNull] IEnumerable<HitObject> selectedHitObjects) => null;
|
||||
|
||||
/// <summary>
|
||||
/// Updates a <see cref="HitObject"/>, invoking <see cref="HitObject.ApplyDefaults"/> and re-processing the beatmap.
|
||||
/// </summary>
|
||||
/// <param name="hitObject">The <see cref="HitObject"/> to update.</param>
|
||||
public abstract void UpdateHitObject([CanBeNull] HitObject hitObject);
|
||||
|
||||
public abstract (Vector2 position, double time) GetSnappedPosition(Vector2 position, double time);
|
||||
|
||||
public abstract float GetBeatSnapDistanceAt(double referenceTime);
|
||||
|
@ -108,11 +108,6 @@ namespace osu.Game.Rulesets.Edit
|
||||
|
||||
public bool IsSelected => State == SelectionState.Selected;
|
||||
|
||||
/// <summary>
|
||||
/// Updates the <see cref="Objects.HitObject"/>, invoking <see cref="Objects.HitObject.ApplyDefaults"/> and re-processing the beatmap.
|
||||
/// </summary>
|
||||
protected void UpdateHitObject() => composer?.UpdateHitObject(HitObject);
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="MenuItem"/>s to be displayed in the context menu for this <see cref="OverlaySelectionBlueprint"/>.
|
||||
/// </summary>
|
||||
|
@ -4,6 +4,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
@ -29,9 +30,9 @@ namespace osu.Game.Screens.Edit
|
||||
public event Action<HitObject> HitObjectRemoved;
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when the start time of a <see cref="HitObject"/> in this <see cref="EditorBeatmap"/> was changed.
|
||||
/// Invoked when a <see cref="HitObject"/> is updated.
|
||||
/// </summary>
|
||||
public event Action<HitObject> StartTimeChanged;
|
||||
public event Action<HitObject> HitObjectUpdated;
|
||||
|
||||
/// <summary>
|
||||
/// All currently selected <see cref="HitObject"/>s.
|
||||
@ -68,7 +69,9 @@ namespace osu.Game.Screens.Edit
|
||||
/// Updates a <see cref="HitObject"/>, invoking <see cref="HitObject.ApplyDefaults"/> and re-processing the beatmap.
|
||||
/// </summary>
|
||||
/// <param name="hitObject">The <see cref="HitObject"/> to update.</param>
|
||||
public void UpdateHitObject(HitObject hitObject)
|
||||
public void UpdateHitObject([NotNull] HitObject hitObject) => updateHitObject(hitObject, false);
|
||||
|
||||
private void updateHitObject([CanBeNull] HitObject hitObject, bool silent)
|
||||
{
|
||||
scheduledUpdate?.Cancel();
|
||||
scheduledUpdate = Scheduler.AddDelayed(() =>
|
||||
@ -76,6 +79,9 @@ namespace osu.Game.Screens.Edit
|
||||
beatmapProcessor?.PreProcess();
|
||||
hitObject?.ApplyDefaults(ControlPointInfo, BeatmapInfo.BaseDifficulty);
|
||||
beatmapProcessor?.PostProcess();
|
||||
|
||||
if (!silent)
|
||||
HitObjectUpdated?.Invoke(hitObject);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@ -114,6 +120,8 @@ namespace osu.Game.Screens.Edit
|
||||
mutableHitObjects.Insert(insertionIndex + 1, hitObject);
|
||||
|
||||
HitObjectAdded?.Invoke(hitObject);
|
||||
|
||||
updateHitObject(hitObject, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -132,6 +140,8 @@ namespace osu.Game.Screens.Edit
|
||||
|
||||
startTimeBindables.Remove(hitObject);
|
||||
HitObjectRemoved?.Invoke(hitObject);
|
||||
|
||||
updateHitObject(null, true);
|
||||
}
|
||||
|
||||
private void trackStartTime(HitObject hitObject)
|
||||
@ -145,7 +155,7 @@ namespace osu.Game.Screens.Edit
|
||||
var insertionIndex = findInsertionIndex(PlayableBeatmap.HitObjects, hitObject.StartTime);
|
||||
mutableHitObjects.Insert(insertionIndex + 1, hitObject);
|
||||
|
||||
StartTimeChanged?.Invoke(hitObject);
|
||||
UpdateHitObject(hitObject);
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user