2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-12-11 20:56:58 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2018-02-12 15:02:42 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-12-11 20:56:58 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-02-12 15:02:42 +08:00
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2017-12-11 20:56:58 +08:00
|
|
|
|
using osu.Framework.Input;
|
2018-02-12 15:02:42 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2017-12-11 20:56:58 +08:00
|
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Edit.Layers.Selection
|
|
|
|
|
{
|
|
|
|
|
public class SelectionLayer : CompositeDrawable
|
|
|
|
|
{
|
|
|
|
|
private readonly Playfield playfield;
|
|
|
|
|
|
|
|
|
|
public SelectionLayer(Playfield playfield)
|
|
|
|
|
{
|
|
|
|
|
this.playfield = playfield;
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-12 15:02:42 +08:00
|
|
|
|
private HitObjectSelectionBox selectionBox;
|
|
|
|
|
private HitObjectCapturer capturer;
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
capturer = new HitObjectCapturer(playfield.HitObjects.Objects);
|
|
|
|
|
capturer.HitObjectCaptured += hitObjectCaptured;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void hitObjectCaptured(DrawableHitObject hitObject) => selectionBox.AddCaptured(hitObject);
|
2017-12-11 20:56:58 +08:00
|
|
|
|
|
|
|
|
|
protected override bool OnDragStart(InputState state)
|
|
|
|
|
{
|
|
|
|
|
// Hide the previous drag box - we won't be working with it any longer
|
2018-02-12 15:02:42 +08:00
|
|
|
|
selectionBox?.Hide();
|
|
|
|
|
selectionBox?.Expire();
|
2017-12-15 13:48:24 +08:00
|
|
|
|
|
2018-02-12 15:02:42 +08:00
|
|
|
|
AddInternal(selectionBox = new HitObjectSelectionBox());
|
2017-12-15 13:48:24 +08:00
|
|
|
|
|
2017-12-11 20:56:58 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnDrag(InputState state)
|
|
|
|
|
{
|
2018-02-12 15:02:42 +08:00
|
|
|
|
var dragPosition = state.Mouse.NativeState.Position;
|
|
|
|
|
var dragStartPosition = state.Mouse.NativeState.PositionMouseDown ?? dragPosition;
|
|
|
|
|
|
|
|
|
|
var screenSpaceDragQuad = new Quad(dragStartPosition.X, dragStartPosition.Y, dragPosition.X - dragStartPosition.X, dragPosition.Y - dragStartPosition.Y);
|
|
|
|
|
|
|
|
|
|
selectionBox.SetDragRectangle(screenSpaceDragQuad.AABBFloat);
|
|
|
|
|
capturer.CaptureQuad(screenSpaceDragQuad);
|
|
|
|
|
|
2017-12-11 20:56:58 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnDragEnd(InputState state)
|
|
|
|
|
{
|
2018-02-12 15:02:42 +08:00
|
|
|
|
// Due to https://github.com/ppy/osu-framework/issues/1382, we may get here after OnClick has set the selectionBox to null
|
|
|
|
|
// In the case that the user dragged within the click distance out of an object
|
|
|
|
|
if (selectionBox == null)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
selectionBox.FinishCapture();
|
|
|
|
|
|
|
|
|
|
// If there are no hitobjects, remove the selection box
|
|
|
|
|
if (!selectionBox.HasCaptured)
|
|
|
|
|
{
|
|
|
|
|
selectionBox.Expire();
|
|
|
|
|
selectionBox = null;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-11 20:56:58 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(InputState state)
|
|
|
|
|
{
|
2018-02-12 15:02:42 +08:00
|
|
|
|
// We could be coming here without a previous selection box
|
|
|
|
|
if (selectionBox == null)
|
|
|
|
|
AddInternal(selectionBox = new HitObjectSelectionBox { Position = ToLocalSpace(state.Mouse.NativeState.Position), Alpha = 0 });
|
|
|
|
|
|
|
|
|
|
// If we're coming here with a previous selection, unselect those hitobjects
|
|
|
|
|
selectionBox.ClearCaptured();
|
|
|
|
|
if (capturer.CapturePoint(state.Mouse.NativeState.Position))
|
|
|
|
|
{
|
|
|
|
|
selectionBox.Alpha = 1;
|
|
|
|
|
selectionBox.FinishCapture(true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
selectionBox.Hide();
|
|
|
|
|
selectionBox = null;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-11 20:56:58 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|