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
|
|
|
|
|
2021-12-21 12:20:12 +08:00
|
|
|
|
using System.Linq;
|
2018-04-06 14:20:09 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-06-07 11:53:51 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2021-12-21 12:20:12 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Framework.Testing;
|
2018-04-06 14:20:09 +08:00
|
|
|
|
using osu.Framework.Testing.Input;
|
2023-07-07 12:32:15 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2019-04-23 12:32:44 +08:00
|
|
|
|
using osu.Game.Graphics.Cursor;
|
2019-06-07 11:53:51 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2022-11-24 15:26:57 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
2020-01-27 11:21:17 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2019-06-07 11:53:51 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2021-12-21 12:20:12 +08:00
|
|
|
|
using osuTK.Input;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-04-06 14:20:09 +08:00
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
|
{
|
2020-03-23 09:01:33 +08:00
|
|
|
|
public abstract partial class OsuManualInputManagerTestScene : OsuTestScene
|
2018-04-06 14:20:09 +08:00
|
|
|
|
{
|
2019-04-23 12:32:44 +08:00
|
|
|
|
protected override Container<Drawable> Content => content;
|
|
|
|
|
private readonly Container content;
|
|
|
|
|
|
2018-04-06 14:20:09 +08:00
|
|
|
|
protected readonly ManualInputManager InputManager;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-07-07 12:32:15 +08:00
|
|
|
|
private readonly Container takeControlOverlay;
|
|
|
|
|
|
2021-04-06 14:05:34 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether to create a nested container to handle <see cref="GlobalAction"/>s that result from local (manual) test input.
|
|
|
|
|
/// This should be disabled when instantiating an <see cref="OsuGame"/> instance else actions will be lost.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual bool CreateNestedActionContainer => true;
|
|
|
|
|
|
2022-10-15 05:19:40 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether a menu cursor controlled by the manual input manager should be displayed.
|
|
|
|
|
/// True by default, but is disabled for <see cref="OsuGameTestScene"/>s as they provide their own global cursor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected virtual bool DisplayCursorForManualInput => true;
|
|
|
|
|
|
2020-03-23 09:01:33 +08:00
|
|
|
|
protected OsuManualInputManagerTestScene()
|
2018-04-06 14:20:09 +08:00
|
|
|
|
{
|
2022-10-15 05:19:40 +08:00
|
|
|
|
var mainContent = content = new Container { RelativeSizeAxes = Axes.Both };
|
2020-03-30 18:15:44 +08:00
|
|
|
|
|
2022-10-15 05:19:40 +08:00
|
|
|
|
if (DisplayCursorForManualInput)
|
2021-07-17 16:26:11 +08:00
|
|
|
|
{
|
2022-10-15 05:19:40 +08:00
|
|
|
|
var cursorDisplay = new GlobalCursorDisplay { RelativeSizeAxes = Axes.Both };
|
|
|
|
|
|
2023-01-11 06:05:08 +08:00
|
|
|
|
cursorDisplay.Add(content = new OsuTooltipContainer(cursorDisplay.MenuCursor)
|
2022-10-15 05:19:40 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
});
|
|
|
|
|
|
2023-01-17 15:24:47 +08:00
|
|
|
|
mainContent.Add(cursorDisplay);
|
2022-10-15 05:19:40 +08:00
|
|
|
|
}
|
2021-04-06 14:05:34 +08:00
|
|
|
|
|
|
|
|
|
if (CreateNestedActionContainer)
|
2023-01-17 15:24:47 +08:00
|
|
|
|
mainContent.Add(new GlobalActionContainer(null));
|
2021-04-06 14:05:34 +08:00
|
|
|
|
|
2019-06-07 11:53:51 +08:00
|
|
|
|
base.Content.AddRange(new Drawable[]
|
2019-04-23 12:32:44 +08:00
|
|
|
|
{
|
2019-06-07 11:53:51 +08:00
|
|
|
|
InputManager = new ManualInputManager
|
|
|
|
|
{
|
|
|
|
|
UseParentInput = true,
|
2021-06-14 12:18:52 +08:00
|
|
|
|
Child = mainContent
|
2019-06-07 11:53:51 +08:00
|
|
|
|
},
|
2023-07-07 12:32:15 +08:00
|
|
|
|
takeControlOverlay = new Container
|
2019-06-07 11:53:51 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2023-07-07 12:32:15 +08:00
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
Margin = new MarginPadding(40),
|
2019-06-07 11:53:51 +08:00
|
|
|
|
CornerRadius = 5,
|
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
Colour = Color4.Black,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2023-07-07 12:32:15 +08:00
|
|
|
|
Alpha = 0.4f,
|
2019-06-07 11:53:51 +08:00
|
|
|
|
},
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
2023-07-07 12:32:15 +08:00
|
|
|
|
Margin = new MarginPadding(10),
|
|
|
|
|
Spacing = new Vector2(10),
|
2019-06-07 11:53:51 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
2023-07-07 12:32:15 +08:00
|
|
|
|
Font = OsuFont.Default.With(weight: FontWeight.Bold),
|
|
|
|
|
Text = "The test is currently overriding local input",
|
2019-06-07 11:53:51 +08:00
|
|
|
|
},
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Spacing = new Vector2(5),
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2023-07-08 21:03:33 +08:00
|
|
|
|
new RoundedButton
|
2019-06-07 11:53:51 +08:00
|
|
|
|
{
|
2023-07-07 12:32:15 +08:00
|
|
|
|
Text = "Take control back",
|
|
|
|
|
Size = new Vector2(180, 30),
|
|
|
|
|
Action = () => InputManager.UseParentInput = true
|
2019-06-07 11:53:51 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
2019-04-23 12:32:44 +08:00
|
|
|
|
});
|
2018-04-06 14:20:09 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-07-07 12:32:15 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
takeControlOverlay.Alpha = InputManager.UseParentInput ? 0 : 1;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 12:20:12 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Wait for a button to become enabled, then click it.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
|
|
protected void ClickButtonWhenEnabled<T>()
|
|
|
|
|
where T : Drawable
|
|
|
|
|
{
|
|
|
|
|
if (typeof(T) == typeof(Button))
|
2022-03-17 16:59:26 +08:00
|
|
|
|
AddUntilStep($"wait for {typeof(T).Name} enabled", () => (this.ChildrenOfType<T>().Single() as ClickableContainer)?.Enabled.Value == true);
|
2021-12-21 12:20:12 +08:00
|
|
|
|
else
|
2022-03-17 16:59:26 +08:00
|
|
|
|
AddUntilStep($"wait for {typeof(T).Name} enabled", () => this.ChildrenOfType<T>().Single().ChildrenOfType<ClickableContainer>().Single().Enabled.Value);
|
2021-12-21 12:20:12 +08:00
|
|
|
|
|
|
|
|
|
AddStep($"click {typeof(T).Name}", () =>
|
|
|
|
|
{
|
|
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<T>().Single());
|
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
|
});
|
|
|
|
|
}
|
2018-04-06 14:20:09 +08:00
|
|
|
|
}
|
|
|
|
|
}
|