mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 19:22:56 +08:00
Merge pull request #8863 from iiSaLMaN/fix-toolbar-ruleset-selector-not-receiving-input
Fix ruleset selector not receiving key input on toolbar absence
This commit is contained in:
commit
34b99b8f28
@ -5,13 +5,17 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Overlays.Toolbar;
|
using osu.Game.Overlays.Toolbar;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Menus
|
namespace osu.Game.Tests.Visual.Menus
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestSceneToolbar : OsuTestScene
|
public class TestSceneToolbar : OsuManualInputManagerTestScene
|
||||||
{
|
{
|
||||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||||
{
|
{
|
||||||
@ -21,24 +25,62 @@ namespace osu.Game.Tests.Visual.Menus
|
|||||||
typeof(ToolbarNotificationButton),
|
typeof(ToolbarNotificationButton),
|
||||||
};
|
};
|
||||||
|
|
||||||
public TestSceneToolbar()
|
private Toolbar toolbar;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private RulesetStore rulesets { get; set; }
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public void SetUp() => Schedule(() =>
|
||||||
|
{
|
||||||
|
Child = toolbar = new Toolbar { State = { Value = Visibility.Visible } };
|
||||||
|
});
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestNotificationCounter()
|
||||||
{
|
{
|
||||||
var toolbar = new Toolbar { State = { Value = Visibility.Visible } };
|
|
||||||
ToolbarNotificationButton notificationButton = null;
|
ToolbarNotificationButton notificationButton = null;
|
||||||
|
|
||||||
AddStep("create toolbar", () =>
|
AddStep("retrieve notification button", () => notificationButton = toolbar.ChildrenOfType<ToolbarNotificationButton>().Single());
|
||||||
{
|
|
||||||
Add(toolbar);
|
|
||||||
notificationButton = toolbar.Children.OfType<FillFlowContainer>().Last().Children.OfType<ToolbarNotificationButton>().First();
|
|
||||||
});
|
|
||||||
|
|
||||||
void setNotifications(int count) => AddStep($"set notification count to {count}", () => notificationButton.NotificationCount.Value = count);
|
|
||||||
|
|
||||||
setNotifications(1);
|
setNotifications(1);
|
||||||
setNotifications(2);
|
setNotifications(2);
|
||||||
setNotifications(3);
|
setNotifications(3);
|
||||||
setNotifications(0);
|
setNotifications(0);
|
||||||
setNotifications(144);
|
setNotifications(144);
|
||||||
|
|
||||||
|
void setNotifications(int count)
|
||||||
|
=> AddStep($"set notification count to {count}",
|
||||||
|
() => notificationButton.NotificationCount.Value = count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestCase(false)]
|
||||||
|
[TestCase(true)]
|
||||||
|
public void TestRulesetSwitchingShortcut(bool toolbarHidden)
|
||||||
|
{
|
||||||
|
ToolbarRulesetSelector rulesetSelector = null;
|
||||||
|
|
||||||
|
if (toolbarHidden)
|
||||||
|
AddStep("hide toolbar", () => toolbar.Hide());
|
||||||
|
|
||||||
|
AddStep("retrieve ruleset selector", () => rulesetSelector = toolbar.ChildrenOfType<ToolbarRulesetSelector>().Single());
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
var expected = rulesets.AvailableRulesets.ElementAt(i);
|
||||||
|
var numberKey = Key.Number1 + i;
|
||||||
|
|
||||||
|
AddStep($"switch to ruleset {i} via shortcut", () =>
|
||||||
|
{
|
||||||
|
InputManager.PressKey(Key.ControlLeft);
|
||||||
|
InputManager.PressKey(numberKey);
|
||||||
|
|
||||||
|
InputManager.ReleaseKey(Key.ControlLeft);
|
||||||
|
InputManager.ReleaseKey(numberKey);
|
||||||
|
});
|
||||||
|
|
||||||
|
AddUntilStep("ruleset switched", () => rulesetSelector.Current.Value.Equals(expected));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,9 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
|
|
||||||
private readonly Bindable<OverlayActivation> overlayActivationMode = new Bindable<OverlayActivation>(OverlayActivation.All);
|
private readonly Bindable<OverlayActivation> overlayActivationMode = new Bindable<OverlayActivation>(OverlayActivation.All);
|
||||||
|
|
||||||
|
// Toolbar components like RulesetSelector should receive keyboard input events even when the toolbar is hidden.
|
||||||
|
public override bool PropagateNonPositionalInputSubTree => true;
|
||||||
|
|
||||||
public Toolbar()
|
public Toolbar()
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
|
Loading…
Reference in New Issue
Block a user