Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mod customization header/panel changes #29626

Merged
merged 10 commits into from
Sep 4, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
Expand Down Expand Up @@ -58,19 +59,19 @@ public void TestDisplay()
{
SelectedMods.Value = new[] { new OsuModDoubleTime() };
panel.Enabled.Value = true;
panel.ExpandedState.Value = ModCustomisationPanel.ModCustomisationPanelState.Expanded;
panel.ExpandedState.Value = ModCustomisationPanel.ModCustomisationPanelState.ExpandedByMod;
});
AddStep("set DA", () =>
{
SelectedMods.Value = new Mod[] { new OsuModDifficultyAdjust() };
panel.Enabled.Value = true;
panel.ExpandedState.Value = ModCustomisationPanel.ModCustomisationPanelState.Expanded;
panel.ExpandedState.Value = ModCustomisationPanel.ModCustomisationPanelState.ExpandedByMod;
});
AddStep("set FL+WU+DA+AD", () =>
{
SelectedMods.Value = new Mod[] { new OsuModFlashlight(), new ModWindUp(), new OsuModDifficultyAdjust(), new OsuModApproachDifferent() };
panel.Enabled.Value = true;
panel.ExpandedState.Value = ModCustomisationPanel.ModCustomisationPanelState.Expanded;
panel.ExpandedState.Value = ModCustomisationPanel.ModCustomisationPanelState.ExpandedByMod;
});
AddStep("set empty", () =>
{
Expand Down Expand Up @@ -120,42 +121,28 @@ public void TestHoverExpandsWithCustomisableMods()
}

[Test]
public void TestExpandedStatePersistsWhenClicked()
public void TestHoverExpandsAndCollapsesWhenHeaderTouched()
{
AddStep("add customisable mod", () =>
{
SelectedMods.Value = new[] { new OsuModDoubleTime() };
panel.Enabled.Value = true;
});

AddStep("hover header", () => InputManager.MoveMouseTo(header));
checkExpanded(true);

AddStep("click", () => InputManager.Click(MouseButton.Left));
checkExpanded(false);
AddStep("click", () => InputManager.Click(MouseButton.Left));
checkExpanded(true);

AddStep("move away", () => InputManager.MoveMouseTo(Vector2.One));
checkExpanded(true);

AddStep("click", () => InputManager.Click(MouseButton.Left));
checkExpanded(false);
}

[Test]
public void TestHoverExpandsAndCollapsesWhenHeaderClicked()
{
AddStep("add customisable mod", () =>
AddStep("touch header", () =>
{
SelectedMods.Value = new[] { new OsuModDoubleTime() };
panel.Enabled.Value = true;
var touch = new Touch(TouchSource.Touch1, header.ScreenSpaceDrawQuad.Centre);
InputManager.BeginTouch(touch);
Schedule(() => InputManager.EndTouch(touch));
});

AddStep("hover header", () => InputManager.MoveMouseTo(header));
checkExpanded(true);

AddStep("click", () => InputManager.Click(MouseButton.Left));
AddStep("touch away from header", () =>
{
var touch = new Touch(TouchSource.Touch1, header.ScreenSpaceDrawQuad.TopLeft - new Vector2(10));
InputManager.BeginTouch(touch);
Schedule(() => InputManager.EndTouch(touch));
});
checkExpanded(false);
}

Expand Down
20 changes: 7 additions & 13 deletions osu.Game.Tests/Visual/UserInterface/TestSceneModSelectOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,8 @@ public void TestCustomisationToggleState()
AddStep("select difficulty adjust via panel", () => getPanelForMod(typeof(OsuModDifficultyAdjust)).TriggerClick());
assertCustomisationToggleState(disabled: false, active: true);

AddStep("dismiss mod customisation via toggle", () =>
{
InputManager.MoveMouseTo(modSelectOverlay.ChildrenOfType<ModCustomisationHeader>().Single());
InputManager.Click(MouseButton.Left);
});
assertCustomisationToggleState(disabled: false, active: false);
AddStep("move mouse away", () => InputManager.MoveMouseTo(Vector2.Zero));
assertCustomisationToggleState(disabled: false, active: true);

AddStep("reset mods", () => SelectedMods.SetDefault());
AddStep("select difficulty adjust via panel", () => getPanelForMod(typeof(OsuModDifficultyAdjust)).TriggerClick());
Expand Down Expand Up @@ -664,7 +660,7 @@ public void TestTextSearchDoesNotBlockCustomisationPanelKeyboardInteractions()
AddStep("select DT", () => SelectedMods.Value = new Mod[] { new OsuModDoubleTime() });
AddAssert("DT selected", () => modSelectOverlay.ChildrenOfType<ModPanel>().Count(panel => panel.Active.Value), () => Is.EqualTo(1));

AddStep("open customisation area", () => modSelectOverlay.ChildrenOfType<ModCustomisationHeader>().Single().TriggerClick());
AddStep("open customisation area", () => InputManager.MoveMouseTo(modSelectOverlay.ChildrenOfType<ModCustomisationHeader>().Single()));
assertCustomisationToggleState(disabled: false, active: true);

AddStep("hover over mod settings slider", () =>
Expand Down Expand Up @@ -976,7 +972,7 @@ public void TestCustomisationPanelAbsorbsInput([Values] bool textSearchStartsAct
createScreen();

AddStep("select DT", () => SelectedMods.Value = new Mod[] { new OsuModDoubleTime() });
AddStep("open customisation panel", () => this.ChildrenOfType<ModCustomisationHeader>().Single().TriggerClick());
AddStep("open customisation panel", () => InputManager.MoveMouseTo(this.ChildrenOfType<ModCustomisationHeader>().Single()));
AddAssert("search lost focus", () => !this.ChildrenOfType<ShearedSearchTextBox>().Single().HasFocus);

AddStep("press tab", () => InputManager.Key(Key.Tab));
Expand All @@ -991,15 +987,13 @@ public void TestCustomisationPanelAbsorbsInput([Values] bool textSearchStartsAct
AddStep("press backspace", () => InputManager.Key(Key.BackSpace));
AddAssert("mods not deselected", () => SelectedMods.Value.Single() is OsuModDoubleTime);

AddStep("move mouse to scroll bar", () => InputManager.MoveMouseTo(modSelectOverlay.ChildrenOfType<ModSelectOverlay.ColumnScrollContainer>().Single().ScreenSpaceDrawQuad.BottomLeft + new Vector2(10f, -5f)));
AddStep("move mouse to customisation panel", () => InputManager.MoveMouseTo(modSelectOverlay.ChildrenOfType<ModCustomisationSection>().First()));

AddStep("scroll down", () => InputManager.ScrollVerticalBy(-10f));
AddAssert("column not scrolled", () => modSelectOverlay.ChildrenOfType<ModSelectOverlay.ColumnScrollContainer>().Single().IsScrolledToStart());

AddStep("press mouse", () => InputManager.PressButton(MouseButton.Left));
AddAssert("search still not focused", () => !this.ChildrenOfType<ShearedSearchTextBox>().Single().HasFocus);
AddStep("release mouse", () => InputManager.ReleaseButton(MouseButton.Left));
AddAssert("customisation panel closed by click",
AddStep("move mouse away", () => InputManager.MoveMouseTo(Vector2.Zero));
AddAssert("customisation panel closed",
() => this.ChildrenOfType<ModCustomisationPanel>().Single().ExpandedState.Value,
() => Is.EqualTo(ModCustomisationPanel.ModCustomisationPanelState.Collapsed));

Expand Down
34 changes: 2 additions & 32 deletions osu.Game/Overlays/Mods/ModCustomisationHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,40 +112,10 @@ protected override void LoadComplete()
}, true);
}

protected override bool OnClick(ClickEvent e)
{
if (Enabled.Value)
{
ExpandedState.Value = ExpandedState.Value switch
{
ModCustomisationPanelState.Collapsed => ModCustomisationPanelState.Expanded,
_ => ModCustomisationPanelState.Collapsed
};
}

return base.OnClick(e);
}

private bool touchedThisFrame;

protected override bool OnTouchDown(TouchDownEvent e)
{
if (Enabled.Value)
{
touchedThisFrame = true;
Schedule(() => touchedThisFrame = false);
}

return base.OnTouchDown(e);
}

protected override bool OnHover(HoverEvent e)
{
if (Enabled.Value)
{
if (!touchedThisFrame && panel.ExpandedState.Value == ModCustomisationPanelState.Collapsed)
panel.ExpandedState.Value = ModCustomisationPanelState.ExpandedByHover;
}
if (Enabled.Value && panel.ExpandedState.Value == ModCustomisationPanelState.Collapsed)
panel.ExpandedState.Value = ModCustomisationPanelState.Expanded;

return base.OnHover(e);
}
Expand Down
6 changes: 3 additions & 3 deletions osu.Game/Overlays/Mods/ModCustomisationPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ protected override void Update()
{
base.Update();

if (ExpandedState.Value == ModCustomisationPanelState.ExpandedByHover
if (ExpandedState.Value == ModCustomisationPanelState.Expanded
&& !ReceivePositionalInputAt(inputManager.CurrentState.Mouse.Position)
&& inputManager.DraggedDrawable == null)
{
Expand All @@ -239,8 +239,8 @@ protected override void Update()
public enum ModCustomisationPanelState
{
Collapsed = 0,
ExpandedByHover = 1,
Expanded = 2,
Expanded = 1,
ExpandedByMod = 2,
}
}
}
2 changes: 1 addition & 1 deletion osu.Game/Overlays/Mods/ModSelectOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ private void updateCustomisation()
customisationPanel.Enabled.Value = true;

if (anyModPendingConfiguration)
customisationPanel.ExpandedState.Value = ModCustomisationPanel.ModCustomisationPanelState.Expanded;
customisationPanel.ExpandedState.Value = ModCustomisationPanel.ModCustomisationPanelState.ExpandedByMod;
}
else
{
Expand Down
Loading