1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 15:32:57 +08:00
osu-lazer/osu.Game.Tests/Visual/Editing/TestSceneHitObjectComposer.cs

208 lines
8.4 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
2018-04-13 17:19:50 +08:00
using System.Collections.Generic;
using System.Linq;
2018-04-13 17:19:50 +08:00
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
2018-04-13 17:19:50 +08:00
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Edit.Tools;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Edit;
using osu.Game.Rulesets.Osu.Objects;
2020-01-02 00:23:21 +08:00
using osu.Game.Screens.Edit;
using osu.Game.Screens.Edit.Components.RadioButtons;
using osu.Game.Screens.Edit.Components.TernaryButtons;
using osu.Game.Screens.Edit.Compose.Components;
2019-03-25 00:02:36 +08:00
using osuTK;
using osuTK.Input;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Tests.Visual.Editing
2018-04-13 17:19:50 +08:00
{
[TestFixture]
2019-10-25 18:00:10 +08:00
public class TestSceneHitObjectComposer : EditorClockTestScene
2018-04-13 17:19:50 +08:00
{
private OsuHitObjectComposer hitObjectComposer;
private EditorBeatmapContainer editorBeatmapContainer;
private EditorBeatmap editorBeatmap => editorBeatmapContainer.EditorBeatmap;
[SetUpSteps]
public void SetUpSteps()
2018-04-13 17:19:50 +08:00
{
AddStep("create beatmap", () =>
2018-04-13 17:19:50 +08:00
{
Beatmap.Value = CreateWorkingBeatmap(new Beatmap
2018-04-13 17:19:50 +08:00
{
BeatmapInfo =
{
Ruleset = new OsuRuleset().RulesetInfo
},
HitObjects = new List<HitObject>
2018-04-13 17:19:50 +08:00
{
new HitCircle
{
Position = new Vector2(256, 192), Scale = 0.5f
},
new HitCircle { Position = new Vector2(344, 148), Scale = 0.5f },
new Slider
2018-04-13 17:19:50 +08:00
{
Position = new Vector2(128, 256),
Path = new SliderPath(PathType.Linear, new[]
{
Vector2.Zero,
new Vector2(216, 0),
}),
Scale = 0.5f,
}
},
});
});
AddStep("Create composer", () =>
{
Child = editorBeatmapContainer = new EditorBeatmapContainer(Beatmap.Value)
{
Child = hitObjectComposer = new OsuHitObjectComposer(new OsuRuleset())
{
// force the composer to fully overlap the playfield area by setting a 4:3 aspect ratio.
FillMode = FillMode.Fit,
FillAspectRatio = 4 / 3f
}
};
2018-04-13 17:19:50 +08:00
});
}
[Test]
public void TestPlacementOnlyWorksWithTiming()
{
AddStep("clear all control points", () => editorBeatmap.ControlPointInfo.Clear());
AddAssert("Tool is selection", () => hitObjectComposer.ChildrenOfType<ComposeBlueprintContainer>().First().CurrentTool is SelectTool);
AddAssert("Hitcircle button not clickable", () => !hitObjectComposer.ChildrenOfType<EditorRadioButton>().First(d => d.Button.Label == "HitCircle").Enabled.Value);
AddStep("Add timing point", () => editorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint()));
AddAssert("Hitcircle button is clickable", () => hitObjectComposer.ChildrenOfType<EditorRadioButton>().First(d => d.Button.Label == "HitCircle").Enabled.Value);
2021-08-04 16:27:44 +08:00
AddStep("Change to hitcircle", () => hitObjectComposer.ChildrenOfType<EditorRadioButton>().First(d => d.Button.Label == "HitCircle").TriggerClick());
AddAssert("Tool changed", () => hitObjectComposer.ChildrenOfType<ComposeBlueprintContainer>().First().CurrentTool is HitCircleCompositionTool);
}
2018-04-13 17:19:50 +08:00
[Test]
public void TestPlacementFailsWhenClickingButton()
{
AddStep("clear all control points and hitobjects", () =>
{
editorBeatmap.ControlPointInfo.Clear();
editorBeatmap.Clear();
});
AddStep("Add timing point", () => editorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint()));
AddStep("Change to hitcircle", () => hitObjectComposer.ChildrenOfType<EditorRadioButton>().First(d => d.Button.Label == "HitCircle").TriggerClick());
AddStep("move mouse to overlapping toggle button", () =>
{
var playfield = hitObjectComposer.Playfield.ScreenSpaceDrawQuad;
var button = hitObjectComposer
.ChildrenOfType<ExpandingToolboxContainer>().First()
.ChildrenOfType<DrawableTernaryButton>().First(b => playfield.Contains(b.ScreenSpaceDrawQuad.Centre));
InputManager.MoveMouseTo(button);
});
AddAssert("no circles placed", () => editorBeatmap.HitObjects.Count == 0);
AddStep("attempt place circle", () => InputManager.Click(MouseButton.Left));
AddAssert("no circles placed", () => editorBeatmap.HitObjects.Count == 0);
}
[Test]
public void TestPlacementWithinToolboxScrollArea()
{
AddStep("clear all control points and hitobjects", () =>
{
editorBeatmap.ControlPointInfo.Clear();
editorBeatmap.Clear();
});
AddStep("Add timing point", () => editorBeatmap.ControlPointInfo.Add(0, new TimingControlPoint()));
AddStep("Change to hitcircle", () => hitObjectComposer.ChildrenOfType<EditorRadioButton>().First(d => d.Button.Label == "HitCircle").TriggerClick());
AddStep("move mouse to scroll area", () =>
{
// Specifically wanting to test the area of overlap between the left expanding toolbox container
// and the playfield/composer.
var scrollArea = hitObjectComposer.ChildrenOfType<ExpandingToolboxContainer>().First().ScreenSpaceDrawQuad;
var playfield = hitObjectComposer.Playfield.ScreenSpaceDrawQuad;
InputManager.MoveMouseTo(new Vector2(scrollArea.TopLeft.X + 1, playfield.Centre.Y));
});
AddAssert("no circles placed", () => editorBeatmap.HitObjects.Count == 0);
AddStep("place circle", () => InputManager.Click(MouseButton.Left));
AddAssert("circle placed", () => editorBeatmap.HitObjects.Count == 1);
}
[Test]
public void TestDistanceSpacingHotkeys()
{
2022-04-28 11:52:42 +08:00
double originalSpacing = 0;
2022-04-28 11:52:42 +08:00
AddStep("retrieve original spacing", () => originalSpacing = editorBeatmap.BeatmapInfo.DistanceSpacing);
AddStep("hold ctrl", () => InputManager.PressKey(Key.LControl));
AddStep("hold alt", () => InputManager.PressKey(Key.LAlt));
AddStep("scroll mouse 5 steps", () => InputManager.ScrollVerticalBy(5));
2022-04-28 11:52:42 +08:00
AddAssert("distance spacing increased by 0.5", () => editorBeatmap.BeatmapInfo.DistanceSpacing == originalSpacing + 0.5);
AddStep("release alt", () => InputManager.ReleaseKey(Key.LAlt));
AddStep("release ctrl", () => InputManager.ReleaseKey(Key.LControl));
}
public class EditorBeatmapContainer : Container
{
private readonly IWorkingBeatmap working;
public EditorBeatmap EditorBeatmap { get; private set; }
public EditorBeatmapContainer(IWorkingBeatmap working)
{
this.working = working;
RelativeSizeAxes = Axes.Both;
}
2020-01-02 00:23:21 +08:00
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
EditorBeatmap = new EditorBeatmap(working.GetPlayableBeatmap(new OsuRuleset().RulesetInfo));
dependencies.CacheAs(EditorBeatmap);
dependencies.CacheAs<IBeatSnapProvider>(EditorBeatmap);
return dependencies;
}
protected override void LoadComplete()
{
base.LoadComplete();
2018-04-13 17:19:50 +08:00
Add(EditorBeatmap);
}
}
2018-04-13 17:19:50 +08:00
}
}