mirror of
https://github.com/osukey/osukey.git
synced 2025-06-20 02:38:04 +09:00
Merge pull request #10495 from FamousPig/mod-customisation-absorb-mouse-input
Fix mod customisation container not absorbing input
This commit is contained in:
commit
2beddf5351
@ -9,6 +9,7 @@ using osu.Framework.Bindables;
|
|||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
@ -18,10 +19,11 @@ using osu.Game.Rulesets.Difficulty;
|
|||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.Osu.Mods;
|
using osu.Game.Rulesets.Osu.Mods;
|
||||||
using osu.Game.Rulesets.UI;
|
using osu.Game.Rulesets.UI;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
{
|
{
|
||||||
public class TestSceneModSettings : OsuTestScene
|
public class TestSceneModSettings : OsuManualInputManagerTestScene
|
||||||
{
|
{
|
||||||
private TestModSelectOverlay modSelect;
|
private TestModSelectOverlay modSelect;
|
||||||
|
|
||||||
@ -113,6 +115,23 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
AddAssert("copy has original value", () => Precision.AlmostEquals(1.5, ((OsuModDoubleTime)copy.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));
|
||||||
|
AddAssert("Customisation opened", () => modSelect.ModSettingsContainer.Alpha == 1);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
private void createModSelect()
|
private void createModSelect()
|
||||||
{
|
{
|
||||||
AddStep("create mod select", () =>
|
AddStep("create mod select", () =>
|
||||||
@ -139,9 +158,16 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
|
|
||||||
public bool ButtonsLoaded => ModSectionsContainer.Children.All(c => c.ModIconsLoaded);
|
public bool ButtonsLoaded => ModSectionsContainer.Children.All(c => c.ModIconsLoaded);
|
||||||
|
|
||||||
|
public ModButton GetModButton(Mod mod)
|
||||||
|
{
|
||||||
|
return ModSectionsContainer.ChildrenOfType<ModButton>().Single(b => b.Mods.Any(m => m.GetType() == mod.GetType()));
|
||||||
|
}
|
||||||
|
|
||||||
public void SelectMod(Mod mod) =>
|
public void SelectMod(Mod mod) =>
|
||||||
ModSectionsContainer.Children.Single(s => s.ModType == mod.Type)
|
GetModButton(mod).SelectNext(1);
|
||||||
.ButtonsContainer.OfType<ModButton>().Single(b => b.Mods.Any(m => m.GetType() == mod.GetType())).SelectNext(1);
|
|
||||||
|
public void SetModSettingsWidth(float newWidth) =>
|
||||||
|
ModSettingsContainer.Width = newWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TestRulesetInfo : RulesetInfo
|
public class TestRulesetInfo : RulesetInfo
|
||||||
|
@ -13,7 +13,6 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Configuration;
|
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Backgrounds;
|
using osu.Game.Graphics.Backgrounds;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
@ -45,9 +44,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
|
|
||||||
protected readonly FillFlowContainer<ModSection> ModSectionsContainer;
|
protected readonly FillFlowContainer<ModSection> ModSectionsContainer;
|
||||||
|
|
||||||
protected readonly FillFlowContainer<ModControlSection> ModSettingsContent;
|
protected readonly ModSettingsContainer ModSettingsContainer;
|
||||||
|
|
||||||
protected readonly Container ModSettingsContainer;
|
|
||||||
|
|
||||||
public readonly Bindable<IReadOnlyList<Mod>> SelectedMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
public readonly Bindable<IReadOnlyList<Mod>> SelectedMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
||||||
|
|
||||||
@ -284,7 +281,7 @@ namespace osu.Game.Overlays.Mods
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ModSettingsContainer = new Container
|
ModSettingsContainer = new ModSettingsContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Anchor = Anchor.BottomRight,
|
Anchor = Anchor.BottomRight,
|
||||||
@ -292,29 +289,11 @@ namespace osu.Game.Overlays.Mods
|
|||||||
Width = 0.25f,
|
Width = 0.25f,
|
||||||
Alpha = 0,
|
Alpha = 0,
|
||||||
X = -100,
|
X = -100,
|
||||||
Children = new Drawable[]
|
SelectedMods = { BindTarget = SelectedMods },
|
||||||
{
|
|
||||||
new Box
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Colour = new Color4(0, 0, 0, 192)
|
|
||||||
},
|
|
||||||
new OsuScrollContainer
|
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Child = ModSettingsContent = new FillFlowContainer<ModControlSection>
|
|
||||||
{
|
|
||||||
Anchor = Anchor.TopCentre,
|
|
||||||
Origin = Anchor.TopCentre,
|
|
||||||
RelativeSizeAxes = Axes.X,
|
|
||||||
AutoSizeAxes = Axes.Y,
|
|
||||||
Spacing = new Vector2(0f, 10f),
|
|
||||||
Padding = new MarginPadding(20),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
((IBindable<bool>)CustomiseButton.Enabled).BindTo(ModSettingsContainer.HasSettingsForSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader(true)]
|
[BackgroundDependencyLoader(true)]
|
||||||
@ -423,8 +402,6 @@ namespace osu.Game.Overlays.Mods
|
|||||||
section.SelectTypes(mods.NewValue.Select(m => m.GetType()).ToList());
|
section.SelectTypes(mods.NewValue.Select(m => m.GetType()).ToList());
|
||||||
|
|
||||||
updateMods();
|
updateMods();
|
||||||
|
|
||||||
updateModSettings(mods);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateMods()
|
private void updateMods()
|
||||||
@ -445,25 +422,6 @@ namespace osu.Game.Overlays.Mods
|
|||||||
MultiplierLabel.FadeColour(Color4.White, 200);
|
MultiplierLabel.FadeColour(Color4.White, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateModSettings(ValueChangedEvent<IReadOnlyList<Mod>> selectedMods)
|
|
||||||
{
|
|
||||||
ModSettingsContent.Clear();
|
|
||||||
|
|
||||||
foreach (var mod in selectedMods.NewValue)
|
|
||||||
{
|
|
||||||
var settings = mod.CreateSettingsControls().ToList();
|
|
||||||
if (settings.Count > 0)
|
|
||||||
ModSettingsContent.Add(new ModControlSection(mod, settings));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasSettings = ModSettingsContent.Count > 0;
|
|
||||||
|
|
||||||
CustomiseButton.Enabled.Value = hasSettings;
|
|
||||||
|
|
||||||
if (!hasSettings)
|
|
||||||
ModSettingsContainer.Hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void modButtonPressed(Mod selectedMod)
|
private void modButtonPressed(Mod selectedMod)
|
||||||
{
|
{
|
||||||
if (selectedMod != null)
|
if (selectedMod != null)
|
||||||
|
84
osu.Game/Overlays/Mods/ModSettingsContainer.cs
Normal file
84
osu.Game/Overlays/Mods/ModSettingsContainer.cs
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
// 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 osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
|
using osu.Game.Configuration;
|
||||||
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osu.Game.Rulesets.Mods;
|
||||||
|
using osuTK;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Mods
|
||||||
|
{
|
||||||
|
public class ModSettingsContainer : Container
|
||||||
|
{
|
||||||
|
public readonly IBindable<IReadOnlyList<Mod>> SelectedMods = new Bindable<IReadOnlyList<Mod>>(Array.Empty<Mod>());
|
||||||
|
|
||||||
|
public IBindable<bool> HasSettingsForSelection => hasSettingsForSelection;
|
||||||
|
|
||||||
|
private readonly Bindable<bool> hasSettingsForSelection = new Bindable<bool>();
|
||||||
|
|
||||||
|
private readonly FillFlowContainer<ModControlSection> modSettingsContent;
|
||||||
|
|
||||||
|
public ModSettingsContainer()
|
||||||
|
{
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new Box
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Colour = new Color4(0, 0, 0, 192)
|
||||||
|
},
|
||||||
|
new OsuScrollContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Child = modSettingsContent = new FillFlowContainer<ModControlSection>
|
||||||
|
{
|
||||||
|
Anchor = Anchor.TopCentre,
|
||||||
|
Origin = Anchor.TopCentre,
|
||||||
|
RelativeSizeAxes = Axes.X,
|
||||||
|
AutoSizeAxes = Axes.Y,
|
||||||
|
Spacing = new Vector2(0f, 10f),
|
||||||
|
Padding = new MarginPadding(20),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void LoadComplete()
|
||||||
|
{
|
||||||
|
base.LoadComplete();
|
||||||
|
|
||||||
|
SelectedMods.BindValueChanged(modsChanged, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void modsChanged(ValueChangedEvent<IReadOnlyList<Mod>> mods)
|
||||||
|
{
|
||||||
|
modSettingsContent.Clear();
|
||||||
|
|
||||||
|
foreach (var mod in mods.NewValue)
|
||||||
|
{
|
||||||
|
var settings = mod.CreateSettingsControls().ToList();
|
||||||
|
if (settings.Count > 0)
|
||||||
|
modSettingsContent.Add(new ModControlSection(mod, settings));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasSettings = modSettingsContent.Count > 0;
|
||||||
|
|
||||||
|
if (!hasSettings)
|
||||||
|
Hide();
|
||||||
|
|
||||||
|
hasSettingsForSelection.Value = hasSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool OnMouseDown(MouseDownEvent e) => true;
|
||||||
|
protected override bool OnHover(HoverEvent e) => true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user