2021-11-13 23:58:24 +08:00
|
|
|
// 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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2021-11-13 23:58:24 +08:00
|
|
|
using System.Linq;
|
|
|
|
using Humanizer;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2021-11-14 00:43:33 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-11-13 23:58:24 +08:00
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
using osu.Game.Rulesets.Osu.UI;
|
|
|
|
using osu.Game.Screens.Edit.Compose.Components.Timeline;
|
|
|
|
using osu.Game.Screens.Edit.Timing;
|
|
|
|
using osu.Game.Tests.Beatmaps;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Input;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Editing
|
|
|
|
{
|
|
|
|
public class TestSceneHitObjectSamplePointAdjustments : EditorTestScene
|
|
|
|
{
|
|
|
|
protected override Ruleset CreateEditorRuleset() => new OsuRuleset();
|
|
|
|
|
|
|
|
protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => new TestBeatmap(ruleset, false);
|
|
|
|
|
|
|
|
public override void SetUpSteps()
|
|
|
|
{
|
|
|
|
base.SetUpSteps();
|
|
|
|
|
|
|
|
AddStep("add test objects", () =>
|
|
|
|
{
|
|
|
|
EditorBeatmap.Add(new HitCircle
|
|
|
|
{
|
|
|
|
StartTime = 0,
|
|
|
|
Position = (OsuPlayfield.BASE_SIZE - new Vector2(100, 0)) / 2,
|
|
|
|
SampleControlPoint = new SampleControlPoint
|
|
|
|
{
|
|
|
|
SampleBank = "normal",
|
|
|
|
SampleVolume = 80
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-11-14 00:43:33 +08:00
|
|
|
EditorBeatmap.Add(new HitCircle
|
2021-11-13 23:58:24 +08:00
|
|
|
{
|
|
|
|
StartTime = 500,
|
|
|
|
Position = (OsuPlayfield.BASE_SIZE + new Vector2(100, 0)) / 2,
|
|
|
|
SampleControlPoint = new SampleControlPoint
|
|
|
|
{
|
|
|
|
SampleBank = "soft",
|
|
|
|
SampleVolume = 60
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-11 14:51:59 +08:00
|
|
|
[Test]
|
|
|
|
public void TestPopoverHasFocus()
|
|
|
|
{
|
|
|
|
clickSamplePiece(0);
|
|
|
|
samplePopoverHasFocus();
|
|
|
|
}
|
|
|
|
|
2021-11-13 23:58:24 +08:00
|
|
|
[Test]
|
|
|
|
public void TestSingleSelection()
|
|
|
|
{
|
|
|
|
clickSamplePiece(0);
|
|
|
|
samplePopoverHasSingleBank("normal");
|
|
|
|
samplePopoverHasSingleVolume(80);
|
|
|
|
|
|
|
|
dismissPopover();
|
|
|
|
|
|
|
|
// select first object to ensure that sample pieces for unselected objects
|
|
|
|
// work independently from selection state.
|
|
|
|
AddStep("select first object", () => EditorBeatmap.SelectedHitObjects.Add(EditorBeatmap.HitObjects.First()));
|
|
|
|
|
|
|
|
clickSamplePiece(1);
|
|
|
|
samplePopoverHasSingleBank("soft");
|
|
|
|
samplePopoverHasSingleVolume(60);
|
|
|
|
|
|
|
|
setVolumeViaPopover(90);
|
|
|
|
hitObjectHasSampleVolume(1, 90);
|
|
|
|
|
|
|
|
setBankViaPopover("drum");
|
|
|
|
hitObjectHasSampleBank(1, "drum");
|
|
|
|
}
|
|
|
|
|
2021-11-14 00:02:55 +08:00
|
|
|
[Test]
|
|
|
|
public void TestMultipleSelectionWithSameSampleVolume()
|
|
|
|
{
|
|
|
|
AddStep("unify sample volume", () =>
|
|
|
|
{
|
|
|
|
foreach (var h in EditorBeatmap.HitObjects)
|
|
|
|
h.SampleControlPoint.SampleVolume = 50;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("select both objects", () => EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects));
|
|
|
|
clickSamplePiece(0);
|
|
|
|
samplePopoverHasSingleVolume(50);
|
|
|
|
|
|
|
|
dismissPopover();
|
|
|
|
|
|
|
|
clickSamplePiece(1);
|
|
|
|
samplePopoverHasSingleVolume(50);
|
|
|
|
|
|
|
|
setVolumeViaPopover(75);
|
|
|
|
hitObjectHasSampleVolume(0, 75);
|
|
|
|
hitObjectHasSampleVolume(1, 75);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMultipleSelectionWithDifferentSampleVolume()
|
|
|
|
{
|
|
|
|
AddStep("select both objects", () => EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects));
|
|
|
|
clickSamplePiece(0);
|
|
|
|
samplePopoverHasIndeterminateVolume();
|
|
|
|
|
|
|
|
dismissPopover();
|
|
|
|
|
|
|
|
clickSamplePiece(1);
|
|
|
|
samplePopoverHasIndeterminateVolume();
|
|
|
|
|
|
|
|
setVolumeViaPopover(30);
|
|
|
|
hitObjectHasSampleVolume(0, 30);
|
|
|
|
hitObjectHasSampleVolume(1, 30);
|
|
|
|
}
|
|
|
|
|
2021-11-14 00:07:19 +08:00
|
|
|
[Test]
|
|
|
|
public void TestMultipleSelectionWithSameSampleBank()
|
|
|
|
{
|
|
|
|
AddStep("unify sample bank", () =>
|
|
|
|
{
|
|
|
|
foreach (var h in EditorBeatmap.HitObjects)
|
|
|
|
h.SampleControlPoint.SampleBank = "soft";
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("select both objects", () => EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects));
|
|
|
|
clickSamplePiece(0);
|
|
|
|
samplePopoverHasSingleBank("soft");
|
|
|
|
|
|
|
|
dismissPopover();
|
|
|
|
|
|
|
|
clickSamplePiece(1);
|
|
|
|
samplePopoverHasSingleBank("soft");
|
|
|
|
|
2021-11-14 00:43:33 +08:00
|
|
|
setBankViaPopover(string.Empty);
|
|
|
|
hitObjectHasSampleBank(0, "soft");
|
|
|
|
hitObjectHasSampleBank(1, "soft");
|
|
|
|
samplePopoverHasSingleBank("soft");
|
|
|
|
|
2021-11-14 00:07:19 +08:00
|
|
|
setBankViaPopover("drum");
|
|
|
|
hitObjectHasSampleBank(0, "drum");
|
|
|
|
hitObjectHasSampleBank(1, "drum");
|
2021-11-14 00:43:33 +08:00
|
|
|
samplePopoverHasSingleBank("drum");
|
2021-11-14 00:07:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMultipleSelectionWithDifferentSampleBank()
|
|
|
|
{
|
|
|
|
AddStep("select both objects", () => EditorBeatmap.SelectedHitObjects.AddRange(EditorBeatmap.HitObjects));
|
|
|
|
clickSamplePiece(0);
|
|
|
|
samplePopoverHasIndeterminateBank();
|
|
|
|
|
|
|
|
dismissPopover();
|
|
|
|
|
|
|
|
clickSamplePiece(1);
|
|
|
|
samplePopoverHasIndeterminateBank();
|
|
|
|
|
2021-11-14 00:43:33 +08:00
|
|
|
setBankViaPopover(string.Empty);
|
|
|
|
hitObjectHasSampleBank(0, "normal");
|
|
|
|
hitObjectHasSampleBank(1, "soft");
|
|
|
|
samplePopoverHasIndeterminateBank();
|
|
|
|
|
2021-11-14 00:07:19 +08:00
|
|
|
setBankViaPopover("normal");
|
|
|
|
hitObjectHasSampleBank(0, "normal");
|
|
|
|
hitObjectHasSampleBank(1, "normal");
|
2021-11-14 00:43:33 +08:00
|
|
|
samplePopoverHasSingleBank("normal");
|
2021-11-14 00:07:19 +08:00
|
|
|
}
|
|
|
|
|
2022-05-11 14:51:00 +08:00
|
|
|
private void clickSamplePiece(int objectIndex) => AddStep($"click {objectIndex.ToOrdinalWords()} sample piece", () =>
|
2021-11-13 23:58:24 +08:00
|
|
|
{
|
2022-05-11 14:51:00 +08:00
|
|
|
var samplePiece = this.ChildrenOfType<SamplePointPiece>().Single(piece => piece.HitObject == EditorBeatmap.HitObjects.ElementAt(objectIndex));
|
2021-11-13 23:58:24 +08:00
|
|
|
|
2022-05-11 14:51:00 +08:00
|
|
|
InputManager.MoveMouseTo(samplePiece);
|
2021-11-13 23:58:24 +08:00
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
|
2022-05-11 14:51:59 +08:00
|
|
|
private void samplePopoverHasFocus() => AddUntilStep("sample popover textbox focused", () =>
|
|
|
|
{
|
|
|
|
var popover = this.ChildrenOfType<SamplePointPiece.SampleEditPopover>().SingleOrDefault();
|
|
|
|
var slider = popover?.ChildrenOfType<IndeterminateSliderWithTextBoxInput<int>>().Single();
|
|
|
|
var textbox = slider?.ChildrenOfType<OsuTextBox>().Single();
|
|
|
|
|
|
|
|
return textbox?.HasFocus == true;
|
|
|
|
});
|
|
|
|
|
2021-11-13 23:58:24 +08:00
|
|
|
private void samplePopoverHasSingleVolume(int volume) => AddUntilStep($"sample popover has volume {volume}", () =>
|
|
|
|
{
|
|
|
|
var popover = this.ChildrenOfType<SamplePointPiece.SampleEditPopover>().SingleOrDefault();
|
2021-11-14 00:21:48 +08:00
|
|
|
var slider = popover?.ChildrenOfType<IndeterminateSliderWithTextBoxInput<int>>().Single();
|
2021-11-13 23:58:24 +08:00
|
|
|
|
|
|
|
return slider?.Current.Value == volume;
|
|
|
|
});
|
|
|
|
|
2021-11-14 00:21:48 +08:00
|
|
|
private void samplePopoverHasIndeterminateVolume() => AddUntilStep("sample popover has indeterminate volume", () =>
|
2021-11-14 00:02:55 +08:00
|
|
|
{
|
|
|
|
var popover = this.ChildrenOfType<SamplePointPiece.SampleEditPopover>().SingleOrDefault();
|
2021-11-14 00:21:48 +08:00
|
|
|
var slider = popover?.ChildrenOfType<IndeterminateSliderWithTextBoxInput<int>>().Single();
|
2021-11-14 00:02:55 +08:00
|
|
|
|
|
|
|
return slider != null && slider.Current.Value == null;
|
|
|
|
});
|
|
|
|
|
2021-11-13 23:58:24 +08:00
|
|
|
private void samplePopoverHasSingleBank(string bank) => AddUntilStep($"sample popover has bank {bank}", () =>
|
|
|
|
{
|
|
|
|
var popover = this.ChildrenOfType<SamplePointPiece.SampleEditPopover>().SingleOrDefault();
|
2021-11-14 00:43:33 +08:00
|
|
|
var textBox = popover?.ChildrenOfType<OsuTextBox>().First();
|
2021-11-13 23:58:24 +08:00
|
|
|
|
2021-11-14 00:43:33 +08:00
|
|
|
return textBox?.Current.Value == bank && string.IsNullOrEmpty(textBox?.PlaceholderText.ToString());
|
2021-11-13 23:58:24 +08:00
|
|
|
});
|
|
|
|
|
2021-11-14 00:43:33 +08:00
|
|
|
private void samplePopoverHasIndeterminateBank() => AddUntilStep("sample popover has indeterminate bank", () =>
|
2021-11-14 00:07:19 +08:00
|
|
|
{
|
|
|
|
var popover = this.ChildrenOfType<SamplePointPiece.SampleEditPopover>().SingleOrDefault();
|
2021-11-14 00:43:33 +08:00
|
|
|
var textBox = popover?.ChildrenOfType<OsuTextBox>().First();
|
2021-11-14 00:07:19 +08:00
|
|
|
|
2021-11-14 00:43:33 +08:00
|
|
|
return textBox != null && string.IsNullOrEmpty(textBox.Current.Value) && !string.IsNullOrEmpty(textBox.PlaceholderText.ToString());
|
2021-11-14 00:07:19 +08:00
|
|
|
});
|
|
|
|
|
2021-11-13 23:58:24 +08:00
|
|
|
private void dismissPopover()
|
|
|
|
{
|
2022-05-11 16:25:41 +08:00
|
|
|
AddStep("unfocus textbox", () => InputManager.Key(Key.Escape));
|
2021-11-13 23:58:24 +08:00
|
|
|
AddStep("dismiss popover", () => InputManager.Key(Key.Escape));
|
2022-05-11 14:51:00 +08:00
|
|
|
AddUntilStep("wait for dismiss", () => !this.ChildrenOfType<SamplePointPiece.SampleEditPopover>().Any(popover => popover.IsPresent));
|
2021-11-13 23:58:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setVolumeViaPopover(int volume) => AddStep($"set volume {volume} via popover", () =>
|
|
|
|
{
|
|
|
|
var popover = this.ChildrenOfType<SamplePointPiece.SampleEditPopover>().Single();
|
2021-11-14 00:21:48 +08:00
|
|
|
var slider = popover.ChildrenOfType<IndeterminateSliderWithTextBoxInput<int>>().Single();
|
2021-11-13 23:58:24 +08:00
|
|
|
slider.Current.Value = volume;
|
|
|
|
});
|
|
|
|
|
|
|
|
private void hitObjectHasSampleVolume(int objectIndex, int volume) => AddAssert($"{objectIndex.ToOrdinalWords()} has volume {volume}", () =>
|
|
|
|
{
|
|
|
|
var h = EditorBeatmap.HitObjects.ElementAt(objectIndex);
|
|
|
|
return h.SampleControlPoint.SampleVolume == volume;
|
|
|
|
});
|
|
|
|
|
|
|
|
private void setBankViaPopover(string bank) => AddStep($"set bank {bank} via popover", () =>
|
|
|
|
{
|
|
|
|
var popover = this.ChildrenOfType<SamplePointPiece.SampleEditPopover>().Single();
|
|
|
|
var textBox = popover.ChildrenOfType<LabelledTextBox>().First();
|
|
|
|
textBox.Current.Value = bank;
|
2021-11-14 01:06:32 +08:00
|
|
|
// force a commit via keyboard.
|
|
|
|
// this is needed when testing attempting to set empty bank - which should revert to the previous value, but only on commit.
|
|
|
|
InputManager.ChangeFocus(textBox);
|
|
|
|
InputManager.Key(Key.Enter);
|
2021-11-13 23:58:24 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
private void hitObjectHasSampleBank(int objectIndex, string bank) => AddAssert($"{objectIndex.ToOrdinalWords()} has bank {bank}", () =>
|
|
|
|
{
|
|
|
|
var h = EditorBeatmap.HitObjects.ElementAt(objectIndex);
|
|
|
|
return h.SampleControlPoint.SampleBank == bank;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|