2021-02-02 20:35:08 +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.
|
|
|
|
|
2023-09-27 17:54:47 +08:00
|
|
|
using System.Collections.Generic;
|
2021-09-10 11:43:12 +08:00
|
|
|
using System.Linq;
|
2021-02-02 20:35:08 +08:00
|
|
|
using NUnit.Framework;
|
2022-07-12 13:32:39 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2023-09-27 17:54:47 +08:00
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Framework.Utils;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2021-09-10 11:43:12 +08:00
|
|
|
using osu.Game.Rulesets.Osu;
|
2021-02-02 20:35:08 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Mods;
|
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
{
|
|
|
|
public partial class TestSceneModIcon : OsuTestScene
|
|
|
|
{
|
2022-07-12 13:32:39 +08:00
|
|
|
[Test]
|
|
|
|
public void TestShowAllMods()
|
|
|
|
{
|
|
|
|
AddStep("create mod icons", () =>
|
|
|
|
{
|
|
|
|
Child = new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Full,
|
|
|
|
ChildrenEnumerable = Ruleset.Value.CreateInstance().CreateAllMods().Select(m => new ModIcon(m)),
|
|
|
|
};
|
|
|
|
});
|
2023-09-27 17:54:47 +08:00
|
|
|
|
|
|
|
AddStep("toggle selected", () =>
|
|
|
|
{
|
|
|
|
foreach (var icon in this.ChildrenOfType<ModIcon>())
|
|
|
|
icon.Selected.Toggle();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestShowRateAdjusts()
|
|
|
|
{
|
|
|
|
AddStep("create mod icons", () =>
|
|
|
|
{
|
|
|
|
Child = new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Full,
|
|
|
|
ChildrenEnumerable = Ruleset.Value.CreateInstance().CreateAllMods()
|
|
|
|
.OfType<ModRateAdjust>()
|
2023-09-28 15:19:06 +08:00
|
|
|
.SelectMany(m =>
|
2023-09-27 17:54:47 +08:00
|
|
|
{
|
|
|
|
List<ModIcon> icons = new List<ModIcon> { new ModIcon(m) };
|
|
|
|
|
|
|
|
for (double i = m.SpeedChange.MinValue; i < m.SpeedChange.MaxValue; i += m.SpeedChange.Precision * 10)
|
|
|
|
{
|
|
|
|
m = (ModRateAdjust)m.DeepClone();
|
|
|
|
m.SpeedChange.Value = i;
|
|
|
|
icons.Add(new ModIcon(m));
|
|
|
|
}
|
|
|
|
|
|
|
|
return icons;
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("adjust rates", () =>
|
|
|
|
{
|
|
|
|
foreach (var icon in this.ChildrenOfType<ModIcon>())
|
|
|
|
{
|
|
|
|
if (icon.Mod is ModRateAdjust rateAdjust)
|
|
|
|
{
|
2023-09-28 15:19:06 +08:00
|
|
|
rateAdjust.SpeedChange.Value = RNG.NextDouble() > 0.9
|
|
|
|
? rateAdjust.SpeedChange.Default
|
|
|
|
: RNG.NextDouble(rateAdjust.SpeedChange.MinValue, rateAdjust.SpeedChange.MaxValue);
|
2023-09-27 17:54:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2022-07-12 13:32:39 +08:00
|
|
|
}
|
|
|
|
|
2021-02-02 20:35:08 +08:00
|
|
|
[Test]
|
|
|
|
public void TestChangeModType()
|
|
|
|
{
|
2022-07-12 13:32:39 +08:00
|
|
|
ModIcon icon = null!;
|
2021-02-02 20:35:08 +08:00
|
|
|
|
|
|
|
AddStep("create mod icon", () => Child = icon = new ModIcon(new OsuModDoubleTime()));
|
|
|
|
AddStep("change mod", () => icon.Mod = new OsuModEasy());
|
|
|
|
}
|
2021-09-10 11:43:12 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestInterfaceModType()
|
|
|
|
{
|
2022-07-12 13:32:39 +08:00
|
|
|
ModIcon icon = null!;
|
2021-09-10 11:43:12 +08:00
|
|
|
|
|
|
|
var ruleset = new OsuRuleset();
|
|
|
|
|
|
|
|
AddStep("create mod icon", () => Child = icon = new ModIcon(ruleset.AllMods.First(m => m.Acronym == "DT")));
|
|
|
|
AddStep("change mod", () => icon.Mod = ruleset.AllMods.First(m => m.Acronym == "EZ"));
|
|
|
|
}
|
2021-02-02 20:35:08 +08:00
|
|
|
}
|
|
|
|
}
|