2019-01-24 08:43:03 +00:00
|
|
|
|
// 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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using NUnit.Framework;
|
2020-04-25 06:54:37 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2020-08-18 13:25:51 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2020-04-25 06:54:37 +00:00
|
|
|
|
using osu.Framework.Testing;
|
2020-08-18 13:25:51 +00:00
|
|
|
|
using osu.Game.Overlays;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Overlays.Toolbar;
|
2020-04-25 06:54:37 +00:00
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
using osuTK.Input;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-24 16:02:36 +00:00
|
|
|
|
namespace osu.Game.Tests.Visual.Menus
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2020-04-25 06:54:37 +00:00
|
|
|
|
public class TestSceneToolbar : OsuManualInputManagerTestScene
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-08-18 13:25:51 +00:00
|
|
|
|
private TestToolbar toolbar;
|
2020-04-25 06:54:37 +00:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private RulesetStore rulesets { get; set; }
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp() => Schedule(() =>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2020-08-18 13:25:51 +00:00
|
|
|
|
Child = toolbar = new TestToolbar { State = { Value = Visibility.Visible } };
|
2020-04-25 06:54:37 +00:00
|
|
|
|
});
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-04-25 06:54:37 +00:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestNotificationCounter()
|
|
|
|
|
{
|
|
|
|
|
ToolbarNotificationButton notificationButton = null;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-04-25 06:54:37 +00:00
|
|
|
|
AddStep("retrieve notification button", () => notificationButton = toolbar.ChildrenOfType<ToolbarNotificationButton>().Single());
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
setNotifications(1);
|
|
|
|
|
setNotifications(2);
|
|
|
|
|
setNotifications(3);
|
|
|
|
|
setNotifications(0);
|
|
|
|
|
setNotifications(144);
|
2020-04-25 06:54:37 +00:00
|
|
|
|
|
|
|
|
|
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);
|
2020-11-05 14:41:56 +00:00
|
|
|
|
InputManager.Key(numberKey);
|
2020-04-25 06:54:37 +00:00
|
|
|
|
InputManager.ReleaseKey(Key.ControlLeft);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddUntilStep("ruleset switched", () => rulesetSelector.Current.Value.Equals(expected));
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
2020-08-18 13:25:51 +00:00
|
|
|
|
|
|
|
|
|
[TestCase(OverlayActivation.All)]
|
|
|
|
|
[TestCase(OverlayActivation.Disabled)]
|
|
|
|
|
public void TestRespectsOverlayActivation(OverlayActivation mode)
|
|
|
|
|
{
|
|
|
|
|
AddStep($"set activation mode to {mode}", () => toolbar.OverlayActivationMode.Value = mode);
|
|
|
|
|
AddStep("hide toolbar", () => toolbar.Hide());
|
|
|
|
|
AddStep("try to show toolbar", () => toolbar.Show());
|
|
|
|
|
|
|
|
|
|
if (mode == OverlayActivation.Disabled)
|
2020-08-19 10:10:45 +00:00
|
|
|
|
AddAssert("toolbar still hidden", () => toolbar.State.Value == Visibility.Hidden);
|
2020-08-18 13:25:51 +00:00
|
|
|
|
else
|
2020-08-19 10:09:35 +00:00
|
|
|
|
AddAssert("toolbar is visible", () => toolbar.State.Value == Visibility.Visible);
|
2020-08-18 13:25:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class TestToolbar : Toolbar
|
|
|
|
|
{
|
2020-08-31 09:16:13 +00:00
|
|
|
|
public new Bindable<OverlayActivation> OverlayActivationMode => base.OverlayActivationMode as Bindable<OverlayActivation>;
|
2020-08-18 13:25:51 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|