Unify SelectionLayer and HitObjectCapturer, rename SelectionBox

This commit is contained in:
smoogipoo 2018-02-12 18:35:01 +09:00
parent 20c0dee17d
commit e10bb2db05
5 changed files with 36 additions and 79 deletions

View File

@ -21,8 +21,7 @@ namespace osu.Game.Tests.Visual
{
public override IReadOnlyList<Type> RequiredTypes => new[]
{
typeof(HitObjectCapturer),
typeof(SelectionDragger),
typeof(SelectionBox),
typeof(SelectionLayer),
typeof(CaptureBox)
};

View File

@ -1,56 +0,0 @@
// 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;
}
}
}

View File

@ -12,12 +12,12 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
/// <summary>
/// A box that represents a drag selection.
/// </summary>
public class SelectionDragger : CompositeDrawable
public class SelectionBox : CompositeDrawable
{
/// <summary>
/// Creates a new <see cref="SelectionDragger"/>.
/// Creates a new <see cref="SelectionBox"/>.
/// </summary>
public SelectionDragger()
public SelectionBox()
{
InternalChildren = new Drawable[]
{

View File

@ -3,13 +3,13 @@
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Input;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.UI;
using OpenTK;
namespace osu.Game.Rulesets.Edit.Layers.Selection
{
@ -24,19 +24,11 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
RelativeSizeAxes = Axes.Both;
}
private SelectionDragger selectionDragger;
private SelectionBox selectionBox;
private CaptureBox captureBox;
private HitObjectCapturer capturer;
private readonly List<DrawableHitObject> capturedHitObjects = new List<DrawableHitObject>();
[BackgroundDependencyLoader]
private void load()
{
capturer = new HitObjectCapturer(playfield.HitObjects.Objects);
capturer.HitObjectCaptured += h => capturedHitObjects.Add(h);
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
capturedHitObjects.Clear();
@ -46,7 +38,7 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
protected override bool OnDragStart(InputState state)
{
AddInternal(selectionDragger = new SelectionDragger());
AddInternal(selectionBox = new SelectionBox());
return true;
}
@ -57,15 +49,15 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
var screenSpaceDragQuad = new Quad(dragStartPosition.X, dragStartPosition.Y, dragPosition.X - dragStartPosition.X, dragPosition.Y - dragStartPosition.Y);
selectionDragger.SetDragRectangle(screenSpaceDragQuad.AABBFloat);
capturer.CaptureQuad(screenSpaceDragQuad);
selectionBox.SetDragRectangle(screenSpaceDragQuad.AABBFloat);
captureQuad(screenSpaceDragQuad);
return true;
}
protected override bool OnDragEnd(InputState state)
{
selectionDragger.Hide();
selectionBox.Hide();
finishCapture();
return true;
@ -73,12 +65,35 @@ namespace osu.Game.Rulesets.Edit.Layers.Selection
protected override bool OnClick(InputState state)
{
if (capturer.CapturePoint(state.Mouse.NativeState.Position))
finishCapture();
capturePoint(state.Mouse.NativeState.Position);
finishCapture();
return true;
}
/// <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>
private void captureQuad(Quad screenSpaceQuad)
{
foreach (var obj in playfield.HitObjects.Objects.Where(h => h.IsAlive && h.IsPresent && screenSpaceQuad.Contains(h.SelectionPoint)))
capturedHitObjects.Add(obj);
}
/// <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>
private void capturePoint(Vector2 screenSpacePoint)
{
var captured = playfield.HitObjects.Objects.Reverse().Where(h => h.IsAlive && h.IsPresent).FirstOrDefault(h => h.ReceiveMouseInputAt(screenSpacePoint));
if (captured == null)
return;
capturedHitObjects.Add(captured);
}
private void finishCapture()
{
if (capturedHitObjects.Count == 0)

View File

@ -333,7 +333,6 @@
<Compile Include="Rulesets\Configuration\IRulesetConfigManager.cs" />
<Compile Include="Rulesets\Configuration\RulesetConfigManager.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\CaptureBox.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\HitObjectCapturer.cs" />
<Compile Include="Rulesets\Mods\IApplicableFailOverride.cs" />
<Compile Include="Rulesets\Mods\IApplicableMod.cs" />
<Compile Include="Rulesets\Mods\IApplicableToBeatmapConverter.cs" />
@ -354,9 +353,9 @@
<Compile Include="Screens\Select\ImportFromStablePopup.cs" />
<Compile Include="Overlays\Settings\SettingsButton.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\OriginHandle.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\SelectionDragger.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\Handle.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\HandleContainer.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\SelectionBox.cs" />
<Compile Include="Rulesets\Edit\Layers\Selection\SelectionLayer.cs" />
<Compile Include="Screens\Edit\Components\BottomBarContainer.cs" />
<Compile Include="Screens\Edit\Components\PlaybackControl.cs" />