1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 20:53:04 +08:00

Add multiple mod testing and update test code style

This commit is contained in:
Dean Herbert 2019-12-06 15:42:11 +09:00
parent 170954bc6e
commit af35df4077
2 changed files with 34 additions and 24 deletions

View File

@ -27,7 +27,7 @@ namespace osu.Game.Tests.Visual.UserInterface
Anchor = Anchor.BottomCentre, Anchor = Anchor.BottomCentre,
}); });
var testMod = new TestModCustomizable(); var testMod = new TestModCustomizable1();
AddStep("open", modSelect.Show); AddStep("open", modSelect.Show);
AddAssert("button disabled", () => !modSelect.CustomizeButton.Enabled.Value); AddAssert("button disabled", () => !modSelect.CustomizeButton.Enabled.Value);
@ -44,64 +44,74 @@ namespace osu.Game.Tests.Visual.UserInterface
public new TriangleButton CustomizeButton => base.CustomizeButton; public new TriangleButton CustomizeButton => base.CustomizeButton;
public void SelectMod(Mod mod) => public void SelectMod(Mod mod) =>
ModSectionsContainer.Children.Single((s) => s.ModType == mod.Type) ModSectionsContainer.Children.Single(s => s.ModType == mod.Type)
.ButtonsContainer.OfType<ModButton>().Single(b => b.Mods.Any(m => m.GetType() == mod.GetType())).SelectNext(1); .ButtonsContainer.OfType<ModButton>().Single(b => b.Mods.Any(m => m.GetType() == mod.GetType())).SelectNext(1);
public ModControlSection GetControlSection(Mod mod) => public ModControlSection GetControlSection(Mod mod) =>
ModSettingsContent.Children.FirstOrDefault((s) => s.Mod == mod); ModSettingsContent.Children.FirstOrDefault(s => s.Mod == mod);
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
foreach (var section in ModSectionsContainer) foreach (var section in ModSectionsContainer)
{
if (section.ModType == ModType.Conversion) if (section.ModType == ModType.Conversion)
section.Mods = new Mod[] { new TestModCustomizable() }; {
section.Mods = new Mod[]
{
new TestModCustomizable1(),
new TestModCustomizable2()
};
}
else else
section.Mods = new Mod[] { }; section.Mods = new Mod[] { };
}
} }
} }
private class TestModCustomizable : Mod, IModHasSettings private class TestModCustomizable1 : TestModCustomizable
{ {
public override string Name => "Customizable Mod"; public override string Name => "Customizable Mod 1";
public override string Acronym => "CM"; public override string Acronym => "CM1";
}
private class TestModCustomizable2 : TestModCustomizable
{
public override string Name => "Customizable Mod 2";
public override string Acronym => "CM2";
}
private abstract class TestModCustomizable : Mod, IModHasSettings
{
public override double ScoreMultiplier => 1.0; public override double ScoreMultiplier => 1.0;
public override ModType Type => ModType.Conversion; public override ModType Type => ModType.Conversion;
public readonly BindableFloat sliderBindable = new BindableFloat public readonly BindableFloat SliderBindable = new BindableFloat
{ {
MinValue = 0, MinValue = 0,
MaxValue = 10, MaxValue = 10,
}; };
public readonly BindableBool tickBindable = new BindableBool(); public readonly BindableBool TickBindable = new BindableBool();
public Drawable[] CreateControls() public Drawable[] CreateControls() =>
{ new Drawable[]
BindableFloat sliderControl = new BindableFloat();
BindableBool tickControl = new BindableBool();
sliderControl.BindTo(sliderBindable);
tickControl.BindTo(tickBindable);
return new Drawable[]
{ {
new SettingsSlider<float> new SettingsSlider<float>
{ {
LabelText = "Slider", LabelText = "Slider",
Bindable = sliderControl Bindable = SliderBindable
}, },
new SettingsCheckbox new SettingsCheckbox
{ {
LabelText = "Checkbox", LabelText = "Checkbox",
Bindable = tickControl Bindable = TickBindable
} }
}; };
}
} }
} }
} }

View File

@ -345,7 +345,7 @@ namespace osu.Game.Overlays.Mods
if (added is IModHasSettings) if (added is IModHasSettings)
ModSettingsContent.Add(new ModControlSection(added)); ModSettingsContent.Add(new ModControlSection(added));
else if (removed is IModHasSettings) else if (removed is IModHasSettings)
ModSettingsContent.Remove(ModSettingsContent.Children.Where(section => section.Mod == removed).Single()); ModSettingsContent.Remove(ModSettingsContent.Children.Single(section => section.Mod == removed));
CustomizeButton.Enabled.Value = ModSettingsContent.Children.Count > 0; CustomizeButton.Enabled.Value = ModSettingsContent.Children.Count > 0;