mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 13:37:25 +08:00
Add test covering expected UX of range selection
This commit is contained in:
parent
0de7db5840
commit
81d160c85a
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Testing;
|
||||
@ -159,5 +160,72 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
|
||||
AddAssert("no hitobjects in beatmap", () => EditorBeatmap.HitObjects.Count == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRangeSelect()
|
||||
{
|
||||
var addedObjects = new[]
|
||||
{
|
||||
new HitCircle { StartTime = 100 },
|
||||
new HitCircle { StartTime = 200, Position = new Vector2(100) },
|
||||
new HitCircle { StartTime = 300, Position = new Vector2(200) },
|
||||
new HitCircle { StartTime = 400, Position = new Vector2(300) },
|
||||
new HitCircle { StartTime = 500, Position = new Vector2(400) },
|
||||
};
|
||||
|
||||
AddStep("add hitobjects", () => EditorBeatmap.AddRange(addedObjects));
|
||||
|
||||
moveMouseToObject(() => addedObjects[1]);
|
||||
AddStep("click second", () => InputManager.Click(MouseButton.Left));
|
||||
|
||||
AddAssert("hitobject selected", () => EditorBeatmap.SelectedHitObjects.Single() == addedObjects[1]);
|
||||
|
||||
AddStep("hold shift", () => InputManager.PressKey(Key.ShiftLeft));
|
||||
|
||||
moveMouseToObject(() => addedObjects[3]);
|
||||
AddStep("click fourth", () => InputManager.Click(MouseButton.Left));
|
||||
assertSelectionIs(addedObjects.Skip(1).Take(3));
|
||||
|
||||
moveMouseToObject(() => addedObjects[0]);
|
||||
AddStep("click first", () => InputManager.Click(MouseButton.Left));
|
||||
assertSelectionIs(addedObjects.Take(2));
|
||||
|
||||
AddStep("clear selection", () => EditorBeatmap.SelectedHitObjects.Clear());
|
||||
AddStep("release shift", () => InputManager.ReleaseKey(Key.ShiftLeft));
|
||||
|
||||
moveMouseToObject(() => addedObjects[0]);
|
||||
AddStep("click first", () => InputManager.Click(MouseButton.Left));
|
||||
assertSelectionIs(addedObjects.Take(1));
|
||||
|
||||
AddStep("hold ctrl", () => InputManager.PressKey(Key.ControlLeft));
|
||||
moveMouseToObject(() => addedObjects[2]);
|
||||
AddStep("click third", () => InputManager.Click(MouseButton.Left));
|
||||
assertSelectionIs(new[] { addedObjects[0], addedObjects[2] });
|
||||
|
||||
AddStep("hold shift", () => InputManager.PressKey(Key.ShiftLeft));
|
||||
moveMouseToObject(() => addedObjects[4]);
|
||||
AddStep("click fifth", () => InputManager.Click(MouseButton.Left));
|
||||
assertSelectionIs(addedObjects.Except(new[] { addedObjects[1] }));
|
||||
|
||||
moveMouseToObject(() => addedObjects[0]);
|
||||
AddStep("click first", () => InputManager.Click(MouseButton.Left));
|
||||
assertSelectionIs(addedObjects);
|
||||
|
||||
AddStep("clear selection", () => EditorBeatmap.SelectedHitObjects.Clear());
|
||||
moveMouseToObject(() => addedObjects[0]);
|
||||
AddStep("click first", () => InputManager.Click(MouseButton.Left));
|
||||
assertSelectionIs(addedObjects.Take(1));
|
||||
|
||||
moveMouseToObject(() => addedObjects[1]);
|
||||
AddStep("click first", () => InputManager.Click(MouseButton.Left));
|
||||
assertSelectionIs(addedObjects.Take(2));
|
||||
|
||||
moveMouseToObject(() => addedObjects[2]);
|
||||
AddStep("click first", () => InputManager.Click(MouseButton.Left));
|
||||
assertSelectionIs(addedObjects.Take(3));
|
||||
}
|
||||
|
||||
private void assertSelectionIs(IEnumerable<HitObject> hitObjects)
|
||||
=> AddAssert("correct hitobjects selected", () => EditorBeatmap.SelectedHitObjects.OrderBy(h => h.StartTime).SequenceEqual(hitObjects));
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,16 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
{
|
||||
@ -62,5 +65,35 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
||||
EditorBeatmap.Update(h);
|
||||
});
|
||||
}
|
||||
|
||||
internal override bool MouseDownSelectionRequested(SelectionBlueprint<HitObject> blueprint, MouseButtonEvent e)
|
||||
{
|
||||
if (e.ShiftPressed && e.Button == MouseButton.Left && SelectedItems.Any())
|
||||
{
|
||||
handleRangeSelection(blueprint);
|
||||
return true;
|
||||
}
|
||||
|
||||
return base.MouseDownSelectionRequested(blueprint, e);
|
||||
}
|
||||
|
||||
private void handleRangeSelection(SelectionBlueprint<HitObject> blueprint)
|
||||
{
|
||||
var clickedObject = blueprint.Item;
|
||||
double rangeStart = clickedObject.StartTime;
|
||||
double rangeEnd = clickedObject.GetEndTime();
|
||||
|
||||
foreach (var selectedObject in SelectedItems)
|
||||
{
|
||||
rangeStart = Math.Min(rangeStart, selectedObject.StartTime);
|
||||
rangeEnd = Math.Max(rangeEnd, selectedObject.GetEndTime());
|
||||
}
|
||||
|
||||
EditorBeatmap.SelectedHitObjects.Clear();
|
||||
EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects.Where(obj => isInRange(obj, rangeStart, rangeEnd)));
|
||||
|
||||
bool isInRange(HitObject hitObject, double start, double end)
|
||||
=> hitObject.StartTime >= start && hitObject.GetEndTime() <= end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user