2023-06-23 00:37:25 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2020-11-17 21:56:21 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2021-09-26 21:48:56 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2023-06-23 23:59:36 +08:00
|
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2020-11-17 21:56:21 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Game.Rulesets.Edit;
|
2020-11-18 12:37:15 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2021-09-26 21:52:25 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2020-11-17 21:56:21 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components
|
|
|
|
|
{
|
2020-11-18 12:37:15 +08:00
|
|
|
|
/// <summary>
|
2021-04-27 14:40:35 +08:00
|
|
|
|
/// A container for <see cref="SelectionBlueprint{HitObject}"/> ordered by their <see cref="HitObject"/> start times.
|
2020-11-18 12:37:15 +08:00
|
|
|
|
/// </summary>
|
2024-10-21 20:44:53 +08:00
|
|
|
|
public sealed partial class HitObjectOrderedSelectionContainer : BlueprintContainer<HitObject>.SelectionBlueprintContainer
|
2020-11-17 21:56:21 +08:00
|
|
|
|
{
|
2021-09-26 21:48:56 +08:00
|
|
|
|
[Resolved]
|
2023-06-23 00:37:25 +08:00
|
|
|
|
private EditorBeatmap editorBeatmap { get; set; } = null!;
|
2020-11-17 21:56:21 +08:00
|
|
|
|
|
2021-09-26 21:48:56 +08:00
|
|
|
|
protected override void LoadComplete()
|
2020-11-17 21:56:21 +08:00
|
|
|
|
{
|
2021-09-26 21:48:56 +08:00
|
|
|
|
base.LoadComplete();
|
2020-11-17 21:56:21 +08:00
|
|
|
|
|
2022-09-13 13:59:30 +08:00
|
|
|
|
editorBeatmap.BeatmapReprocessed += SortInternal;
|
2020-11-17 21:56:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-26 21:48:56 +08:00
|
|
|
|
public override void Add(SelectionBlueprint<HitObject> drawable)
|
2020-11-17 21:56:21 +08:00
|
|
|
|
{
|
2024-10-21 20:44:53 +08:00
|
|
|
|
Sort();
|
2021-09-26 21:48:56 +08:00
|
|
|
|
base.Add(drawable);
|
2020-11-17 21:56:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-26 14:19:05 +08:00
|
|
|
|
public override bool Remove(SelectionBlueprint<HitObject> drawable, bool disposeImmediately)
|
2020-11-17 21:56:21 +08:00
|
|
|
|
{
|
2024-10-21 20:44:53 +08:00
|
|
|
|
Sort();
|
2022-08-26 14:19:05 +08:00
|
|
|
|
return base.Remove(drawable, disposeImmediately);
|
2020-11-17 21:56:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 20:44:53 +08:00
|
|
|
|
internal void Sort() => SortInternal();
|
|
|
|
|
|
2020-11-17 21:56:21 +08:00
|
|
|
|
protected override int Compare(Drawable x, Drawable y)
|
|
|
|
|
{
|
2021-09-27 13:24:17 +08:00
|
|
|
|
var xObj = ((SelectionBlueprint<HitObject>)x).Item;
|
|
|
|
|
var yObj = ((SelectionBlueprint<HitObject>)y).Item;
|
2020-11-17 21:56:21 +08:00
|
|
|
|
|
|
|
|
|
// Put earlier blueprints towards the end of the list, so they handle input first
|
2021-09-27 13:24:17 +08:00
|
|
|
|
int result = yObj.StartTime.CompareTo(xObj.StartTime);
|
|
|
|
|
if (result != 0) return result;
|
2021-03-26 15:33:16 +08:00
|
|
|
|
|
|
|
|
|
// Fall back to end time if the start time is equal.
|
2021-09-27 13:24:17 +08:00
|
|
|
|
result = yObj.GetEndTime().CompareTo(xObj.GetEndTime());
|
|
|
|
|
if (result != 0) return result;
|
2021-09-26 21:52:25 +08:00
|
|
|
|
|
|
|
|
|
// As a final fallback, use combo information if available.
|
2021-09-27 13:24:17 +08:00
|
|
|
|
if (xObj is IHasComboInformation xHasCombo && yObj is IHasComboInformation yHasCombo)
|
2021-09-26 21:52:25 +08:00
|
|
|
|
{
|
2021-09-27 13:24:17 +08:00
|
|
|
|
result = yHasCombo.ComboIndex.CompareTo(xHasCombo.ComboIndex);
|
|
|
|
|
if (result != 0) return result;
|
2021-09-26 21:52:25 +08:00
|
|
|
|
|
2021-09-27 13:24:17 +08:00
|
|
|
|
result = yHasCombo.IndexInCurrentCombo.CompareTo(xHasCombo.IndexInCurrentCombo);
|
|
|
|
|
if (result != 0) return result;
|
2021-09-26 21:52:25 +08:00
|
|
|
|
}
|
2021-03-26 15:33:16 +08:00
|
|
|
|
|
2022-08-29 14:23:53 +08:00
|
|
|
|
return CompareReverseChildID(x, y);
|
2020-11-17 21:56:21 +08:00
|
|
|
|
}
|
2021-09-26 21:48:56 +08:00
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
2023-06-23 23:59:36 +08:00
|
|
|
|
if (editorBeatmap.IsNotNull())
|
2022-09-13 13:59:30 +08:00
|
|
|
|
editorBeatmap.BeatmapReprocessed -= SortInternal;
|
2021-09-26 21:48:56 +08:00
|
|
|
|
}
|
2020-11-17 21:56:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|