mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 12:17:26 +08:00
Add pooling support to the editor
This commit is contained in:
parent
4ef2e9548c
commit
3957697c48
@ -1,7 +1,6 @@
|
||||
// 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.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -65,17 +64,13 @@ namespace osu.Game.Rulesets.Edit
|
||||
|
||||
private void addHitObject(HitObject hitObject)
|
||||
{
|
||||
var drawableObject = drawableRuleset.CreateDrawableRepresentation((TObject)hitObject);
|
||||
|
||||
drawableRuleset.Playfield.Add(drawableObject);
|
||||
drawableRuleset.AddHitObject((TObject)hitObject);
|
||||
drawableRuleset.Playfield.PostProcess();
|
||||
}
|
||||
|
||||
private void removeHitObject(HitObject hitObject)
|
||||
{
|
||||
var drawableObject = Playfield.AllHitObjects.Single(d => d.HitObject == hitObject);
|
||||
|
||||
drawableRuleset.Playfield.Remove(drawableObject);
|
||||
drawableRuleset.RemoveHitObject((TObject)hitObject);
|
||||
drawableRuleset.Playfield.PostProcess();
|
||||
}
|
||||
|
||||
|
@ -105,6 +105,16 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
|
||||
Beatmap.HitObjectAdded += addBlueprintFor;
|
||||
Beatmap.HitObjectRemoved += removeBlueprintFor;
|
||||
|
||||
if (composer != null)
|
||||
{
|
||||
// For pooled rulesets, blueprints must be added for hitobjects already "current" as they would've not been "current" during the async load addition process above.
|
||||
foreach (var obj in composer.HitObjects)
|
||||
addBlueprintFor(obj.HitObject);
|
||||
|
||||
composer.Playfield.HitObjectUsageBegan += addBlueprintFor;
|
||||
composer.Playfield.HitObjectUsageFinished += removeBlueprintFor;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual Container<SelectionBlueprint> CreateSelectionBlueprintContainer() =>
|
||||
@ -381,7 +391,13 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
/// <summary>
|
||||
/// Selects all <see cref="SelectionBlueprint"/>s.
|
||||
/// </summary>
|
||||
private void selectAll() => SelectionBlueprints.ToList().ForEach(m => m.Select());
|
||||
private void selectAll()
|
||||
{
|
||||
composer.Playfield.KeepAllAlive();
|
||||
|
||||
// Scheduled to allow the change in lifetime to take place.
|
||||
Schedule(() => SelectionBlueprints.ToList().ForEach(m => m.Select()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deselects all selected <see cref="SelectionBlueprint"/>s.
|
||||
@ -392,12 +408,16 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
{
|
||||
SelectionHandler.HandleSelected(blueprint);
|
||||
SelectionBlueprints.ChangeChildDepth(blueprint, 1);
|
||||
|
||||
composer.Playfield.SetKeepAlive(blueprint.HitObject, true);
|
||||
}
|
||||
|
||||
private void onBlueprintDeselected(SelectionBlueprint blueprint)
|
||||
{
|
||||
SelectionHandler.HandleDeselected(blueprint);
|
||||
SelectionBlueprints.ChangeChildDepth(blueprint, 0);
|
||||
|
||||
composer.Playfield.SetKeepAlive(blueprint.HitObject, false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -491,6 +511,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
Beatmap.HitObjectAdded -= addBlueprintFor;
|
||||
Beatmap.HitObjectRemoved -= removeBlueprintFor;
|
||||
}
|
||||
|
||||
if (composer != null)
|
||||
{
|
||||
composer.Playfield.HitObjectUsageBegan -= addBlueprintFor;
|
||||
composer.Playfield.HitObjectUsageFinished -= removeBlueprintFor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user