1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00

Move selection events to BlueprintContainer

This commit is contained in:
smoogipoo 2019-10-24 14:58:02 +09:00
parent 714c89faa4
commit e04c77178c
2 changed files with 19 additions and 37 deletions

View File

@ -6,8 +6,6 @@ using osu.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Input.Events;
using osu.Framework.Input.States;
using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets.Objects.Drawables;
using osuTK;
@ -29,12 +27,6 @@ namespace osu.Game.Rulesets.Edit
/// </summary>
public event Action<SelectionBlueprint> Deselected;
/// <summary>
/// Invoked when this <see cref="SelectionBlueprint"/> has requested selection.
/// Will fire even if already selected. Does not actually perform selection.
/// </summary>
public event Action<SelectionBlueprint, InputState> SelectionRequested;
/// <summary>
/// The <see cref="DrawableHitObject"/> which this <see cref="SelectionBlueprint"/> applies to.
/// </summary>
@ -99,33 +91,6 @@ namespace osu.Game.Rulesets.Edit
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => DrawableObject.ReceivePositionalInputAt(screenSpacePos);
private bool selectionRequested;
protected override bool OnMouseDown(MouseDownEvent e)
{
selectionRequested = false;
if (State == SelectionState.NotSelected)
{
SelectionRequested?.Invoke(this, e.CurrentState);
selectionRequested = true;
}
return IsSelected;
}
protected override bool OnClick(ClickEvent e)
{
if (State == SelectionState.Selected && !selectionRequested)
{
selectionRequested = true;
SelectionRequested?.Invoke(this, e.CurrentState);
return true;
}
return base.OnClick(e);
}
/// <summary>
/// The screen-space point that causes this <see cref="SelectionBlueprint"/> to be selected.
/// </summary>

View File

@ -109,7 +109,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
blueprint.Selected -= onBlueprintSelected;
blueprint.Deselected -= onBlueprintDeselected;
blueprint.SelectionRequested -= onSelectionRequested;
selectionBlueprints.Remove(blueprint);
}
@ -124,15 +123,31 @@ namespace osu.Game.Screens.Edit.Compose.Components
blueprint.Selected += onBlueprintSelected;
blueprint.Deselected += onBlueprintDeselected;
blueprint.SelectionRequested += onSelectionRequested;
selectionBlueprints.Add(blueprint);
}
private void removeBlueprintFor(DrawableHitObject hitObject) => removeBlueprintFor(hitObject.HitObject);
protected override bool OnMouseDown(MouseDownEvent e)
{
foreach (SelectionBlueprint blueprint in selectionBlueprints.AliveBlueprints)
{
if (blueprint.IsHovered)
{
selectionHandler.HandleSelectionRequested(blueprint, e.CurrentState);
break;
}
}
return true;
}
protected override bool OnClick(ClickEvent e)
{
if (selectionBlueprints.AliveBlueprints.Any(b => b.IsHovered))
return true;
deselectAll();
return true;
}
@ -298,6 +313,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
private class SelectionBlueprintContainer : Container<SelectionBlueprint>
{
public IEnumerable<SelectionBlueprint> AliveBlueprints => AliveInternalChildren.Cast<SelectionBlueprint>();
protected override int Compare(Drawable x, Drawable y)
{
if (!(x is SelectionBlueprint xBlueprint) || !(y is SelectionBlueprint yBlueprint))