mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 08:12:56 +08:00
Move delegate debounce logic to Editor
itself
This commit is contained in:
parent
ea50936d71
commit
8ce50e98a6
@ -24,6 +24,7 @@ using osu.Framework.Logging;
|
|||||||
using osu.Framework.Platform;
|
using osu.Framework.Platform;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
using osu.Framework.Testing;
|
using osu.Framework.Testing;
|
||||||
|
using osu.Framework.Threading;
|
||||||
using osu.Framework.Timing;
|
using osu.Framework.Timing;
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
@ -231,6 +232,8 @@ namespace osu.Game.Screens.Edit
|
|||||||
AddInternal(editorBeatmap = new EditorBeatmap(playableBeatmap, loadableBeatmap.GetSkin(), loadableBeatmap.BeatmapInfo));
|
AddInternal(editorBeatmap = new EditorBeatmap(playableBeatmap, loadableBeatmap.GetSkin(), loadableBeatmap.BeatmapInfo));
|
||||||
dependencies.CacheAs(editorBeatmap);
|
dependencies.CacheAs(editorBeatmap);
|
||||||
|
|
||||||
|
editorBeatmap.UpdateInProgress.BindValueChanged(updateInProgress);
|
||||||
|
|
||||||
canSave = editorBeatmap.BeatmapInfo.Ruleset.CreateInstance() is ILegacyRuleset;
|
canSave = editorBeatmap.BeatmapInfo.Ruleset.CreateInstance() is ILegacyRuleset;
|
||||||
|
|
||||||
if (canSave)
|
if (canSave)
|
||||||
@ -431,7 +434,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
|
|
||||||
samplePlaybackDisabled.Value = clock.SeekingOrStopped.Value
|
samplePlaybackDisabled.Value = clock.SeekingOrStopped.Value
|
||||||
|| currentScreen is not ComposeScreen
|
|| currentScreen is not ComposeScreen
|
||||||
|| editorBeatmap.UpdateInProgress;
|
|| temporaryMuteFromUpdateInProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool OnPressed(KeyBindingPressEvent<PlatformAction> e)
|
public bool OnPressed(KeyBindingPressEvent<PlatformAction> e)
|
||||||
@ -717,6 +720,22 @@ namespace osu.Game.Screens.Edit
|
|||||||
this.Exit();
|
this.Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Mute from update application
|
||||||
|
|
||||||
|
private ScheduledDelegate temporaryMuteRestorationDelegate;
|
||||||
|
private bool temporaryMuteFromUpdateInProgress;
|
||||||
|
|
||||||
|
private void updateInProgress(ValueChangedEvent<bool> obj)
|
||||||
|
{
|
||||||
|
temporaryMuteFromUpdateInProgress = true;
|
||||||
|
|
||||||
|
// Debounce is arbitrarily high enough to avoid flip-flopping the value each other frame.
|
||||||
|
temporaryMuteRestorationDelegate?.Cancel();
|
||||||
|
temporaryMuteRestorationDelegate = Scheduler.AddDelayed(() => temporaryMuteFromUpdateInProgress = false, 50);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Clipboard support
|
#region Clipboard support
|
||||||
|
|
||||||
private EditorMenuItem cutMenuItem;
|
private EditorMenuItem cutMenuItem;
|
||||||
|
@ -10,7 +10,6 @@ using System.Linq;
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Threading;
|
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.ControlPoints;
|
using osu.Game.Beatmaps.ControlPoints;
|
||||||
using osu.Game.Beatmaps.Legacy;
|
using osu.Game.Beatmaps.Legacy;
|
||||||
@ -24,13 +23,15 @@ namespace osu.Game.Screens.Edit
|
|||||||
public class EditorBeatmap : TransactionalCommitComponent, IBeatmap, IBeatSnapProvider
|
public class EditorBeatmap : TransactionalCommitComponent, IBeatmap, IBeatSnapProvider
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// While performing updates on hitobjects, this will momentarily become true.
|
/// Will become <c>true</c> when a new update is queued, and <c>false</c> when all updates have been applied.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// This is intended to be used to avoid performing operations (like playback of samples)
|
/// This is intended to be used to avoid performing operations (like playback of samples)
|
||||||
/// while mutating hitobjects.
|
/// while mutating hitobjects.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public bool UpdateInProgress { get; private set; }
|
public IBindable<bool> UpdateInProgress => updateInProgress;
|
||||||
|
|
||||||
|
private readonly BindableBool updateInProgress = new BindableBool();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked when a <see cref="HitObject"/> is added to this <see cref="EditorBeatmap"/>.
|
/// Invoked when a <see cref="HitObject"/> is added to this <see cref="EditorBeatmap"/>.
|
||||||
@ -236,11 +237,9 @@ namespace osu.Game.Screens.Edit
|
|||||||
// updates are debounced regardless of whether a batch is active.
|
// updates are debounced regardless of whether a batch is active.
|
||||||
batchPendingUpdates.Add(hitObject);
|
batchPendingUpdates.Add(hitObject);
|
||||||
|
|
||||||
advertiseUpdateInProgress();
|
updateInProgress.Value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ScheduledDelegate updateCompleteDelegate;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update all hit objects with potentially changed difficulty or control point data.
|
/// Update all hit objects with potentially changed difficulty or control point data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -249,7 +248,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
foreach (var h in HitObjects)
|
foreach (var h in HitObjects)
|
||||||
batchPendingUpdates.Add(h);
|
batchPendingUpdates.Add(h);
|
||||||
|
|
||||||
advertiseUpdateInProgress();
|
updateInProgress.Value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -342,6 +341,8 @@ namespace osu.Game.Screens.Edit
|
|||||||
foreach (var h in deletes) HitObjectRemoved?.Invoke(h);
|
foreach (var h in deletes) HitObjectRemoved?.Invoke(h);
|
||||||
foreach (var h in inserts) HitObjectAdded?.Invoke(h);
|
foreach (var h in inserts) HitObjectAdded?.Invoke(h);
|
||||||
foreach (var h in updates) HitObjectUpdated?.Invoke(h);
|
foreach (var h in updates) HitObjectUpdated?.Invoke(h);
|
||||||
|
|
||||||
|
updateInProgress.Value = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -349,15 +350,6 @@ namespace osu.Game.Screens.Edit
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Clear() => RemoveRange(HitObjects.ToArray());
|
public void Clear() => RemoveRange(HitObjects.ToArray());
|
||||||
|
|
||||||
private void advertiseUpdateInProgress()
|
|
||||||
{
|
|
||||||
UpdateInProgress = true;
|
|
||||||
|
|
||||||
// Debounce is arbitrarily high enough to avoid flip-flopping the value each other frame.
|
|
||||||
updateCompleteDelegate?.Cancel();
|
|
||||||
updateCompleteDelegate = Scheduler.AddDelayed(() => UpdateInProgress = false, 50);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processHitObject(HitObject hitObject) => hitObject.ApplyDefaults(ControlPointInfo, PlayableBeatmap.Difficulty);
|
private void processHitObject(HitObject hitObject) => hitObject.ApplyDefaults(ControlPointInfo, PlayableBeatmap.Difficulty);
|
||||||
|
|
||||||
private void trackStartTime(HitObject hitObject)
|
private void trackStartTime(HitObject hitObject)
|
||||||
|
Loading…
Reference in New Issue
Block a user