2022-07-22 04:01:03 +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-07-24 05:24:30 +08:00
|
|
|
using System;
|
2022-07-22 04:01:03 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2022-07-24 05:08:05 +08:00
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2022-07-22 04:01:03 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-07-24 05:24:30 +08:00
|
|
|
using osu.Framework.Testing;
|
2022-07-24 00:01:11 +08:00
|
|
|
using osu.Game.Database;
|
2022-07-22 04:01:03 +08:00
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Game.Overlays.Mods;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2022-07-24 03:29:30 +08:00
|
|
|
using osu.Game.Rulesets.Osu;
|
2022-07-22 04:01:03 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Mods;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2022-11-24 13:32:20 +08:00
|
|
|
public partial class TestSceneModPresetPanel : OsuTestScene
|
2022-07-22 04:01:03 +08:00
|
|
|
{
|
|
|
|
[Cached]
|
|
|
|
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);
|
|
|
|
|
2022-07-24 05:24:30 +08:00
|
|
|
[SetUpSteps]
|
|
|
|
public void SetUpSteps()
|
|
|
|
{
|
|
|
|
AddStep("reset selected mods", () => SelectedMods.SetDefault());
|
|
|
|
}
|
|
|
|
|
2022-07-22 04:01:03 +08:00
|
|
|
[Test]
|
|
|
|
public void TestVariousModPresets()
|
|
|
|
{
|
|
|
|
AddStep("create content", () => Child = new FillFlowContainer
|
|
|
|
{
|
|
|
|
Width = 300,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Spacing = new Vector2(0, 5),
|
2022-07-24 00:01:11 +08:00
|
|
|
ChildrenEnumerable = createTestPresets().Select(preset => new ModPresetPanel(preset.ToLiveUnmanaged()))
|
2022-07-22 04:01:03 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-07-24 05:08:05 +08:00
|
|
|
[Test]
|
|
|
|
public void TestPresetSelectionStateAfterExternalModChanges()
|
|
|
|
{
|
|
|
|
ModPresetPanel? panel = null;
|
|
|
|
|
|
|
|
AddStep("create panel", () => Child = panel = new ModPresetPanel(createTestPresets().First().ToLiveUnmanaged())
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Width = 0.5f
|
|
|
|
});
|
|
|
|
AddAssert("panel is not active", () => !panel.AsNonNull().Active.Value);
|
|
|
|
|
|
|
|
AddStep("set mods to HR", () => SelectedMods.Value = new[] { new OsuModHardRock() });
|
|
|
|
AddAssert("panel is not active", () => !panel.AsNonNull().Active.Value);
|
|
|
|
|
|
|
|
AddStep("set mods to DT", () => SelectedMods.Value = new[] { new OsuModDoubleTime() });
|
|
|
|
AddAssert("panel is not active", () => !panel.AsNonNull().Active.Value);
|
|
|
|
|
|
|
|
AddStep("set mods to HR+DT", () => SelectedMods.Value = new Mod[] { new OsuModHardRock(), new OsuModDoubleTime() });
|
|
|
|
AddAssert("panel is active", () => panel.AsNonNull().Active.Value);
|
|
|
|
|
|
|
|
AddStep("set mods to HR+customised DT", () => SelectedMods.Value = new Mod[]
|
|
|
|
{
|
|
|
|
new OsuModHardRock(),
|
|
|
|
new OsuModDoubleTime
|
|
|
|
{
|
|
|
|
SpeedChange = { Value = 1.25 }
|
|
|
|
}
|
|
|
|
});
|
|
|
|
AddAssert("panel is not active", () => !panel.AsNonNull().Active.Value);
|
|
|
|
|
|
|
|
AddStep("set mods to HR+DT", () => SelectedMods.Value = new Mod[] { new OsuModHardRock(), new OsuModDoubleTime() });
|
|
|
|
AddAssert("panel is active", () => panel.AsNonNull().Active.Value);
|
|
|
|
|
|
|
|
AddStep("customise mod in place", () => SelectedMods.Value.OfType<OsuModDoubleTime>().Single().SpeedChange.Value = 1.33);
|
|
|
|
AddAssert("panel is not active", () => !panel.AsNonNull().Active.Value);
|
|
|
|
|
|
|
|
AddStep("set mods to HD+HR+DT", () => SelectedMods.Value = new Mod[] { new OsuModHidden(), new OsuModHardRock(), new OsuModDoubleTime() });
|
|
|
|
AddAssert("panel is not active", () => !panel.AsNonNull().Active.Value);
|
2023-11-06 14:56:09 +08:00
|
|
|
|
|
|
|
// system mods are not included in presets.
|
|
|
|
AddStep("set mods to HR+DT+TD", () => SelectedMods.Value = new Mod[] { new OsuModHardRock(), new OsuModDoubleTime(), new OsuModTouchDevice() });
|
|
|
|
AddAssert("panel is active", () => panel.AsNonNull().Active.Value);
|
2022-07-24 05:08:05 +08:00
|
|
|
}
|
|
|
|
|
2022-07-24 05:24:30 +08:00
|
|
|
[Test]
|
|
|
|
public void TestActivatingPresetTogglesIncludedMods()
|
|
|
|
{
|
|
|
|
ModPresetPanel? panel = null;
|
|
|
|
|
|
|
|
AddStep("create panel", () => Child = panel = new ModPresetPanel(createTestPresets().First().ToLiveUnmanaged())
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Width = 0.5f
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("activate panel", () => panel.AsNonNull().TriggerClick());
|
|
|
|
assertSelectedModsEquivalentTo(new Mod[] { new OsuModHardRock(), new OsuModDoubleTime() });
|
|
|
|
|
|
|
|
AddStep("deactivate panel", () => panel.AsNonNull().TriggerClick());
|
|
|
|
assertSelectedModsEquivalentTo(Array.Empty<Mod>());
|
|
|
|
|
|
|
|
AddStep("set different mod", () => SelectedMods.Value = new[] { new OsuModHidden() });
|
|
|
|
AddStep("activate panel", () => panel.AsNonNull().TriggerClick());
|
|
|
|
assertSelectedModsEquivalentTo(new Mod[] { new OsuModHardRock(), new OsuModDoubleTime() });
|
|
|
|
|
|
|
|
AddStep("set customised mod", () => SelectedMods.Value = new[] { new OsuModDoubleTime { SpeedChange = { Value = 1.25 } } });
|
|
|
|
AddStep("activate panel", () => panel.AsNonNull().TriggerClick());
|
|
|
|
assertSelectedModsEquivalentTo(new Mod[] { new OsuModHardRock(), new OsuModDoubleTime { SpeedChange = { Value = 1.5 } } });
|
2023-11-06 14:56:09 +08:00
|
|
|
|
|
|
|
AddStep("set system mod", () => SelectedMods.Value = new[] { new OsuModTouchDevice() });
|
|
|
|
AddStep("activate panel", () => panel.AsNonNull().TriggerClick());
|
|
|
|
assertSelectedModsEquivalentTo(new Mod[] { new OsuModTouchDevice(), new OsuModHardRock(), new OsuModDoubleTime { SpeedChange = { Value = 1.5 } } });
|
2022-07-24 05:24:30 +08:00
|
|
|
}
|
|
|
|
|
2024-05-04 18:43:04 +08:00
|
|
|
[Test]
|
|
|
|
public void TestActivatingPresetWithAutoplayWhenSystemModEnabled()
|
|
|
|
{
|
|
|
|
ModPresetPanel? panel = null;
|
|
|
|
|
|
|
|
AddStep("create panel", () => Child = panel = new ModPresetPanel(new ModPreset
|
|
|
|
{
|
|
|
|
Name = "Autoplay include",
|
|
|
|
Description = "no way",
|
|
|
|
Mods = new Mod[]
|
|
|
|
{
|
|
|
|
new OsuModAutoplay()
|
|
|
|
},
|
|
|
|
Ruleset = new OsuRuleset().RulesetInfo
|
|
|
|
}.ToLiveUnmanaged())
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Width = 0.5f
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("Add touch device to selected mod", () => SelectedMods.Value = new Mod[] { new OsuModTouchDevice() });
|
|
|
|
AddStep("activate panel", () => panel.AsNonNull().TriggerClick());
|
|
|
|
|
|
|
|
// touch device should be removed due to incompatible with autoplay.
|
|
|
|
assertSelectedModsEquivalentTo(new Mod[] { new OsuModAutoplay() });
|
2024-05-04 20:02:35 +08:00
|
|
|
|
|
|
|
AddStep("deactivate panel", () => panel.AsNonNull().TriggerClick());
|
|
|
|
assertSelectedModsEquivalentTo(Array.Empty<Mod>());
|
|
|
|
|
|
|
|
// just for test purpose
|
|
|
|
AddStep("Add score v2 to selected mod", () => SelectedMods.Value = new Mod[] { new ModScoreV2() });
|
|
|
|
AddStep("activate panel", () => panel.AsNonNull().TriggerClick());
|
|
|
|
|
|
|
|
assertSelectedModsEquivalentTo(new Mod[] { new OsuModAutoplay(), new ModScoreV2() });
|
2024-05-04 18:43:04 +08:00
|
|
|
}
|
|
|
|
|
2022-07-24 05:24:30 +08:00
|
|
|
private void assertSelectedModsEquivalentTo(IEnumerable<Mod> mods)
|
|
|
|
=> AddAssert("selected mods changed correctly", () => new HashSet<Mod>(SelectedMods.Value).SetEquals(mods));
|
|
|
|
|
2022-07-22 04:01:03 +08:00
|
|
|
private static IEnumerable<ModPreset> createTestPresets() => new[]
|
|
|
|
{
|
|
|
|
new ModPreset
|
|
|
|
{
|
|
|
|
Name = "First preset",
|
|
|
|
Description = "Please ignore",
|
|
|
|
Mods = new Mod[]
|
|
|
|
{
|
|
|
|
new OsuModHardRock(),
|
|
|
|
new OsuModDoubleTime()
|
2022-07-24 03:29:30 +08:00
|
|
|
},
|
|
|
|
Ruleset = new OsuRuleset().RulesetInfo
|
2022-07-22 04:01:03 +08:00
|
|
|
},
|
|
|
|
new ModPreset
|
|
|
|
{
|
|
|
|
Name = "AR0",
|
|
|
|
Description = "For good readers",
|
|
|
|
Mods = new Mod[]
|
|
|
|
{
|
|
|
|
new OsuModDifficultyAdjust
|
|
|
|
{
|
|
|
|
ApproachRate = { Value = 0 }
|
|
|
|
}
|
2022-07-24 03:29:30 +08:00
|
|
|
},
|
|
|
|
Ruleset = new OsuRuleset().RulesetInfo
|
2022-07-22 04:01:03 +08:00
|
|
|
},
|
|
|
|
new ModPreset
|
|
|
|
{
|
|
|
|
Name = "This preset is going to have an extraordinarily long name",
|
|
|
|
Description = "This is done so that the capability to truncate overlong texts may be demonstrated",
|
|
|
|
Mods = new Mod[]
|
|
|
|
{
|
|
|
|
new OsuModFlashlight(),
|
|
|
|
new OsuModSpinIn()
|
2022-07-24 03:29:30 +08:00
|
|
|
},
|
|
|
|
Ruleset = new OsuRuleset().RulesetInfo
|
2022-07-22 04:01:03 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|