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

Update OsuDropdown implementation inline with framework changes #26205

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 5 additions & 35 deletions osu.Game.Tests/Visual/UserInterface/TestSceneOsuDropdown.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,19 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Input.States;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;

namespace osu.Game.Tests.Visual.UserInterface
{
public partial class TestSceneOsuDropdown : ThemeComparisonTestScene
{
protected override Drawable CreateContent() =>
new OsuEnumDropdown<BeatmapOnlineStatus>
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
Width = 150
};

[Test]
// todo: this can be written much better if ThemeComparisonTestScene has a manual input manager
public void TestBackAction()
protected override Drawable CreateContent() => new OsuEnumDropdown<BeatmapOnlineStatus>
{
AddStep("open", () => dropdown().ChildrenOfType<Menu>().Single().Open());
AddStep("press back", () => dropdown().OnPressed(new KeyBindingPressEvent<GlobalAction>(new InputState(), GlobalAction.Back)));
AddAssert("closed", () => dropdown().ChildrenOfType<Menu>().Single().State == MenuState.Closed);

AddStep("open", () => dropdown().ChildrenOfType<Menu>().Single().Open());
AddStep("type something", () => dropdown().ChildrenOfType<DropdownSearchBar>().Single().SearchTerm.Value = "something");
AddAssert("search bar visible", () => dropdown().ChildrenOfType<DropdownSearchBar>().Single().State.Value == Visibility.Visible);
AddStep("press back", () => dropdown().OnPressed(new KeyBindingPressEvent<GlobalAction>(new InputState(), GlobalAction.Back)));
AddAssert("text clear", () => dropdown().ChildrenOfType<DropdownSearchBar>().Single().SearchTerm.Value == string.Empty);
AddAssert("search bar hidden", () => dropdown().ChildrenOfType<DropdownSearchBar>().Single().State.Value == Visibility.Hidden);
AddAssert("still open", () => dropdown().ChildrenOfType<Menu>().Single().State == MenuState.Open);
AddStep("press back", () => dropdown().OnPressed(new KeyBindingPressEvent<GlobalAction>(new InputState(), GlobalAction.Back)));
AddAssert("closed", () => dropdown().ChildrenOfType<Menu>().Single().State == MenuState.Closed);

OsuEnumDropdown<BeatmapOnlineStatus> dropdown() => this.ChildrenOfType<OsuEnumDropdown<BeatmapOnlineStatus>>().First();
}
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
Width = 150
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterface;
using osuTK.Input;

namespace osu.Game.Tests.Visual.UserInterface
{
public partial class TestSceneOsuDropdownInputHandling : OsuManualInputManagerTestScene
{
private OsuDropdown<BeatmapOnlineStatus> dropdown = null!;

[SetUp]
public void SetUp() => Schedule(() =>
{
Child = dropdown = new OsuEnumDropdown<BeatmapOnlineStatus>
{
Anchor = Anchor.Centre,
Origin = Anchor.TopCentre,
Width = 150
};
});

[Test]
public void TestBackAction()
{
AddStep("open", () => dropdown.ChildrenOfType<Menu>().Single().Open());
AddStep("press back", () => InputManager.Key(Key.Escape));
AddAssert("closed", () => dropdown.ChildrenOfType<Menu>().Single().State == MenuState.Closed);
AddStep("open", () => dropdown.ChildrenOfType<Menu>().Single().Open());
AddStep("type something", () => dropdown.ChildrenOfType<DropdownSearchBar>().Single().SearchTerm.Value = "something");
AddAssert("search bar visible", () => dropdown.ChildrenOfType<DropdownSearchBar>().Single().State.Value == Visibility.Visible);
AddStep("press back", () => InputManager.Key(Key.Escape));
AddAssert("text clear", () => dropdown.ChildrenOfType<DropdownSearchBar>().Single().SearchTerm.Value == string.Empty);
AddAssert("search bar hidden", () => dropdown.ChildrenOfType<DropdownSearchBar>().Single().State.Value == Visibility.Hidden);
AddAssert("still open", () => dropdown.ChildrenOfType<Menu>().Single().State == MenuState.Open);
AddStep("press back", () => InputManager.Key(Key.Escape));
AddAssert("closed", () => dropdown.ChildrenOfType<Menu>().Single().State == MenuState.Closed);
}
}
}
33 changes: 17 additions & 16 deletions osu.Game/Graphics/UserInterface/OsuDropdown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ public partial class OsuDropdown<T> : Dropdown<T>, IKeyBindingHandler<GlobalActi

public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (e.Repeat) return false;

if (e.Action == GlobalAction.Back)
return Back();
if (e.Action == GlobalAction.Back && Menu.State == MenuState.Open)
{
Menu.Close();
return true;
}

return false;
}
Expand All @@ -48,8 +49,6 @@ public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)

protected partial class OsuDropdownMenu : DropdownMenu
{
public override bool HandleNonPositionalInput => State == MenuState.Open;

private Sample? sampleOpen;
private Sample? sampleClose;

Expand Down Expand Up @@ -400,28 +399,30 @@ private void updateColour()
Padding = new MarginPadding { Right = 26 },
};

private partial class OsuDropdownSearchBar : DropdownSearchBar
private partial class OsuDropdownSearchBar : DropdownSearchBar, IKeyBindingHandler<GlobalAction>
{
protected override void PopIn() => this.FadeIn();

protected override void PopOut() => this.FadeOut();

protected override TextBox CreateTextBox() => new DropdownSearchTextBox
protected override TextBox CreateTextBox() => new SearchTextBox
{
FontSize = OsuFont.Default.Size,
};

private partial class DropdownSearchTextBox : SearchTextBox
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
if (e.Action == GlobalAction.Back && !string.IsNullOrEmpty(SearchTerm.Value))
{
if (e.Action == GlobalAction.Back)
// this method is blocking Dropdown from receiving the back action, despite this text box residing in a separate input manager.
// to fix this properly, a local global action container needs to be added as well, but for simplicity, just don't handle the back action here.
return false;

return base.OnPressed(e);
SearchTerm.Value = string.Empty;
return true;
}

return false;
}

public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}
}
}
Expand Down
Loading