2020-11-17 21:56:21 +08:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Rulesets.Edit;
|
2020-11-18 12:37:15 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2020-11-17 21:56:21 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components
|
|
|
|
{
|
2020-11-18 12:37:15 +08:00
|
|
|
/// <summary>
|
|
|
|
/// A container for <see cref="SelectionBlueprint"/> ordered by their <see cref="HitObject"/> start times.
|
|
|
|
/// </summary>
|
2020-11-18 12:33:22 +08:00
|
|
|
public sealed class HitObjectOrderedSelectionContainer : Container<SelectionBlueprint>
|
2020-11-17 21:56:21 +08:00
|
|
|
{
|
|
|
|
public override void Add(SelectionBlueprint drawable)
|
|
|
|
{
|
|
|
|
base.Add(drawable);
|
2020-11-18 12:33:22 +08:00
|
|
|
bindStartTime(drawable);
|
2020-11-17 21:56:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override bool Remove(SelectionBlueprint drawable)
|
|
|
|
{
|
|
|
|
if (!base.Remove(drawable))
|
|
|
|
return false;
|
|
|
|
|
2020-11-18 12:33:22 +08:00
|
|
|
unbindStartTime(drawable);
|
2020-11-17 21:56:21 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Clear(bool disposeChildren)
|
|
|
|
{
|
|
|
|
base.Clear(disposeChildren);
|
|
|
|
unbindAllStartTimes();
|
|
|
|
}
|
|
|
|
|
|
|
|
private readonly Dictionary<SelectionBlueprint, IBindable> startTimeMap = new Dictionary<SelectionBlueprint, IBindable>();
|
|
|
|
|
|
|
|
private void bindStartTime(SelectionBlueprint blueprint)
|
|
|
|
{
|
|
|
|
var bindable = blueprint.HitObject.StartTimeBindable.GetBoundCopy();
|
|
|
|
|
|
|
|
bindable.BindValueChanged(_ =>
|
|
|
|
{
|
|
|
|
if (LoadState >= LoadState.Ready)
|
|
|
|
SortInternal();
|
|
|
|
});
|
|
|
|
|
|
|
|
startTimeMap[blueprint] = bindable;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void unbindStartTime(SelectionBlueprint 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)
|
|
|
|
{
|
2020-11-18 12:33:22 +08:00
|
|
|
var xObj = (SelectionBlueprint)x;
|
|
|
|
var yObj = (SelectionBlueprint)y;
|
2020-11-17 21:56:21 +08:00
|
|
|
|
|
|
|
// Put earlier blueprints towards the end of the list, so they handle input first
|
|
|
|
int i = yObj.HitObject.StartTime.CompareTo(xObj.HitObject.StartTime);
|
|
|
|
return i == 0 ? CompareReverseChildID(x, y) : i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|