mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 15:07:44 +08:00
Always re-sort blueprints before adding/removing one
This commit is contained in:
parent
ce70d1082d
commit
a86b9893ac
@ -1,8 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// 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 osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Rulesets.Edit;
|
using osu.Game.Rulesets.Edit;
|
||||||
@ -15,53 +14,28 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class HitObjectOrderedSelectionContainer : Container<SelectionBlueprint<HitObject>>
|
public sealed class HitObjectOrderedSelectionContainer : Container<SelectionBlueprint<HitObject>>
|
||||||
{
|
{
|
||||||
|
[Resolved]
|
||||||
|
private EditorBeatmap editorBeatmap { get; set; }
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
editorBeatmap.HitObjectUpdated += hitObjectUpdated;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void hitObjectUpdated(HitObject _) => SortInternal();
|
||||||
|
|
||||||
public override void Add(SelectionBlueprint<HitObject> drawable)
|
public override void Add(SelectionBlueprint<HitObject> drawable)
|
||||||
{
|
{
|
||||||
|
SortInternal();
|
||||||
base.Add(drawable);
|
base.Add(drawable);
|
||||||
bindStartTime(drawable);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Remove(SelectionBlueprint<HitObject> drawable)
|
public override bool Remove(SelectionBlueprint<HitObject> drawable)
|
||||||
{
|
{
|
||||||
if (!base.Remove(drawable))
|
SortInternal();
|
||||||
return false;
|
return base.Remove(drawable);
|
||||||
|
|
||||||
unbindStartTime(drawable);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Clear(bool disposeChildren)
|
|
||||||
{
|
|
||||||
base.Clear(disposeChildren);
|
|
||||||
unbindAllStartTimes();
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly Dictionary<SelectionBlueprint<HitObject>, IBindable> startTimeMap = new Dictionary<SelectionBlueprint<HitObject>, IBindable>();
|
|
||||||
|
|
||||||
private void bindStartTime(SelectionBlueprint<HitObject> blueprint)
|
|
||||||
{
|
|
||||||
var bindable = blueprint.Item.StartTimeBindable.GetBoundCopy();
|
|
||||||
|
|
||||||
bindable.BindValueChanged(_ =>
|
|
||||||
{
|
|
||||||
if (LoadState >= LoadState.Ready)
|
|
||||||
SortInternal();
|
|
||||||
});
|
|
||||||
|
|
||||||
startTimeMap[blueprint] = bindable;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void unbindStartTime(SelectionBlueprint<HitObject> blueprint)
|
|
||||||
{
|
|
||||||
startTimeMap[blueprint].UnbindAll();
|
|
||||||
startTimeMap.Remove(blueprint);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void unbindAllStartTimes()
|
|
||||||
{
|
|
||||||
foreach (var kvp in startTimeMap)
|
|
||||||
kvp.Value.UnbindAll();
|
|
||||||
startTimeMap.Clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override int Compare(Drawable x, Drawable y)
|
protected override int Compare(Drawable x, Drawable y)
|
||||||
@ -79,5 +53,13 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
|||||||
|
|
||||||
return i == 0 ? CompareReverseChildID(y, x) : i;
|
return i == 0 ? CompareReverseChildID(y, x) : i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Dispose(bool isDisposing)
|
||||||
|
{
|
||||||
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
|
if (editorBeatmap != null)
|
||||||
|
editorBeatmap.HitObjectUpdated -= hitObjectUpdated;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user