mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 06:36:31 +09:00
Merge remote-tracking branch 'refs/remotes/origin/master' into multiplier-text
This commit is contained in:
@ -157,7 +157,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
|
||||
private TimingControlPoint getNextTimingPoint(TimingControlPoint current)
|
||||
{
|
||||
if (timingPoints[timingPoints.Count - 1] == current)
|
||||
if (timingPoints[^1] == current)
|
||||
return current;
|
||||
|
||||
int index = timingPoints.IndexOf(current); // -1 means that this is a "default beat"
|
||||
@ -169,7 +169,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
if (timingPoints.Count == 0) return 0;
|
||||
|
||||
if (timingPoints[timingPoints.Count - 1] == current)
|
||||
if (timingPoints[^1] == current)
|
||||
return (int)Math.Ceiling((Beatmap.Value.Track.Length - current.Time) / current.BeatLength);
|
||||
|
||||
return (int)Math.Ceiling((getNextTimingPoint(current).Time - current.Time) / current.BeatLength);
|
||||
|
@ -8,13 +8,16 @@ using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Overlays.Mods;
|
||||
using osu.Game.Overlays.Mods.Sections;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mania;
|
||||
using osu.Game.Rulesets.Mania.Mods;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Rulesets.Osu.Mods;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Screens.Play.HUD;
|
||||
@ -48,42 +51,48 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
private void load(RulesetStore rulesets)
|
||||
{
|
||||
this.rulesets = rulesets;
|
||||
}
|
||||
|
||||
Add(modSelect = new TestModSelectOverlay
|
||||
[SetUp]
|
||||
public void SetUp() => Schedule(() =>
|
||||
{
|
||||
Children = new Drawable[]
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Origin = Anchor.BottomCentre,
|
||||
Anchor = Anchor.BottomCentre,
|
||||
});
|
||||
modSelect = new TestModSelectOverlay
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Origin = Anchor.BottomCentre,
|
||||
Anchor = Anchor.BottomCentre,
|
||||
},
|
||||
|
||||
Add(modDisplay = new ModDisplay
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Position = new Vector2(0, 25),
|
||||
});
|
||||
modDisplay = new ModDisplay
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Position = new Vector2(0, 25),
|
||||
Current = { BindTarget = modSelect.SelectedMods }
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
modDisplay.Current.UnbindBindings();
|
||||
modDisplay.Current.BindTo(modSelect.SelectedMods);
|
||||
|
||||
AddStep("Show", modSelect.Show);
|
||||
AddStep("Toggle", modSelect.ToggleVisibility);
|
||||
AddStep("Toggle", modSelect.ToggleVisibility);
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
AddStep("show", () => modSelect.Show());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestOsuMods()
|
||||
{
|
||||
var ruleset = rulesets.AvailableRulesets.First(r => r.ID == 0);
|
||||
changeRuleset(ruleset);
|
||||
changeRuleset(0);
|
||||
|
||||
var instance = ruleset.CreateInstance();
|
||||
var osu = new OsuRuleset();
|
||||
|
||||
var easierMods = instance.GetModsFor(ModType.DifficultyReduction);
|
||||
var harderMods = instance.GetModsFor(ModType.DifficultyIncrease);
|
||||
var easierMods = osu.GetModsFor(ModType.DifficultyReduction);
|
||||
var harderMods = osu.GetModsFor(ModType.DifficultyIncrease);
|
||||
|
||||
var noFailMod = easierMods.FirstOrDefault(m => m is OsuModNoFail);
|
||||
var noFailMod = osu.GetModsFor(ModType.DifficultyReduction).FirstOrDefault(m => m is OsuModNoFail);
|
||||
var hiddenMod = harderMods.FirstOrDefault(m => m is OsuModHidden);
|
||||
|
||||
var doubleTimeMod = harderMods.OfType<MultiMod>().FirstOrDefault(m => m.Mods.Any(a => a is OsuModDoubleTime));
|
||||
@ -97,8 +106,8 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
testMultiMod(doubleTimeMod);
|
||||
testIncompatibleMods(easy, hardRock);
|
||||
testDeselectAll(easierMods.Where(m => !(m is MultiMod)));
|
||||
testMultiplierTextColour(noFailMod, modSelect.LowMultiplierColour);
|
||||
testMultiplierTextColour(hiddenMod, modSelect.HighMultiplierColour);
|
||||
testMultiplierTextColour(noFailMod, () => modSelect.LowMultiplierColour);
|
||||
testMultiplierTextColour(hiddenMod, () => modSelect.HighMultiplierColour);
|
||||
|
||||
testUnimplementedMod(spunOutMod);
|
||||
}
|
||||
@ -106,37 +115,31 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
[Test]
|
||||
public void TestManiaMods()
|
||||
{
|
||||
var ruleset = rulesets.AvailableRulesets.First(r => r.ID == 3);
|
||||
changeRuleset(ruleset);
|
||||
changeRuleset(3);
|
||||
|
||||
testRankedText(ruleset.CreateInstance().GetModsFor(ModType.Conversion).First(m => m is ManiaModRandom));
|
||||
testRankedText(new ManiaRuleset().GetModsFor(ModType.Conversion).First(m => m is ManiaModRandom));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestRulesetChanges()
|
||||
{
|
||||
var rulesetOsu = rulesets.AvailableRulesets.First(r => r.ID == 0);
|
||||
var rulesetMania = rulesets.AvailableRulesets.First(r => r.ID == 3);
|
||||
changeRuleset(0);
|
||||
|
||||
changeRuleset(null);
|
||||
var noFailMod = new OsuRuleset().GetModsFor(ModType.DifficultyReduction).FirstOrDefault(m => m is OsuModNoFail);
|
||||
|
||||
var instance = rulesetOsu.CreateInstance();
|
||||
var easierMods = instance.GetModsFor(ModType.DifficultyReduction);
|
||||
var noFailMod = easierMods.FirstOrDefault(m => m is OsuModNoFail);
|
||||
AddStep("set mods externally", () => { SelectedMods.Value = new[] { noFailMod }; });
|
||||
|
||||
AddStep("set mods externally", () => { modDisplay.Current.Value = new[] { noFailMod }; });
|
||||
|
||||
changeRuleset(rulesetOsu);
|
||||
changeRuleset(0);
|
||||
|
||||
AddAssert("ensure mods still selected", () => modDisplay.Current.Value.Single(m => m is OsuModNoFail) != null);
|
||||
|
||||
changeRuleset(rulesetMania);
|
||||
changeRuleset(3);
|
||||
|
||||
AddAssert("ensure mods not selected", () => !modDisplay.Current.Value.Any(m => m is OsuModNoFail));
|
||||
AddAssert("ensure mods not selected", () => modDisplay.Current.Value.Count == 0);
|
||||
|
||||
changeRuleset(rulesetOsu);
|
||||
changeRuleset(0);
|
||||
|
||||
AddAssert("ensure mods not selected", () => !modDisplay.Current.Value.Any());
|
||||
AddAssert("ensure mods not selected", () => modDisplay.Current.Value.Count == 0);
|
||||
}
|
||||
|
||||
private void testSingleMod(Mod mod)
|
||||
@ -198,19 +201,19 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
selectNext(mod);
|
||||
|
||||
AddAssert("check for any selection", () => modSelect.SelectedMods.Value.Any());
|
||||
AddStep("deselect all", modSelect.DeselectAllButton.Action.Invoke);
|
||||
AddStep("deselect all", () => modSelect.DeselectAllButton.Action.Invoke());
|
||||
AddAssert("check for no selection", () => !modSelect.SelectedMods.Value.Any());
|
||||
}
|
||||
|
||||
private void testMultiplierTextColour(Mod mod, Color4 colour)
|
||||
private void testMultiplierTextColour(Mod mod, Func<Color4> getCorrectColour)
|
||||
{
|
||||
checkLabelColor(Color4.White);
|
||||
checkLabelColor(() => Color4.White);
|
||||
selectNext(mod);
|
||||
AddWaitStep("wait for changing colour", 1);
|
||||
checkLabelColor(colour);
|
||||
checkLabelColor(getCorrectColour);
|
||||
selectPrevious(mod);
|
||||
AddWaitStep("wait for changing colour", 1);
|
||||
checkLabelColor(Color4.White);
|
||||
checkLabelColor(() => Color4.White);
|
||||
}
|
||||
|
||||
private void testRankedText(Mod mod)
|
||||
@ -235,9 +238,9 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
});
|
||||
}
|
||||
|
||||
private void changeRuleset(RulesetInfo ruleset)
|
||||
private void changeRuleset(int? id)
|
||||
{
|
||||
AddStep($"change ruleset to {ruleset}", () => { Ruleset.Value = ruleset; });
|
||||
AddStep($"change ruleset to {(id?.ToString() ?? "none")}", () => { Ruleset.Value = rulesets.AvailableRulesets.FirstOrDefault(r => r.ID == id); });
|
||||
waitForLoad();
|
||||
}
|
||||
|
||||
@ -253,7 +256,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
});
|
||||
}
|
||||
|
||||
private void checkLabelColor(Color4 color) => AddAssert("check label has expected colour", () => modSelect.MultiplierLabel.Colour.AverageColour == color);
|
||||
private void checkLabelColor(Func<Color4> getColour) => AddAssert("check label has expected colour", () => modSelect.MultiplierLabel.Colour.AverageColour == getColour());
|
||||
|
||||
private class TestModSelectOverlay : ModSelectOverlay
|
||||
{
|
||||
|
152
osu.Game.Tests/Visual/UserInterface/TestSceneModSettings.cs
Normal file
152
osu.Game.Tests/Visual/UserInterface/TestSceneModSettings.cs
Normal file
@ -0,0 +1,152 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Overlays.Mods;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.UI;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
public class TestSceneModSettings : OsuTestScene
|
||||
{
|
||||
private TestModSelectOverlay modSelect;
|
||||
|
||||
private readonly Mod testCustomisableMod = new TestModCustomisable1();
|
||||
|
||||
[Test]
|
||||
public void TestButtonShowsOnCustomisableMod()
|
||||
{
|
||||
createModSelect();
|
||||
|
||||
AddStep("open", () => modSelect.Show());
|
||||
AddAssert("button disabled", () => !modSelect.CustomiseButton.Enabled.Value);
|
||||
AddUntilStep("wait for button load", () => modSelect.ButtonsLoaded);
|
||||
AddStep("select mod", () => modSelect.SelectMod(testCustomisableMod));
|
||||
AddAssert("button enabled", () => modSelect.CustomiseButton.Enabled.Value);
|
||||
AddStep("open Customisation", () => modSelect.CustomiseButton.Click());
|
||||
AddStep("deselect mod", () => modSelect.SelectMod(testCustomisableMod));
|
||||
AddAssert("controls hidden", () => modSelect.ModSettingsContainer.Alpha == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestButtonShowsOnModAlreadyAdded()
|
||||
{
|
||||
AddStep("set active mods", () => SelectedMods.Value = new List<Mod> { testCustomisableMod });
|
||||
|
||||
createModSelect();
|
||||
|
||||
AddAssert("mods still active", () => SelectedMods.Value.Count == 1);
|
||||
|
||||
AddStep("open", () => modSelect.Show());
|
||||
AddAssert("button enabled", () => modSelect.CustomiseButton.Enabled.Value);
|
||||
}
|
||||
|
||||
private void createModSelect()
|
||||
{
|
||||
AddStep("create mod select", () =>
|
||||
{
|
||||
Ruleset.Value = new TestRulesetInfo();
|
||||
|
||||
Child = modSelect = new TestModSelectOverlay
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Origin = Anchor.BottomCentre,
|
||||
Anchor = Anchor.BottomCentre,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private class TestModSelectOverlay : ModSelectOverlay
|
||||
{
|
||||
public new Container ModSettingsContainer => base.ModSettingsContainer;
|
||||
public new TriangleButton CustomiseButton => base.CustomiseButton;
|
||||
|
||||
public bool ButtonsLoaded => ModSectionsContainer.Children.All(c => c.ModIconsLoaded);
|
||||
|
||||
public void SelectMod(Mod mod) =>
|
||||
ModSectionsContainer.Children.Single(s => s.ModType == mod.Type)
|
||||
.ButtonsContainer.OfType<ModButton>().Single(b => b.Mods.Any(m => m.GetType() == mod.GetType())).SelectNext(1);
|
||||
}
|
||||
|
||||
public class TestRulesetInfo : RulesetInfo
|
||||
{
|
||||
public override Ruleset CreateInstance() => new TestCustomisableModRuleset();
|
||||
|
||||
public TestRulesetInfo()
|
||||
{
|
||||
Available = true;
|
||||
}
|
||||
|
||||
public class TestCustomisableModRuleset : Ruleset
|
||||
{
|
||||
public override IEnumerable<Mod> GetModsFor(ModType type)
|
||||
{
|
||||
if (type == ModType.Conversion)
|
||||
{
|
||||
return new Mod[]
|
||||
{
|
||||
new TestModCustomisable1(),
|
||||
new TestModCustomisable2()
|
||||
};
|
||||
}
|
||||
|
||||
return Array.Empty<Mod>();
|
||||
}
|
||||
|
||||
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod> mods = null) => throw new NotImplementedException();
|
||||
|
||||
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => throw new NotImplementedException();
|
||||
|
||||
public override DifficultyCalculator CreateDifficultyCalculator(WorkingBeatmap beatmap) => throw new NotImplementedException();
|
||||
|
||||
public override string Description { get; } = "test";
|
||||
public override string ShortName { get; } = "tst";
|
||||
}
|
||||
}
|
||||
|
||||
private class TestModCustomisable1 : TestModCustomisable
|
||||
{
|
||||
public override string Name => "Customisable Mod 1";
|
||||
|
||||
public override string Acronym => "CM1";
|
||||
}
|
||||
|
||||
private class TestModCustomisable2 : TestModCustomisable
|
||||
{
|
||||
public override string Name => "Customisable Mod 2";
|
||||
|
||||
public override string Acronym => "CM2";
|
||||
}
|
||||
|
||||
private abstract class TestModCustomisable : Mod, IApplicableMod
|
||||
{
|
||||
public override double ScoreMultiplier => 1.0;
|
||||
|
||||
public override ModType Type => ModType.Conversion;
|
||||
|
||||
[SettingSource("Sample float", "Change something for a mod")]
|
||||
public BindableFloat SliderBindable { get; } = new BindableFloat
|
||||
{
|
||||
MinValue = 0,
|
||||
MaxValue = 10,
|
||||
Default = 5,
|
||||
Value = 7
|
||||
};
|
||||
|
||||
[SettingSource("Sample bool", "Clicking this changes a setting")]
|
||||
public BindableBool TickBindable { get; } = new BindableBool();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
// 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.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Overlays.Dialog;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
@ -11,13 +14,22 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
[TestFixture]
|
||||
public class TestScenePopupDialog : OsuTestScene
|
||||
{
|
||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||
{
|
||||
typeof(PopupDialogOkButton),
|
||||
typeof(PopupDialogCancelButton),
|
||||
typeof(PopupDialogButton),
|
||||
typeof(DialogButton),
|
||||
};
|
||||
|
||||
public TestScenePopupDialog()
|
||||
{
|
||||
Add(new TestPopupDialog
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
State = { Value = Framework.Graphics.Containers.Visibility.Visible },
|
||||
});
|
||||
AddStep("new popup", () =>
|
||||
Add(new TestPopupDialog
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
State = { Value = Framework.Graphics.Containers.Visibility.Visible },
|
||||
}));
|
||||
}
|
||||
|
||||
private class TestPopupDialog : PopupDialog
|
||||
|
Reference in New Issue
Block a user