Add blueprint transferral

This commit is contained in:
smoogipoo 2021-05-13 21:16:19 +09:00
parent 86042e1763
commit aaf31af326
4 changed files with 40 additions and 21 deletions

View File

@ -276,6 +276,13 @@ namespace osu.Game.Screens.Edit.Compose.Components
{
}
/// <summary>
/// Retrieves an item's blueprint.
/// </summary>
/// <param name="item">The item to retrieve the blueprint of.</param>
/// <returns>The blueprint.</returns>
protected SelectionBlueprint<T> GetBlueprintFor(T item) => blueprintMap[item];
#endregion
#region Selection

View File

@ -16,6 +16,7 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Tools;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Screens.Edit.Components.TernaryButtons;
using osuTK;
@ -73,6 +74,14 @@ namespace osu.Game.Screens.Edit.Compose.Components
}
}
protected override void TransferBlueprintFor(HitObject hitObject, DrawableHitObject drawableObject)
{
base.TransferBlueprintFor(hitObject, drawableObject);
var blueprint = (HitObjectSelectionBlueprint)GetBlueprintFor(hitObject);
blueprint.DrawableObject = drawableObject;
}
protected override bool OnKeyDown(KeyDownEvent e)
{
if (e.ControlPressed)

View File

@ -11,6 +11,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
namespace osu.Game.Screens.Edit.Compose.Components
{
@ -65,8 +66,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
foreach (var obj in Composer.HitObjects)
AddBlueprintFor(obj.HitObject);
Composer.Playfield.HitObjectUsageBegan += AddBlueprintFor;
Composer.Playfield.HitObjectUsageFinished += RemoveBlueprintFor;
var eventQueue = new HitObjectContainerEventQueue(Composer.Playfield);
eventQueue.HitObjectUsageBegan += AddBlueprintFor;
eventQueue.HitObjectUsageFinished += RemoveBlueprintFor;
eventQueue.HitObjectUsageTransferred += TransferBlueprintFor;
AddInternal(eventQueue);
}
}
@ -100,6 +104,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
base.AddBlueprintFor(item);
}
protected virtual void TransferBlueprintFor(HitObject hitObject, DrawableHitObject drawableObject)
{
}
protected override void DragOperationCompleted()
{
base.DragOperationCompleted();
@ -152,12 +160,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
Beatmap.HitObjectAdded -= AddBlueprintFor;
Beatmap.HitObjectRemoved -= RemoveBlueprintFor;
}
if (Composer != null)
{
Composer.Playfield.HitObjectUsageBegan -= AddBlueprintFor;
Composer.Playfield.HitObjectUsageFinished -= RemoveBlueprintFor;
}
}
}
}

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
@ -23,7 +24,7 @@ namespace osu.Game.Screens.Edit.Compose
/// <remarks>
/// If the ruleset uses pooled objects, this represents the time when the <see cref="HitObject"/>s become alive.
/// </remarks>
public event Action<HitObject, DrawableHitObject> HitObjectUsageBegan;
public event Action<HitObject> HitObjectUsageBegan;
/// <summary>
/// Invoked when a <see cref="HitObject"/> becomes unused by a <see cref="DrawableHitObject"/>.
@ -44,20 +45,12 @@ namespace osu.Game.Screens.Edit.Compose
/// Creates a new <see cref="HitObjectContainerEventQueue"/>.
/// </summary>
/// <param name="playfield">The most top-level <see cref="Playfield"/>.</param>
public HitObjectContainerEventQueue(Playfield playfield)
public HitObjectContainerEventQueue([NotNull] Playfield playfield)
{
this.playfield = playfield;
bindPlayfieldRecursive(playfield);
}
private void bindPlayfieldRecursive(Playfield p)
{
p.HitObjectContainer.HitObjectUsageBegan += onHitObjectUsageBegan;
p.HitObjectContainer.HitObjectUsageFinished += onHitObjectUsageFinished;
foreach (var nested in p.NestedPlayfields)
bindPlayfieldRecursive(nested);
playfield.HitObjectUsageBegan += onHitObjectUsageBegan;
playfield.HitObjectUsageFinished += onHitObjectUsageFinished;
}
private readonly Dictionary<HitObject, int> pendingUsagesBegan = new Dictionary<HitObject, int>();
@ -87,7 +80,7 @@ namespace osu.Game.Screens.Edit.Compose
else
{
// This is a new usage of the hitobject.
HitObjectUsageBegan?.Invoke(hitObject, playfield.AllHitObjects.Single(d => d.HitObject == hitObject));
HitObjectUsageBegan?.Invoke(hitObject);
}
}
@ -98,5 +91,13 @@ namespace osu.Game.Screens.Edit.Compose
pendingUsagesBegan.Clear();
pendingUsagesFinished.Clear();
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
playfield.HitObjectUsageBegan -= onHitObjectUsageBegan;
playfield.HitObjectUsageFinished -= onHitObjectUsageFinished;
}
}
}