mirror of
https://github.com/osukey/osukey.git
synced 2025-05-29 17:37:23 +09:00
Rework SelctionLayer to support click-selections
This commit is contained in:
parent
b6531d632f
commit
cfb2b3f1e8
@ -157,6 +157,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
|
|
||||||
public Drawable ProxiedLayer => HeadCircle.ApproachCircle;
|
public Drawable ProxiedLayer => HeadCircle.ApproachCircle;
|
||||||
|
|
||||||
|
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => Body.ReceiveMouseInputAt(screenSpacePos);
|
||||||
|
|
||||||
public override Vector2 SelectionPoint => ToScreenSpace(Body.Position);
|
public override Vector2 SelectionPoint => ToScreenSpace(Body.Position);
|
||||||
public override Quad SelectionQuad => Body.PathDrawQuad;
|
public override Quad SelectionQuad => Body.PathDrawQuad;
|
||||||
}
|
}
|
||||||
|
@ -78,6 +78,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
|
|||||||
container.Attach(RenderbufferInternalFormat.DepthComponent16);
|
container.Attach(RenderbufferInternalFormat.DepthComponent16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => path.ReceiveMouseInputAt(screenSpacePos);
|
||||||
|
|
||||||
public void SetRange(double p0, double p1)
|
public void SetRange(double p0, double p1)
|
||||||
{
|
{
|
||||||
if (p0 > p1)
|
if (p0 > p1)
|
||||||
|
@ -19,7 +19,12 @@ namespace osu.Game.Tests.Visual
|
|||||||
{
|
{
|
||||||
public class TestCaseEditorSelectionLayer : OsuTestCase
|
public class TestCaseEditorSelectionLayer : OsuTestCase
|
||||||
{
|
{
|
||||||
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(SelectionLayer) };
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
|
{
|
||||||
|
typeof(HitObjectCapturer),
|
||||||
|
typeof(HitObjectSelectionBox),
|
||||||
|
typeof(SelectionLayer)
|
||||||
|
};
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
|
56
osu.Game/Rulesets/Edit/Layers/Selection/HitObjectCapturer.cs
Normal file
56
osu.Game/Rulesets/Edit/Layers/Selection/HitObjectCapturer.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Graphics.Primitives;
|
||||||
|
using osu.Game.Rulesets.Objects.Drawables;
|
||||||
|
using OpenTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.Edit.Layers.Selection
|
||||||
|
{
|
||||||
|
public class HitObjectCapturer
|
||||||
|
{
|
||||||
|
public event Action<DrawableHitObject> HitObjectCaptured;
|
||||||
|
|
||||||
|
private readonly IEnumerable<DrawableHitObject> capturableHitObjects;
|
||||||
|
|
||||||
|
public HitObjectCapturer(IEnumerable<DrawableHitObject> capturableHitObjects)
|
||||||
|
{
|
||||||
|
this.capturableHitObjects = capturableHitObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Captures all hitobjects that are present within the area of a <see cref="Quad"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="screenSpaceQuad">The capture <see cref="Quad"/>.</param>
|
||||||
|
/// <returns>If any <see cref="DrawableHitObject"/>s were captured.</returns>
|
||||||
|
public bool CaptureQuad(Quad screenSpaceQuad)
|
||||||
|
{
|
||||||
|
bool anyCaptured = false;
|
||||||
|
foreach (var obj in capturableHitObjects.Where(h => h.IsAlive && h.IsPresent && screenSpaceQuad.Contains(h.SelectionPoint)))
|
||||||
|
{
|
||||||
|
HitObjectCaptured?.Invoke(obj);
|
||||||
|
anyCaptured = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return anyCaptured;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Captures the top-most hitobject that is present under a specific point.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="screenSpacePoint">The <see cref="Vector2"/> to capture at.</param>
|
||||||
|
/// <returns>Whether a <see cref="DrawableHitObject"/> was captured.</returns>
|
||||||
|
public bool CapturePoint(Vector2 screenSpacePoint)
|
||||||
|
{
|
||||||
|
var captured = capturableHitObjects.Reverse().Where(h => h.IsAlive && h.IsPresent).FirstOrDefault(h => h.ReceiveMouseInputAt(screenSpacePoint));
|
||||||
|
if (captured == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
HitObjectCaptured?.Invoke(captured);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
@ -12,7 +11,6 @@ using osu.Game.Graphics;
|
|||||||
using osu.Game.Rulesets.Objects.Drawables;
|
using osu.Game.Rulesets.Objects.Drawables;
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
using osu.Framework.Configuration;
|
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Edit.Layers.Selection
|
namespace osu.Game.Rulesets.Edit.Layers.Selection
|
||||||
{
|
{
|
||||||
@ -21,29 +19,18 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class HitObjectSelectionBox : CompositeDrawable
|
public class HitObjectSelectionBox : CompositeDrawable
|
||||||
{
|
{
|
||||||
public readonly Bindable<SelectionInfo> Selection = new Bindable<SelectionInfo>();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The <see cref="DrawableHitObject"/>s that can be selected through a drag-selection.
|
|
||||||
/// </summary>
|
|
||||||
public IEnumerable<DrawableHitObject> CapturableObjects;
|
|
||||||
|
|
||||||
private readonly Container borderMask;
|
private readonly Container borderMask;
|
||||||
private readonly Drawable background;
|
private readonly Drawable background;
|
||||||
private readonly HandleContainer handles;
|
private readonly HandleContainer handles;
|
||||||
|
|
||||||
private Color4 captureFinishedColour;
|
private Color4 captureFinishedColour;
|
||||||
|
private RectangleF dragRectangle;
|
||||||
private readonly Vector2 startPos;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="HitObjectSelectionBox"/>.
|
/// Creates a new <see cref="HitObjectSelectionBox"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="startPos">The point at which the drag was initiated, in the parent's coordinates.</param>
|
public HitObjectSelectionBox()
|
||||||
public HitObjectSelectionBox(Vector2 startPos)
|
|
||||||
{
|
{
|
||||||
this.startPos = startPos;
|
|
||||||
|
|
||||||
InternalChildren = new Drawable[]
|
InternalChildren = new Drawable[]
|
||||||
{
|
{
|
||||||
new Container
|
new Container
|
||||||
@ -70,8 +57,8 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
|
|||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Alpha = 0,
|
Alpha = 0,
|
||||||
GetDragRectangle = () => dragRectangle,
|
GetDragRectangle = () => dragRectangle,
|
||||||
UpdateDragRectangle = updateDragRectangle,
|
UpdateDragRectangle = SetDragRectangle,
|
||||||
FinishDrag = FinishCapture
|
FinishDrag = () => FinishCapture()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -82,49 +69,29 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
|
|||||||
captureFinishedColour = colours.Yellow;
|
captureFinishedColour = colours.Yellow;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public void SetDragRectangle(RectangleF rectangle)
|
||||||
/// The secondary corner of the drag selection box. A rectangle will be fit between the starting position and this value.
|
|
||||||
/// </summary>
|
|
||||||
public Vector2 DragEndPosition { set => updateDragRectangle(RectangleF.FromLTRB(startPos.X, startPos.Y, value.X, value.Y)); }
|
|
||||||
|
|
||||||
private RectangleF dragRectangle;
|
|
||||||
private void updateDragRectangle(RectangleF rectangle)
|
|
||||||
{
|
{
|
||||||
dragRectangle = rectangle;
|
dragRectangle = rectangle;
|
||||||
|
|
||||||
Position = new Vector2(
|
var topLeft = Parent.ToLocalSpace(rectangle.TopLeft);
|
||||||
Math.Min(rectangle.Left, rectangle.Right),
|
var bottomRight = Parent.ToLocalSpace(rectangle.BottomRight);
|
||||||
Math.Min(rectangle.Top, rectangle.Bottom));
|
|
||||||
|
|
||||||
Size = new Vector2(
|
Position = topLeft;
|
||||||
Math.Max(rectangle.Left, rectangle.Right) - Position.X,
|
Size = bottomRight - topLeft;
|
||||||
Math.Max(rectangle.Top, rectangle.Bottom) - Position.Y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly List<DrawableHitObject> capturedHitObjects = new List<DrawableHitObject>();
|
private readonly List<DrawableHitObject> capturedHitObjects = new List<DrawableHitObject>();
|
||||||
|
|
||||||
/// <summary>
|
public bool HasCaptured => capturedHitObjects.Count > 0;
|
||||||
/// Processes hitobjects to determine which ones are captured by the drag selection.
|
|
||||||
/// Captured hitobjects will be enclosed by the drag selection upon <see cref="FinishCapture"/>.
|
|
||||||
/// </summary>
|
|
||||||
public void BeginCapture()
|
|
||||||
{
|
|
||||||
capturedHitObjects.Clear();
|
|
||||||
|
|
||||||
foreach (var obj in CapturableObjects)
|
public void AddCaptured(DrawableHitObject hitObject) => capturedHitObjects.Add(hitObject);
|
||||||
{
|
|
||||||
if (!obj.IsAlive || !obj.IsPresent)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (ScreenSpaceDrawQuad.Contains(obj.SelectionPoint))
|
public void ClearCaptured() => capturedHitObjects.Clear();
|
||||||
capturedHitObjects.Add(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Encloses hitobjects captured through <see cref="BeginCapture"/> in the drag selection box.
|
/// Encloses hitobjects captured through <see cref="BeginCapture"/> in the drag selection box.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void FinishCapture()
|
public void FinishCapture(bool instant = false)
|
||||||
{
|
{
|
||||||
if (capturedHitObjects.Count == 0)
|
if (capturedHitObjects.Count == 0)
|
||||||
{
|
{
|
||||||
@ -145,8 +112,8 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
|
|||||||
topLeft -= new Vector2(5);
|
topLeft -= new Vector2(5);
|
||||||
bottomRight += new Vector2(5);
|
bottomRight += new Vector2(5);
|
||||||
|
|
||||||
this.MoveTo(topLeft, 200, Easing.OutQuint)
|
this.MoveTo(topLeft, instant ? 0 : 100, Easing.OutQuint)
|
||||||
.ResizeTo(bottomRight - topLeft, 200, Easing.OutQuint);
|
.ResizeTo(bottomRight - topLeft, instant ? 0 : 100, Easing.OutQuint);
|
||||||
|
|
||||||
dragRectangle = RectangleF.FromLTRB(topLeft.X, topLeft.Y, bottomRight.X, bottomRight.Y);
|
dragRectangle = RectangleF.FromLTRB(topLeft.X, topLeft.Y, bottomRight.X, bottomRight.Y);
|
||||||
|
|
||||||
@ -156,12 +123,6 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
|
|||||||
// Transform into markers to let the user modify the drag selection further.
|
// Transform into markers to let the user modify the drag selection further.
|
||||||
background.Delay(50).FadeOut(200);
|
background.Delay(50).FadeOut(200);
|
||||||
handles.FadeIn(200);
|
handles.FadeIn(200);
|
||||||
|
|
||||||
Selection.Value = new SelectionInfo
|
|
||||||
{
|
|
||||||
Objects = capturedHitObjects,
|
|
||||||
SelectionQuad = Parent.ToScreenSpace(dragRectangle)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool isActive = true;
|
private bool isActive = true;
|
||||||
@ -171,9 +132,7 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
|
|||||||
public override void Hide()
|
public override void Hide()
|
||||||
{
|
{
|
||||||
isActive = false;
|
isActive = false;
|
||||||
this.FadeOut(400, Easing.OutQuint).Expire();
|
this.FadeOut(400, Easing.OutQuint);
|
||||||
|
|
||||||
Selection.Value = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Primitives;
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
|
using osu.Game.Rulesets.Objects.Drawables;
|
||||||
using osu.Game.Rulesets.UI;
|
using osu.Game.Rulesets.UI;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Edit.Layers.Selection
|
namespace osu.Game.Rulesets.Edit.Layers.Selection
|
||||||
{
|
{
|
||||||
public class SelectionLayer : CompositeDrawable
|
public class SelectionLayer : CompositeDrawable
|
||||||
{
|
{
|
||||||
public readonly Bindable<SelectionInfo> Selection = new Bindable<SelectionInfo>();
|
|
||||||
|
|
||||||
private readonly Playfield playfield;
|
private readonly Playfield playfield;
|
||||||
|
|
||||||
public SelectionLayer(Playfield playfield)
|
public SelectionLayer(Playfield playfield)
|
||||||
@ -22,39 +22,80 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
|
|||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
}
|
}
|
||||||
|
|
||||||
private HitObjectSelectionBox selectionBoxBox;
|
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);
|
||||||
|
|
||||||
protected override bool OnDragStart(InputState state)
|
protected override bool OnDragStart(InputState state)
|
||||||
{
|
{
|
||||||
// Hide the previous drag box - we won't be working with it any longer
|
// Hide the previous drag box - we won't be working with it any longer
|
||||||
selectionBoxBox?.Hide();
|
selectionBox?.Hide();
|
||||||
|
selectionBox?.Expire();
|
||||||
|
|
||||||
AddInternal(selectionBoxBox = new HitObjectSelectionBox(ToLocalSpace(state.Mouse.NativeState.Position))
|
AddInternal(selectionBox = new HitObjectSelectionBox());
|
||||||
{
|
|
||||||
CapturableObjects = playfield.HitObjects.Objects,
|
|
||||||
});
|
|
||||||
|
|
||||||
Selection.BindTo(selectionBoxBox.Selection);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnDrag(InputState state)
|
protected override bool OnDrag(InputState state)
|
||||||
{
|
{
|
||||||
selectionBoxBox.DragEndPosition = ToLocalSpace(state.Mouse.NativeState.Position);
|
var dragPosition = state.Mouse.NativeState.Position;
|
||||||
selectionBoxBox.BeginCapture();
|
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);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnDragEnd(InputState state)
|
protected override bool OnDragEnd(InputState state)
|
||||||
{
|
{
|
||||||
selectionBoxBox.FinishCapture();
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnClick(InputState state)
|
protected override bool OnClick(InputState state)
|
||||||
{
|
{
|
||||||
selectionBoxBox?.Hide();
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -332,6 +332,7 @@
|
|||||||
<Compile Include="Overlays\Settings\Sections\Maintenance\DeleteAllBeatmapsDialog.cs" />
|
<Compile Include="Overlays\Settings\Sections\Maintenance\DeleteAllBeatmapsDialog.cs" />
|
||||||
<Compile Include="Rulesets\Configuration\IRulesetConfigManager.cs" />
|
<Compile Include="Rulesets\Configuration\IRulesetConfigManager.cs" />
|
||||||
<Compile Include="Rulesets\Configuration\RulesetConfigManager.cs" />
|
<Compile Include="Rulesets\Configuration\RulesetConfigManager.cs" />
|
||||||
|
<Compile Include="Rulesets\Edit\Layers\Selection\HitObjectCapturer.cs" />
|
||||||
<Compile Include="Rulesets\Mods\IApplicableFailOverride.cs" />
|
<Compile Include="Rulesets\Mods\IApplicableFailOverride.cs" />
|
||||||
<Compile Include="Rulesets\Mods\IApplicableMod.cs" />
|
<Compile Include="Rulesets\Mods\IApplicableMod.cs" />
|
||||||
<Compile Include="Rulesets\Mods\IApplicableToBeatmapConverter.cs" />
|
<Compile Include="Rulesets\Mods\IApplicableToBeatmapConverter.cs" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user