mirror of
https://github.com/ppy/osu.git
synced 2025-02-20 05:03:20 +08:00
Pass HitObjectComposer to BlueprintContainer via ctor
This commit is contained in:
parent
8aaa500431
commit
4ef2e9548c
@ -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.Collections.Generic;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Mania.Edit.Blueprints;
|
||||
using osu.Game.Rulesets.Mania.Objects.Drawables;
|
||||
@ -12,8 +11,8 @@ namespace osu.Game.Rulesets.Mania.Edit
|
||||
{
|
||||
public class ManiaBlueprintContainer : ComposeBlueprintContainer
|
||||
{
|
||||
public ManiaBlueprintContainer(IEnumerable<DrawableHitObject> drawableHitObjects)
|
||||
: base(drawableHitObjects)
|
||||
public ManiaBlueprintContainer(HitObjectComposer composer)
|
||||
: base(composer)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@ using osu.Game.Rulesets.Mania.Objects.Drawables.Pieces;
|
||||
using osu.Game.Rulesets.Mania.UI;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Rulesets.UI.Scrolling;
|
||||
using osu.Game.Screens.Edit.Compose.Components;
|
||||
@ -89,8 +88,8 @@ namespace osu.Game.Rulesets.Mania.Edit
|
||||
return drawableRuleset;
|
||||
}
|
||||
|
||||
protected override ComposeBlueprintContainer CreateBlueprintContainer(IEnumerable<DrawableHitObject> hitObjects)
|
||||
=> new ManiaBlueprintContainer(hitObjects);
|
||||
protected override ComposeBlueprintContainer CreateBlueprintContainer()
|
||||
=> new ManiaBlueprintContainer(this);
|
||||
|
||||
protected override IReadOnlyList<HitObjectCompositionTool> CompositionTools => new HitObjectCompositionTool[]
|
||||
{
|
||||
|
@ -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.Collections.Generic;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles;
|
||||
@ -14,8 +13,8 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
{
|
||||
public class OsuBlueprintContainer : ComposeBlueprintContainer
|
||||
{
|
||||
public OsuBlueprintContainer(IEnumerable<DrawableHitObject> drawableHitObjects)
|
||||
: base(drawableHitObjects)
|
||||
public OsuBlueprintContainer(HitObjectComposer composer)
|
||||
: base(composer)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@ using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Edit.Tools;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Screens.Edit.Components.TernaryButtons;
|
||||
@ -80,8 +79,8 @@ namespace osu.Game.Rulesets.Osu.Edit
|
||||
updateDistanceSnapGrid();
|
||||
}
|
||||
|
||||
protected override ComposeBlueprintContainer CreateBlueprintContainer(IEnumerable<DrawableHitObject> hitObjects)
|
||||
=> new OsuBlueprintContainer(hitObjects);
|
||||
protected override ComposeBlueprintContainer CreateBlueprintContainer()
|
||||
=> new OsuBlueprintContainer(this);
|
||||
|
||||
private DistanceSnapGrid distanceSnapGrid;
|
||||
private Container distanceSnapGridContainer;
|
||||
|
@ -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.Collections.Generic;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.Taiko.Edit.Blueprints;
|
||||
@ -11,8 +10,8 @@ namespace osu.Game.Rulesets.Taiko.Edit
|
||||
{
|
||||
public class TaikoBlueprintContainer : ComposeBlueprintContainer
|
||||
{
|
||||
public TaikoBlueprintContainer(IEnumerable<DrawableHitObject> hitObjects)
|
||||
: base(hitObjects)
|
||||
public TaikoBlueprintContainer(HitObjectComposer composer)
|
||||
: base(composer)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Edit.Tools;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.Taiko.Objects;
|
||||
using osu.Game.Screens.Edit.Compose.Components;
|
||||
|
||||
@ -24,7 +23,7 @@ namespace osu.Game.Rulesets.Taiko.Edit
|
||||
new SwellCompositionTool()
|
||||
};
|
||||
|
||||
protected override ComposeBlueprintContainer CreateBlueprintContainer(IEnumerable<DrawableHitObject> hitObjects)
|
||||
=> new TaikoBlueprintContainer(hitObjects);
|
||||
protected override ComposeBlueprintContainer CreateBlueprintContainer()
|
||||
=> new TaikoBlueprintContainer(this);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
[TestFixture]
|
||||
public class TestSceneTimelineBlueprintContainer : TimelineTestScene
|
||||
{
|
||||
public override Drawable CreateTestComponent() => new TimelineBlueprintContainer();
|
||||
public override Drawable CreateTestComponent() => new TimelineBlueprintContainer(null);
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
|
@ -104,7 +104,7 @@ namespace osu.Game.Rulesets.Edit
|
||||
drawableRulesetWrapper,
|
||||
// layers above playfield
|
||||
drawableRulesetWrapper.CreatePlayfieldAdjustmentContainer()
|
||||
.WithChild(BlueprintContainer = CreateBlueprintContainer(HitObjects))
|
||||
.WithChild(BlueprintContainer = CreateBlueprintContainer())
|
||||
}
|
||||
},
|
||||
new FillFlowContainer
|
||||
@ -182,9 +182,8 @@ namespace osu.Game.Rulesets.Edit
|
||||
/// <summary>
|
||||
/// Construct a relevant blueprint container. This will manage hitobject selection/placement input handling and display logic.
|
||||
/// </summary>
|
||||
/// <param name="hitObjects">A live collection of all <see cref="DrawableHitObject"/>s in the editor beatmap.</param>
|
||||
protected virtual ComposeBlueprintContainer CreateBlueprintContainer(IEnumerable<DrawableHitObject> hitObjects)
|
||||
=> new ComposeBlueprintContainer(hitObjects);
|
||||
protected virtual ComposeBlueprintContainer CreateBlueprintContainer()
|
||||
=> new ComposeBlueprintContainer(this);
|
||||
|
||||
/// <summary>
|
||||
/// Construct a drawable ruleset for the provided ruleset.
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
@ -44,12 +45,16 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
protected EditorBeatmap Beatmap { get; private set; }
|
||||
|
||||
private readonly BindableList<HitObject> selectedHitObjects = new BindableList<HitObject>();
|
||||
private readonly HitObjectComposer composer;
|
||||
private readonly Dictionary<HitObject, SelectionBlueprint> blueprintMap = new Dictionary<HitObject, SelectionBlueprint>();
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private IPositionSnapProvider snapProvider { get; set; }
|
||||
|
||||
protected BlueprintContainer()
|
||||
protected BlueprintContainer(HitObjectComposer composer)
|
||||
{
|
||||
this.composer = composer;
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
}
|
||||
|
||||
@ -68,8 +73,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
DragBox.CreateProxy().With(p => p.Depth = float.MinValue)
|
||||
});
|
||||
|
||||
foreach (var obj in Beatmap.HitObjects)
|
||||
AddBlueprintFor(obj);
|
||||
// For non-pooled rulesets, hitobjects are already present in the playfield which allows the blueprints to be loaded in the async context.
|
||||
if (composer != null)
|
||||
{
|
||||
foreach (var obj in composer.HitObjects)
|
||||
addBlueprintFor(obj.HitObject);
|
||||
}
|
||||
|
||||
selectedHitObjects.BindTo(Beatmap.SelectedHitObjects);
|
||||
selectedHitObjects.CollectionChanged += (selectedObjects, args) =>
|
||||
@ -94,7 +103,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Beatmap.HitObjectAdded += AddBlueprintFor;
|
||||
Beatmap.HitObjectAdded += addBlueprintFor;
|
||||
Beatmap.HitObjectRemoved += removeBlueprintFor;
|
||||
}
|
||||
|
||||
@ -247,29 +256,17 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
|
||||
#region Blueprint Addition/Removal
|
||||
|
||||
private void removeBlueprintFor(HitObject hitObject)
|
||||
private void addBlueprintFor(HitObject hitObject)
|
||||
{
|
||||
var blueprint = SelectionBlueprints.SingleOrDefault(m => m.HitObject == hitObject);
|
||||
if (blueprint == null)
|
||||
if (blueprintMap.ContainsKey(hitObject))
|
||||
return;
|
||||
|
||||
blueprint.Deselect();
|
||||
|
||||
blueprint.Selected -= onBlueprintSelected;
|
||||
blueprint.Deselected -= onBlueprintDeselected;
|
||||
|
||||
SelectionBlueprints.Remove(blueprint);
|
||||
|
||||
if (movementBlueprint == blueprint)
|
||||
finishSelectionMovement();
|
||||
}
|
||||
|
||||
protected virtual void AddBlueprintFor(HitObject hitObject)
|
||||
{
|
||||
var blueprint = CreateBlueprintFor(hitObject);
|
||||
if (blueprint == null)
|
||||
return;
|
||||
|
||||
blueprintMap[hitObject] = blueprint;
|
||||
|
||||
blueprint.Selected += onBlueprintSelected;
|
||||
blueprint.Deselected += onBlueprintDeselected;
|
||||
|
||||
@ -277,6 +274,41 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
blueprint.Select();
|
||||
|
||||
SelectionBlueprints.Add(blueprint);
|
||||
|
||||
OnBlueprintAdded(hitObject);
|
||||
}
|
||||
|
||||
private void removeBlueprintFor(HitObject hitObject)
|
||||
{
|
||||
if (!blueprintMap.Remove(hitObject, out var blueprint))
|
||||
return;
|
||||
|
||||
blueprint.Deselect();
|
||||
blueprint.Selected -= onBlueprintSelected;
|
||||
blueprint.Deselected -= onBlueprintDeselected;
|
||||
|
||||
SelectionBlueprints.Remove(blueprint);
|
||||
|
||||
if (movementBlueprint == blueprint)
|
||||
finishSelectionMovement();
|
||||
|
||||
OnBlueprintRemoved(hitObject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called after a <see cref="HitObject"/> blueprint has been added.
|
||||
/// </summary>
|
||||
/// <param name="hitObject">The <see cref="HitObject"/> for which the blueprint has been added.</param>
|
||||
protected virtual void OnBlueprintAdded(HitObject hitObject)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called after a <see cref="HitObject"/> blueprint has been removed.
|
||||
/// </summary>
|
||||
/// <param name="hitObject">The <see cref="HitObject"/> for which the blueprint has been removed.</param>
|
||||
protected virtual void OnBlueprintRemoved(HitObject hitObject)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -456,7 +488,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
|
||||
if (Beatmap != null)
|
||||
{
|
||||
Beatmap.HitObjectAdded -= AddBlueprintFor;
|
||||
Beatmap.HitObjectAdded -= addBlueprintFor;
|
||||
Beatmap.HitObjectRemoved -= removeBlueprintFor;
|
||||
}
|
||||
}
|
||||
|
@ -27,22 +27,18 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
/// </summary>
|
||||
public class ComposeBlueprintContainer : BlueprintContainer
|
||||
{
|
||||
[Resolved]
|
||||
private HitObjectComposer composer { get; set; }
|
||||
|
||||
private PlacementBlueprint currentPlacement;
|
||||
|
||||
private readonly Container<PlacementBlueprint> placementBlueprintContainer;
|
||||
|
||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
|
||||
|
||||
private readonly HitObjectComposer composer;
|
||||
private readonly Container<PlacementBlueprint> placementBlueprintContainer;
|
||||
|
||||
private PlacementBlueprint currentPlacement;
|
||||
private InputManager inputManager;
|
||||
|
||||
private readonly IEnumerable<DrawableHitObject> drawableHitObjects;
|
||||
|
||||
public ComposeBlueprintContainer(IEnumerable<DrawableHitObject> drawableHitObjects)
|
||||
public ComposeBlueprintContainer(HitObjectComposer composer)
|
||||
: base(composer)
|
||||
{
|
||||
this.drawableHitObjects = drawableHitObjects;
|
||||
this.composer = composer;
|
||||
|
||||
placementBlueprintContainer = new Container<PlacementBlueprint>
|
||||
{
|
||||
@ -186,7 +182,7 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
|
||||
protected sealed override SelectionBlueprint CreateBlueprintFor(HitObject hitObject)
|
||||
{
|
||||
var drawable = drawableHitObjects.FirstOrDefault(d => d.HitObject == hitObject);
|
||||
var drawable = composer.HitObjects.FirstOrDefault(d => d.HitObject == hitObject);
|
||||
|
||||
if (drawable == null)
|
||||
return null;
|
||||
@ -196,11 +192,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
|
||||
public virtual OverlaySelectionBlueprint CreateBlueprintFor(DrawableHitObject hitObject) => null;
|
||||
|
||||
protected override void AddBlueprintFor(HitObject hitObject)
|
||||
protected override void OnBlueprintAdded(HitObject hitObject)
|
||||
{
|
||||
refreshTool();
|
||||
base.OnBlueprintAdded(hitObject);
|
||||
|
||||
base.AddBlueprintFor(hitObject);
|
||||
refreshTool();
|
||||
|
||||
// on successful placement, the new combo button should be reset as this is the most common user interaction.
|
||||
if (Beatmap.SelectedHitObjects.Count == 0)
|
||||
|
@ -31,7 +31,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
|
||||
private SelectionBlueprint placementBlueprint;
|
||||
|
||||
public TimelineBlueprintContainer()
|
||||
public TimelineBlueprintContainer(HitObjectComposer composer)
|
||||
: base(composer)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
Anchor = Anchor.Centre;
|
||||
|
@ -53,6 +53,6 @@ namespace osu.Game.Screens.Edit.Compose
|
||||
return beatmapSkinProvider.WithChild(rulesetSkinProvider.WithChild(composer));
|
||||
}
|
||||
|
||||
protected override Drawable CreateTimelineContent() => composer == null ? base.CreateTimelineContent() : new TimelineBlueprintContainer();
|
||||
protected override Drawable CreateTimelineContent() => composer == null ? base.CreateTimelineContent() : new TimelineBlueprintContainer(composer);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user