mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 16:12:57 +08:00
Allow mod buttons to not be stacked
This commit is contained in:
parent
4ecbe058f7
commit
6d620264f4
@ -38,28 +38,7 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void SetUp() => Schedule(() =>
|
public void SetUp() => Schedule(() => createDisplay(() => new TestModSelectOverlay()));
|
||||||
{
|
|
||||||
SelectedMods.Value = Array.Empty<Mod>();
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
modSelect = new TestModSelectOverlay
|
|
||||||
{
|
|
||||||
Origin = Anchor.BottomCentre,
|
|
||||||
Anchor = Anchor.BottomCentre,
|
|
||||||
SelectedMods = { BindTarget = SelectedMods }
|
|
||||||
},
|
|
||||||
|
|
||||||
modDisplay = new ModDisplay
|
|
||||||
{
|
|
||||||
Anchor = Anchor.TopRight,
|
|
||||||
Origin = Anchor.TopRight,
|
|
||||||
AutoSizeAxes = Axes.Both,
|
|
||||||
Position = new Vector2(-5, 25),
|
|
||||||
Current = { BindTarget = modSelect.SelectedMods }
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
[SetUpSteps]
|
[SetUpSteps]
|
||||||
public void SetUpSteps()
|
public void SetUpSteps()
|
||||||
@ -146,6 +125,18 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestNonStacked()
|
||||||
|
{
|
||||||
|
changeRuleset(0);
|
||||||
|
|
||||||
|
AddStep("create overlay", () => createDisplay(() => new TestNonStackedModSelectOverlay()));
|
||||||
|
|
||||||
|
AddStep("show", () => modSelect.Show());
|
||||||
|
|
||||||
|
AddAssert("ensure all buttons are spread out", () => modSelect.ChildrenOfType<ModButton>().All(m => m.Mods.Length <= 1));
|
||||||
|
}
|
||||||
|
|
||||||
private void testSingleMod(Mod mod)
|
private void testSingleMod(Mod mod)
|
||||||
{
|
{
|
||||||
selectNext(mod);
|
selectNext(mod);
|
||||||
@ -265,6 +256,28 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
|
|
||||||
private void checkLabelColor(Func<Color4> getColour) => AddAssert("check label has expected colour", () => modSelect.MultiplierLabel.Colour.AverageColour == getColour());
|
private void checkLabelColor(Func<Color4> getColour) => AddAssert("check label has expected colour", () => modSelect.MultiplierLabel.Colour.AverageColour == getColour());
|
||||||
|
|
||||||
|
private void createDisplay(Func<TestModSelectOverlay> createOverlayFunc)
|
||||||
|
{
|
||||||
|
SelectedMods.Value = Array.Empty<Mod>();
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
modSelect = createOverlayFunc().With(d =>
|
||||||
|
{
|
||||||
|
d.Origin = Anchor.BottomCentre;
|
||||||
|
d.Anchor = Anchor.BottomCentre;
|
||||||
|
d.SelectedMods.BindTarget = SelectedMods;
|
||||||
|
}),
|
||||||
|
modDisplay = new ModDisplay
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopRight,
|
||||||
|
Origin = Anchor.TopRight,
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Position = new Vector2(-5, 25),
|
||||||
|
Current = { BindTarget = modSelect.SelectedMods }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private class TestModSelectOverlay : ModSelectOverlay
|
private class TestModSelectOverlay : ModSelectOverlay
|
||||||
{
|
{
|
||||||
public new Bindable<IReadOnlyList<Mod>> SelectedMods => base.SelectedMods;
|
public new Bindable<IReadOnlyList<Mod>> SelectedMods => base.SelectedMods;
|
||||||
@ -283,5 +296,10 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
public new Color4 LowMultiplierColour => base.LowMultiplierColour;
|
public new Color4 LowMultiplierColour => base.LowMultiplierColour;
|
||||||
public new Color4 HighMultiplierColour => base.HighMultiplierColour;
|
public new Color4 HighMultiplierColour => base.HighMultiplierColour;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class TestNonStackedModSelectOverlay : TestModSelectOverlay
|
||||||
|
{
|
||||||
|
protected override bool Stacked => false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ using osu.Game.Input.Bindings;
|
|||||||
using osu.Game.Overlays.Mods.Sections;
|
using osu.Game.Overlays.Mods.Sections;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Screens;
|
using osu.Game.Screens;
|
||||||
|
using osu.Game.Utils;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
@ -43,6 +44,11 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
protected override bool DimMainContent => false;
|
protected override bool DimMainContent => false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether <see cref="Mod"/>s underneath the same <see cref="MultiMod"/> instance should appear as stacked buttons.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual bool Stacked => true;
|
||||||
|
|
||||||
protected readonly FillFlowContainer<ModSection> ModSectionsContainer;
|
protected readonly FillFlowContainer<ModSection> ModSectionsContainer;
|
||||||
|
|
||||||
protected readonly ModSettingsContainer ModSettingsContainer;
|
protected readonly ModSettingsContainer ModSettingsContainer;
|
||||||
@ -405,7 +411,11 @@ namespace osu.Game.Overlays.Mods
|
|||||||
if (mods.NewValue == null) return;
|
if (mods.NewValue == null) return;
|
||||||
|
|
||||||
foreach (var section in ModSectionsContainer.Children)
|
foreach (var section in ModSectionsContainer.Children)
|
||||||
section.Mods = mods.NewValue[section.ModType].Where(isValidMod);
|
{
|
||||||
|
section.Mods = Stacked
|
||||||
|
? availableMods.Value[section.ModType]
|
||||||
|
: ModUtils.FlattenMods(availableMods.Value[section.ModType]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void selectedModsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
|
private void selectedModsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
|
||||||
|
Loading…
Reference in New Issue
Block a user