Expose selection changed event from BlueprintContainer

This commit is contained in:
smoogipoo
2019-10-16 20:07:11 +09:00
parent 5ccdd2b203
commit bc76a9cb8c
2 changed files with 12 additions and 8 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -19,15 +20,14 @@ namespace osu.Game.Screens.Edit.Compose.Components
{ {
public class BlueprintContainer : CompositeDrawable public class BlueprintContainer : CompositeDrawable
{ {
private SelectionBlueprintContainer selectionBlueprints; public event Action<IEnumerable<HitObject>> SelectionChanged;
private SelectionBlueprintContainer selectionBlueprints;
private Container<PlacementBlueprint> placementBlueprintContainer; private Container<PlacementBlueprint> placementBlueprintContainer;
private PlacementBlueprint currentPlacement; private PlacementBlueprint currentPlacement;
private SelectionHandler selectionHandler; private SelectionHandler selectionHandler;
private InputManager inputManager; private InputManager inputManager;
private IEnumerable<SelectionBlueprint> selections => selectionBlueprints.Children.Where(c => c.IsAlive);
[Resolved] [Resolved]
private HitObjectComposer composer { get; set; } private HitObjectComposer composer { get; set; }
@ -196,9 +196,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <param name="rect">The rectangle to perform a selection on in screen-space coordinates.</param> /// <param name="rect">The rectangle to perform a selection on in screen-space coordinates.</param>
private void select(RectangleF rect) private void select(RectangleF rect)
{ {
foreach (var blueprint in selections.ToList()) foreach (var blueprint in selectionBlueprints)
{ {
if (blueprint.IsPresent && rect.Contains(blueprint.SelectionPoint)) if (blueprint.IsAlive && blueprint.IsPresent && rect.Contains(blueprint.SelectionPoint))
blueprint.Select(); blueprint.Select();
else else
blueprint.Deselect(); blueprint.Deselect();
@ -208,18 +208,22 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <summary> /// <summary>
/// Deselects all selected <see cref="SelectionBlueprint"/>s. /// Deselects all selected <see cref="SelectionBlueprint"/>s.
/// </summary> /// </summary>
private void deselectAll() => selections.ToList().ForEach(m => m.Deselect()); private void deselectAll() => selectionHandler.SelectedBlueprints.ToList().ForEach(m => m.Deselect());
private void onBlueprintSelected(SelectionBlueprint blueprint) private void onBlueprintSelected(SelectionBlueprint blueprint)
{ {
selectionHandler.HandleSelected(blueprint); selectionHandler.HandleSelected(blueprint);
selectionBlueprints.ChangeChildDepth(blueprint, 1); selectionBlueprints.ChangeChildDepth(blueprint, 1);
SelectionChanged?.Invoke(selectionHandler.SelectedHitObjects);
} }
private void onBlueprintDeselected(SelectionBlueprint blueprint) private void onBlueprintDeselected(SelectionBlueprint blueprint)
{ {
selectionHandler.HandleDeselected(blueprint); selectionHandler.HandleDeselected(blueprint);
selectionBlueprints.ChangeChildDepth(blueprint, 0); selectionBlueprints.ChangeChildDepth(blueprint, 0);
SelectionChanged?.Invoke(selectionHandler.SelectedHitObjects);
} }
private void onSelectionRequested(SelectionBlueprint blueprint, InputState state) => selectionHandler.HandleSelectionRequested(blueprint, state); private void onSelectionRequested(SelectionBlueprint blueprint, InputState state) => selectionHandler.HandleSelectionRequested(blueprint, state);

View File

@ -26,10 +26,10 @@ namespace osu.Game.Screens.Edit.Compose.Components
{ {
public const float BORDER_RADIUS = 2; public const float BORDER_RADIUS = 2;
protected IEnumerable<SelectionBlueprint> SelectedBlueprints => selectedBlueprints; public IEnumerable<SelectionBlueprint> SelectedBlueprints => selectedBlueprints;
private readonly List<SelectionBlueprint> selectedBlueprints; private readonly List<SelectionBlueprint> selectedBlueprints;
protected IEnumerable<HitObject> SelectedHitObjects => selectedBlueprints.Select(b => b.HitObject.HitObject); public IEnumerable<HitObject> SelectedHitObjects => selectedBlueprints.Select(b => b.HitObject.HitObject);
private Drawable outline; private Drawable outline;