2019-01-24 16:43:03 +08: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 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using System.Linq;
|
2022-06-15 01:05:07 +08:00
|
|
|
|
using JetBrains.Annotations;
|
2022-04-19 10:10:11 +08:00
|
|
|
|
using Moq;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using NUnit.Framework;
|
2020-04-25 14:54:37 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2020-08-18 21:25:51 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2022-06-15 00:04:01 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Colour;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-06-15 00:04:01 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2020-04-25 14:54:37 +08:00
|
|
|
|
using osu.Framework.Testing;
|
2022-06-15 00:04:01 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2020-08-18 21:25:51 +08:00
|
|
|
|
using osu.Game.Overlays;
|
2022-06-15 01:05:07 +08:00
|
|
|
|
using osu.Game.Overlays.Notifications;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Overlays.Toolbar;
|
2020-04-25 14:54:37 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
2022-06-17 01:22:56 +08:00
|
|
|
|
using osuTK;
|
2022-06-15 00:04:01 +08:00
|
|
|
|
using osuTK.Graphics;
|
2020-04-25 14:54:37 +08:00
|
|
|
|
using osuTK.Input;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-03-25 00:02:36 +08:00
|
|
|
|
namespace osu.Game.Tests.Visual.Menus
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class TestSceneToolbar : OsuManualInputManagerTestScene
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-08-18 21:25:51 +08:00
|
|
|
|
private TestToolbar toolbar;
|
2020-04-25 14:54:37 +08:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
2021-12-03 17:14:44 +08:00
|
|
|
|
private IRulesetStore rulesets { get; set; }
|
2020-04-25 14:54:37 +08:00
|
|
|
|
|
2022-06-15 01:35:09 +08:00
|
|
|
|
[Cached]
|
|
|
|
|
private readonly NowPlayingOverlay nowPlayingOverlay = new NowPlayingOverlay
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
Y = Toolbar.HEIGHT,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
[Cached]
|
|
|
|
|
private readonly VolumeOverlay volumeOverlay = new VolumeOverlay
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
};
|
|
|
|
|
|
2022-06-15 01:05:07 +08:00
|
|
|
|
private readonly Mock<TestNotificationOverlay> notifications = new Mock<TestNotificationOverlay>();
|
2022-04-19 10:10:11 +08:00
|
|
|
|
|
|
|
|
|
private readonly BindableInt unreadNotificationCount = new BindableInt();
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
2022-06-15 01:05:07 +08:00
|
|
|
|
Dependencies.CacheAs<INotificationOverlay>(notifications.Object);
|
2022-04-19 10:10:11 +08:00
|
|
|
|
notifications.SetupGet(n => n.UnreadCount).Returns(unreadNotificationCount);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-25 14:54:37 +08:00
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp() => Schedule(() =>
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2022-08-26 14:19:05 +08:00
|
|
|
|
Remove(nowPlayingOverlay, false);
|
|
|
|
|
Remove(volumeOverlay, false);
|
2022-06-15 01:35:09 +08:00
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
nowPlayingOverlay,
|
|
|
|
|
volumeOverlay,
|
|
|
|
|
toolbar = new TestToolbar { State = { Value = Visibility.Visible } },
|
|
|
|
|
};
|
2020-04-25 14:54:37 +08:00
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-04-25 14:54:37 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestNotificationCounter()
|
|
|
|
|
{
|
2018-04-13 17:19:50 +08:00
|
|
|
|
setNotifications(1);
|
|
|
|
|
setNotifications(2);
|
|
|
|
|
setNotifications(3);
|
|
|
|
|
setNotifications(0);
|
|
|
|
|
setNotifications(144);
|
2020-04-25 14:54:37 +08:00
|
|
|
|
|
|
|
|
|
void setNotifications(int count)
|
|
|
|
|
=> AddStep($"set notification count to {count}",
|
2022-04-19 10:10:11 +08:00
|
|
|
|
() => unreadNotificationCount.Value = count);
|
2020-04-25 14:54:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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 22:41:56 +08:00
|
|
|
|
InputManager.Key(numberKey);
|
2020-04-25 14:54:37 +08:00
|
|
|
|
InputManager.ReleaseKey(Key.ControlLeft);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
AddUntilStep("ruleset switched", () => rulesetSelector.Current.Value.Equals(expected));
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2020-08-18 21:25:51 +08:00
|
|
|
|
|
2023-04-03 13:56:29 +08:00
|
|
|
|
[TestCase(OverlayActivation.All)]
|
|
|
|
|
[TestCase(OverlayActivation.Disabled)]
|
|
|
|
|
public void TestButtonKeyboardInputRespectsOverlayActivation(OverlayActivation mode)
|
|
|
|
|
{
|
|
|
|
|
AddStep($"set activation mode to {mode}", () => toolbar.OverlayActivationMode.Value = mode);
|
|
|
|
|
AddStep("hide toolbar", () => toolbar.Hide());
|
|
|
|
|
|
|
|
|
|
if (mode == OverlayActivation.Disabled)
|
|
|
|
|
AddAssert("check buttons not accepting input", () => InputManager.NonPositionalInputQueue.OfType<ToolbarButton>().Count(), () => Is.Zero);
|
|
|
|
|
else
|
|
|
|
|
AddAssert("check buttons accepting input", () => InputManager.NonPositionalInputQueue.OfType<ToolbarButton>().Count(), () => Is.Not.Zero);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-18 21:25:51 +08: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 18:10:45 +08:00
|
|
|
|
AddAssert("toolbar still hidden", () => toolbar.State.Value == Visibility.Hidden);
|
2020-08-18 21:25:51 +08:00
|
|
|
|
else
|
2020-08-19 18:09:35 +08:00
|
|
|
|
AddAssert("toolbar is visible", () => toolbar.State.Value == Visibility.Visible);
|
2020-08-18 21:25:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 00:04:01 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestScrollInput()
|
|
|
|
|
{
|
|
|
|
|
OsuScrollContainer scroll = null;
|
|
|
|
|
|
|
|
|
|
AddStep("add scroll layer", () => Add(scroll = new OsuScrollContainer
|
|
|
|
|
{
|
|
|
|
|
Depth = 1f,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Child = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = DrawHeight * 2,
|
|
|
|
|
Colour = ColourInfo.GradientVertical(Color4.Gray, Color4.DarkGray),
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
AddStep("hover toolbar", () => InputManager.MoveMouseTo(toolbar));
|
|
|
|
|
AddStep("perform scroll", () => InputManager.ScrollVerticalBy(500));
|
|
|
|
|
AddAssert("not scrolled", () => scroll.Current == 0);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 01:35:09 +08:00
|
|
|
|
[Test]
|
2022-06-15 14:57:09 +08:00
|
|
|
|
public void TestVolumeControlViaMusicButtonScroll()
|
2022-06-15 01:35:09 +08:00
|
|
|
|
{
|
|
|
|
|
AddStep("hover toolbar music button", () => InputManager.MoveMouseTo(this.ChildrenOfType<ToolbarMusicButton>().Single()));
|
|
|
|
|
|
|
|
|
|
AddStep("reset volume", () => Audio.Volume.Value = 1);
|
2022-06-17 01:22:56 +08:00
|
|
|
|
AddStep("hide volume overlay", () => volumeOverlay.Hide());
|
2022-06-15 01:35:09 +08:00
|
|
|
|
|
|
|
|
|
AddRepeatStep("scroll down", () => InputManager.ScrollVerticalBy(-10), 5);
|
|
|
|
|
AddAssert("volume lowered down", () => Audio.Volume.Value < 1);
|
|
|
|
|
AddRepeatStep("scroll up", () => InputManager.ScrollVerticalBy(10), 5);
|
|
|
|
|
AddAssert("volume raised up", () => Audio.Volume.Value == 1);
|
2022-06-17 01:22:56 +08:00
|
|
|
|
|
|
|
|
|
AddStep("move mouse away", () => InputManager.MoveMouseTo(Vector2.Zero));
|
|
|
|
|
AddAssert("button not hovered", () => !this.ChildrenOfType<ToolbarMusicButton>().Single().IsHovered);
|
|
|
|
|
|
|
|
|
|
AddStep("set volume to 0.5", () => Audio.Volume.Value = 0.5);
|
|
|
|
|
AddStep("hide volume overlay", () => volumeOverlay.Hide());
|
|
|
|
|
|
|
|
|
|
AddRepeatStep("scroll down", () => InputManager.ScrollVerticalBy(-10), 5);
|
|
|
|
|
AddAssert("volume not changed", () => Audio.Volume.Value == 0.5);
|
|
|
|
|
AddRepeatStep("scroll up", () => InputManager.ScrollVerticalBy(10), 5);
|
|
|
|
|
AddAssert("volume not changed", () => Audio.Volume.Value == 0.5);
|
2022-06-15 01:35:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 14:57:09 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestVolumeControlViaMusicButtonArrowKeys()
|
|
|
|
|
{
|
|
|
|
|
AddStep("hover toolbar music button", () => InputManager.MoveMouseTo(this.ChildrenOfType<ToolbarMusicButton>().Single()));
|
|
|
|
|
|
|
|
|
|
AddStep("reset volume", () => Audio.Volume.Value = 1);
|
2022-06-17 01:22:56 +08:00
|
|
|
|
AddStep("hide volume overlay", () => volumeOverlay.Hide());
|
2022-06-15 14:57:09 +08:00
|
|
|
|
|
|
|
|
|
AddRepeatStep("arrow down", () => InputManager.Key(Key.Down), 5);
|
|
|
|
|
AddAssert("volume lowered down", () => Audio.Volume.Value < 1);
|
|
|
|
|
AddRepeatStep("arrow up", () => InputManager.Key(Key.Up), 5);
|
|
|
|
|
AddAssert("volume raised up", () => Audio.Volume.Value == 1);
|
2022-06-17 01:22:56 +08:00
|
|
|
|
|
|
|
|
|
AddStep("hide volume overlay", () => volumeOverlay.Hide());
|
|
|
|
|
AddStep("move mouse away", () => InputManager.MoveMouseTo(Vector2.Zero));
|
|
|
|
|
AddAssert("button not hovered", () => !this.ChildrenOfType<ToolbarMusicButton>().Single().IsHovered);
|
|
|
|
|
|
|
|
|
|
AddStep("set volume", () => Audio.Volume.Value = 0.5);
|
|
|
|
|
AddStep("hide volume overlay", () => volumeOverlay.Hide());
|
|
|
|
|
|
|
|
|
|
AddRepeatStep("arrow down", () => InputManager.Key(Key.Down), 5);
|
|
|
|
|
AddAssert("volume not changed", () => Audio.Volume.Value == 0.5);
|
|
|
|
|
AddRepeatStep("arrow up", () => InputManager.Key(Key.Up), 5);
|
|
|
|
|
AddAssert("volume not changed", () => Audio.Volume.Value == 0.5);
|
2022-06-15 14:57:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-29 20:16:13 +08:00
|
|
|
|
[Test]
|
|
|
|
|
public void TestRulesetSelectorOverflow()
|
|
|
|
|
{
|
|
|
|
|
AddStep("set toolbar width", () =>
|
|
|
|
|
{
|
|
|
|
|
toolbar.RelativeSizeAxes = Axes.None;
|
2022-12-30 05:48:33 +08:00
|
|
|
|
toolbar.Width = 400;
|
2022-12-29 20:16:13 +08:00
|
|
|
|
});
|
|
|
|
|
AddStep("move mouse over news toggle button", () =>
|
|
|
|
|
{
|
|
|
|
|
var button = toolbar.ChildrenOfType<ToolbarNewsButton>().Single();
|
|
|
|
|
InputManager.MoveMouseTo(button);
|
|
|
|
|
});
|
|
|
|
|
AddAssert("no ruleset toggle buttons hovered", () => !toolbar.ChildrenOfType<ToolbarRulesetTabButton>().Any(button => button.IsHovered));
|
2022-12-30 05:48:33 +08:00
|
|
|
|
AddUntilStep("toolbar gradient visible", () => toolbar.ChildrenOfType<Toolbar.ToolbarBackground>().Single().Children.All(d => d.Alpha > 0));
|
2022-12-29 20:16:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class TestToolbar : Toolbar
|
2020-08-18 21:25:51 +08:00
|
|
|
|
{
|
2020-08-31 17:16:13 +08:00
|
|
|
|
public new Bindable<OverlayActivation> OverlayActivationMode => base.OverlayActivationMode as Bindable<OverlayActivation>;
|
2020-08-18 21:25:51 +08:00
|
|
|
|
}
|
2022-06-15 01:05:07 +08:00
|
|
|
|
|
|
|
|
|
// interface mocks break hot reload, mocking this stub implementation instead works around it.
|
|
|
|
|
// see: https://github.com/moq/moq4/issues/1252
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
public class TestNotificationOverlay : INotificationOverlay
|
|
|
|
|
{
|
|
|
|
|
public virtual void Post(Notification notification)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual void Hide()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public virtual IBindable<int> UnreadCount => null;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|