1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 06:07:28 +08:00
osu-lazer/osu.Game.Tests/Visual/UserInterface/TestSceneModSettings.cs

247 lines
9.4 KiB
C#
Raw Normal View History

2019-11-05 00:56:09 +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.
2019-12-06 19:14:56 +08:00
using System;
2019-12-12 16:12:01 +08:00
using System.Collections.Generic;
2019-11-05 00:56:09 +08:00
using System.Linq;
2019-12-12 16:12:01 +08:00
using NUnit.Framework;
2019-11-05 00:56:09 +08:00
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2020-08-13 18:48:31 +08:00
using osu.Framework.Utils;
2020-10-14 01:20:15 +08:00
using osu.Framework.Testing;
2019-12-12 16:12:01 +08:00
using osu.Game.Beatmaps;
using osu.Game.Configuration;
2019-11-05 00:56:09 +08:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Mods;
2019-12-12 16:12:01 +08:00
using osu.Game.Rulesets;
using osu.Game.Rulesets.Difficulty;
2019-11-05 00:56:09 +08:00
using osu.Game.Rulesets.Mods;
2020-08-13 18:48:31 +08:00
using osu.Game.Rulesets.Osu.Mods;
2019-12-12 16:12:01 +08:00
using osu.Game.Rulesets.UI;
using osuTK.Input;
2019-11-05 00:56:09 +08:00
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneModSettings : OsuManualInputManagerTestScene
2019-11-05 00:56:09 +08:00
{
private TestModSelectOverlay modSelect;
2019-12-12 16:36:37 +08:00
private readonly Mod testCustomisableMod = new TestModCustomisable1();
2019-11-05 00:56:09 +08:00
2020-01-21 22:32:53 +08:00
private readonly Mod testCustomisableAutoOpenMod = new TestModCustomisable2();
2020-01-21 18:26:51 +08:00
2020-01-30 18:55:25 +08:00
[SetUp]
public void SetUp() => Schedule(() =>
{
SelectedMods.Value = Array.Empty<Mod>();
Ruleset.Value = new TestRulesetInfo();
});
2019-12-12 16:12:01 +08:00
[Test]
public void TestButtonShowsOnCustomisableMod()
{
createModSelect();
2020-02-09 21:39:27 +08:00
openModSelect();
2019-11-05 00:56:09 +08:00
2019-12-06 17:57:11 +08:00
AddAssert("button disabled", () => !modSelect.CustomiseButton.Enabled.Value);
2019-12-06 18:04:55 +08:00
AddUntilStep("wait for button load", () => modSelect.ButtonsLoaded);
2019-12-12 16:12:01 +08:00
AddStep("select mod", () => modSelect.SelectMod(testCustomisableMod));
2019-12-06 17:57:11 +08:00
AddAssert("button enabled", () => modSelect.CustomiseButton.Enabled.Value);
2021-08-04 16:27:44 +08:00
AddStep("open Customisation", () => modSelect.CustomiseButton.TriggerClick());
2019-12-12 16:12:01 +08:00
AddStep("deselect mod", () => modSelect.SelectMod(testCustomisableMod));
2020-12-07 05:18:19 +08:00
AddAssert("controls hidden", () => modSelect.ModSettingsContainer.State.Value == Visibility.Hidden);
2019-11-05 00:56:09 +08:00
}
2019-12-12 16:12:01 +08:00
[Test]
public void TestButtonShowsOnModAlreadyAdded()
{
2019-12-13 20:45:38 +08:00
AddStep("set active mods", () => SelectedMods.Value = new List<Mod> { testCustomisableMod });
2019-12-12 16:12:01 +08:00
createModSelect();
2019-12-13 20:45:38 +08:00
AddAssert("mods still active", () => SelectedMods.Value.Count == 1);
2019-12-12 16:12:01 +08:00
2020-02-09 21:39:27 +08:00
openModSelect();
2019-12-12 16:12:01 +08:00
AddAssert("button enabled", () => modSelect.CustomiseButton.Enabled.Value);
}
2020-01-21 18:26:51 +08:00
[Test]
public void TestCustomisationMenuVisibility()
2020-01-21 18:26:51 +08:00
{
createModSelect();
2020-02-09 21:39:27 +08:00
openModSelect();
2020-01-21 18:26:51 +08:00
2020-12-07 05:18:19 +08:00
AddAssert("Customisation closed", () => modSelect.ModSettingsContainer.State.Value == Visibility.Hidden);
2020-01-21 18:26:51 +08:00
AddStep("select mod", () => modSelect.SelectMod(testCustomisableAutoOpenMod));
2020-12-07 05:18:19 +08:00
AddAssert("Customisation opened", () => modSelect.ModSettingsContainer.State.Value == Visibility.Visible);
AddStep("deselect mod", () => modSelect.SelectMod(testCustomisableAutoOpenMod));
2020-12-07 05:18:19 +08:00
AddAssert("Customisation closed", () => modSelect.ModSettingsContainer.State.Value == Visibility.Hidden);
2020-01-21 18:26:51 +08:00
}
2020-08-13 18:48:31 +08:00
[Test]
public void TestModSettingsUnboundWhenCopied()
{
OsuModDoubleTime original = null;
OsuModDoubleTime copy = null;
AddStep("create mods", () =>
{
original = new OsuModDoubleTime();
copy = (OsuModDoubleTime)original.DeepClone();
2020-08-13 18:48:31 +08:00
});
AddStep("change property", () => original.SpeedChange.Value = 2);
AddAssert("original has new value", () => Precision.AlmostEquals(2.0, original.SpeedChange.Value));
AddAssert("copy has original value", () => Precision.AlmostEquals(1.5, copy.SpeedChange.Value));
}
[Test]
public void TestMultiModSettingsUnboundWhenCopied()
{
MultiMod original = null;
MultiMod copy = null;
AddStep("create mods", () =>
{
original = new MultiMod(new OsuModDoubleTime());
copy = (MultiMod)original.DeepClone();
});
AddStep("change property", () => ((OsuModDoubleTime)original.Mods[0]).SpeedChange.Value = 2);
AddAssert("original has new value", () => Precision.AlmostEquals(2.0, ((OsuModDoubleTime)original.Mods[0]).SpeedChange.Value));
AddAssert("copy has original value", () => Precision.AlmostEquals(1.5, ((OsuModDoubleTime)copy.Mods[0]).SpeedChange.Value));
}
[Test]
public void TestCustomisationMenuNoClickthrough()
{
createModSelect();
openModSelect();
AddStep("change mod settings menu width to full screen", () => modSelect.SetModSettingsWidth(1.0f));
AddStep("select cm2", () => modSelect.SelectMod(testCustomisableAutoOpenMod));
2020-12-07 05:18:19 +08:00
AddAssert("Customisation opened", () => modSelect.ModSettingsContainer.State.Value == Visibility.Visible);
2020-10-14 01:20:15 +08:00
AddStep("hover over mod behind settings menu", () => InputManager.MoveMouseTo(modSelect.GetModButton(testCustomisableMod)));
AddAssert("Mod is not considered hovered over", () => !modSelect.GetModButton(testCustomisableMod).IsHovered);
AddStep("left click mod", () => InputManager.Click(MouseButton.Left));
AddAssert("only cm2 is active", () => SelectedMods.Value.Count == 1);
AddStep("right click mod", () => InputManager.Click(MouseButton.Right));
AddAssert("only cm2 is active", () => SelectedMods.Value.Count == 1);
}
2019-12-12 16:12:01 +08:00
private void createModSelect()
{
AddStep("create mod select", () =>
{
Child = modSelect = new TestModSelectOverlay
{
Origin = Anchor.BottomCentre,
Anchor = Anchor.BottomCentre,
2020-01-30 18:55:25 +08:00
SelectedMods = { BindTarget = SelectedMods }
2019-12-12 16:12:01 +08:00
};
});
}
2020-02-09 21:39:27 +08:00
private void openModSelect()
{
AddStep("open", () => modSelect.Show());
AddUntilStep("wait for ready", () => modSelect.State.Value == Visibility.Visible && modSelect.ButtonsLoaded);
}
private class TestModSelectOverlay : UserModSelectOverlay
2019-11-05 00:56:09 +08:00
{
2020-12-07 05:18:19 +08:00
public new VisibilityContainer ModSettingsContainer => base.ModSettingsContainer;
2019-12-06 17:57:11 +08:00
public new TriangleButton CustomiseButton => base.CustomiseButton;
2019-11-05 00:56:09 +08:00
2019-12-06 18:04:55 +08:00
public bool ButtonsLoaded => ModSectionsContainer.Children.All(c => c.ModIconsLoaded);
public ModButton GetModButton(Mod mod)
{
2020-10-14 01:20:15 +08:00
return ModSectionsContainer.ChildrenOfType<ModButton>().Single(b => b.Mods.Any(m => m.GetType() == mod.GetType()));
}
2020-10-12 21:58:34 +08:00
public void SelectMod(Mod mod) =>
GetModButton(mod).SelectNext(1);
2020-10-14 01:20:15 +08:00
public void SetModSettingsWidth(float newWidth) =>
ModSettingsContainer.Parent.Width = newWidth;
2019-12-12 16:12:01 +08:00
}
2019-11-05 00:56:09 +08:00
2019-12-12 16:12:01 +08:00
public class TestRulesetInfo : RulesetInfo
{
public override Ruleset CreateInstance() => new TestCustomisableModRuleset();
2019-11-05 00:56:09 +08:00
2019-12-15 02:01:37 +08:00
public TestRulesetInfo()
{
Available = true;
}
2019-12-12 16:12:01 +08:00
public class TestCustomisableModRuleset : Ruleset
{
public override IEnumerable<Mod> GetModsFor(ModType type)
{
2019-12-12 16:12:01 +08:00
if (type == ModType.Conversion)
{
2019-12-12 16:12:01 +08:00
return new Mod[]
{
2019-12-06 17:57:11 +08:00
new TestModCustomisable1(),
2020-01-21 22:32:53 +08:00
new TestModCustomisable2()
};
}
2019-12-12 16:12:01 +08:00
return Array.Empty<Mod>();
}
2019-12-12 16:12:01 +08:00
2019-12-13 20:45:38 +08:00
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null) => throw new NotImplementedException();
2019-12-12 16:12:01 +08:00
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => throw new NotImplementedException();
public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => throw new NotImplementedException();
2019-12-12 16:36:37 +08:00
public override string Description { get; } = "test";
public override string ShortName { get; } = "tst";
2019-11-05 00:56:09 +08:00
}
}
2019-12-06 17:57:11 +08:00
private class TestModCustomisable1 : TestModCustomisable
2019-11-05 00:56:09 +08:00
{
2019-12-06 17:57:11 +08:00
public override string Name => "Customisable Mod 1";
2019-11-05 00:56:09 +08:00
public override string Acronym => "CM1";
}
2019-11-05 00:56:09 +08:00
2019-12-06 17:57:11 +08:00
private class TestModCustomisable2 : TestModCustomisable
{
2019-12-06 17:57:11 +08:00
public override string Name => "Customisable Mod 2";
public override string Acronym => "CM2";
2020-01-21 18:26:51 +08:00
public override bool RequiresConfiguration => true;
}
2019-12-06 17:57:11 +08:00
private abstract class TestModCustomisable : Mod, IApplicableMod
{
2019-11-05 00:56:09 +08:00
public override double ScoreMultiplier => 1.0;
public override string Description => "This is a customisable test mod.";
2019-11-05 00:56:09 +08:00
public override ModType Type => ModType.Conversion;
[SettingSource("Sample float", "Change something for a mod")]
public BindableFloat SliderBindable { get; } = new BindableFloat
2019-11-05 00:56:09 +08:00
{
MinValue = 0,
MaxValue = 10,
Default = 5,
Value = 7
2019-11-05 00:56:09 +08:00
};
[SettingSource("Sample bool", "Clicking this changes a setting")]
public BindableBool TickBindable { get; } = new BindableBool();
2019-11-05 00:56:09 +08:00
}
}
}