1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 14:02:55 +08:00

Merge pull request #19389 from peppy/cursor-with-touch

Add ability to make cursor show even during touch input
This commit is contained in:
Dan Balasescu 2022-07-26 15:13:55 +09:00 committed by GitHub
commit 5345e431cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 153 additions and 132 deletions

View File

@ -31,7 +31,7 @@ namespace osu.Game.Tests.Visual.Gameplay
public TestScenePause()
{
base.Content.Add(content = new MenuCursorContainer { RelativeSizeAxes = Axes.Both });
base.Content.Add(content = new GlobalCursorDisplay { RelativeSizeAxes = Axes.Both });
}
[SetUpSteps]

View File

@ -21,12 +21,12 @@ namespace osu.Game.Tests.Visual.UserInterface
[TestFixture]
public class TestSceneCursors : OsuManualInputManagerTestScene
{
private readonly MenuCursorContainer menuCursorContainer;
private readonly GlobalCursorDisplay globalCursorDisplay;
private readonly CustomCursorBox[] cursorBoxes = new CustomCursorBox[6];
public TestSceneCursors()
{
Child = menuCursorContainer = new MenuCursorContainer
Child = globalCursorDisplay = new GlobalCursorDisplay
{
RelativeSizeAxes = Axes.Both,
Children = new[]
@ -96,11 +96,11 @@ namespace osu.Game.Tests.Visual.UserInterface
private void testUserCursor()
{
AddStep("Move to green area", () => InputManager.MoveMouseTo(cursorBoxes[0]));
AddAssert("Check green cursor visible", () => checkVisible(cursorBoxes[0].Cursor));
AddAssert("Check green cursor at mouse", () => checkAtMouse(cursorBoxes[0].Cursor));
AddAssert("Check green cursor visible", () => checkVisible(cursorBoxes[0].MenuCursor));
AddAssert("Check green cursor at mouse", () => checkAtMouse(cursorBoxes[0].MenuCursor));
AddStep("Move out", moveOut);
AddAssert("Check green cursor invisible", () => !checkVisible(cursorBoxes[0].Cursor));
AddAssert("Check global cursor visible", () => checkVisible(menuCursorContainer.Cursor));
AddAssert("Check green cursor invisible", () => !checkVisible(cursorBoxes[0].MenuCursor));
AddAssert("Check global cursor visible", () => checkVisible(globalCursorDisplay.MenuCursor));
}
/// <summary>
@ -111,13 +111,13 @@ namespace osu.Game.Tests.Visual.UserInterface
private void testLocalCursor()
{
AddStep("Move to purple area", () => InputManager.MoveMouseTo(cursorBoxes[3]));
AddAssert("Check purple cursor visible", () => checkVisible(cursorBoxes[3].Cursor));
AddAssert("Check purple cursor at mouse", () => checkAtMouse(cursorBoxes[3].Cursor));
AddAssert("Check global cursor visible", () => checkVisible(menuCursorContainer.Cursor));
AddAssert("Check global cursor at mouse", () => checkAtMouse(menuCursorContainer.Cursor));
AddAssert("Check purple cursor visible", () => checkVisible(cursorBoxes[3].MenuCursor));
AddAssert("Check purple cursor at mouse", () => checkAtMouse(cursorBoxes[3].MenuCursor));
AddAssert("Check global cursor visible", () => checkVisible(globalCursorDisplay.MenuCursor));
AddAssert("Check global cursor at mouse", () => checkAtMouse(globalCursorDisplay.MenuCursor));
AddStep("Move out", moveOut);
AddAssert("Check purple cursor visible", () => checkVisible(cursorBoxes[3].Cursor));
AddAssert("Check global cursor visible", () => checkVisible(menuCursorContainer.Cursor));
AddAssert("Check purple cursor visible", () => checkVisible(cursorBoxes[3].MenuCursor));
AddAssert("Check global cursor visible", () => checkVisible(globalCursorDisplay.MenuCursor));
}
/// <summary>
@ -128,12 +128,12 @@ namespace osu.Game.Tests.Visual.UserInterface
private void testUserCursorOverride()
{
AddStep("Move to blue-green boundary", () => InputManager.MoveMouseTo(cursorBoxes[1].ScreenSpaceDrawQuad.BottomRight - new Vector2(10)));
AddAssert("Check blue cursor visible", () => checkVisible(cursorBoxes[1].Cursor));
AddAssert("Check green cursor invisible", () => !checkVisible(cursorBoxes[0].Cursor));
AddAssert("Check blue cursor at mouse", () => checkAtMouse(cursorBoxes[1].Cursor));
AddAssert("Check blue cursor visible", () => checkVisible(cursorBoxes[1].MenuCursor));
AddAssert("Check green cursor invisible", () => !checkVisible(cursorBoxes[0].MenuCursor));
AddAssert("Check blue cursor at mouse", () => checkAtMouse(cursorBoxes[1].MenuCursor));
AddStep("Move out", moveOut);
AddAssert("Check blue cursor not visible", () => !checkVisible(cursorBoxes[1].Cursor));
AddAssert("Check green cursor not visible", () => !checkVisible(cursorBoxes[0].Cursor));
AddAssert("Check blue cursor not visible", () => !checkVisible(cursorBoxes[1].MenuCursor));
AddAssert("Check green cursor not visible", () => !checkVisible(cursorBoxes[0].MenuCursor));
}
/// <summary>
@ -143,13 +143,13 @@ namespace osu.Game.Tests.Visual.UserInterface
private void testMultipleLocalCursors()
{
AddStep("Move to yellow-purple boundary", () => InputManager.MoveMouseTo(cursorBoxes[5].ScreenSpaceDrawQuad.BottomRight - new Vector2(10)));
AddAssert("Check purple cursor visible", () => checkVisible(cursorBoxes[3].Cursor));
AddAssert("Check purple cursor at mouse", () => checkAtMouse(cursorBoxes[3].Cursor));
AddAssert("Check yellow cursor visible", () => checkVisible(cursorBoxes[5].Cursor));
AddAssert("Check yellow cursor at mouse", () => checkAtMouse(cursorBoxes[5].Cursor));
AddAssert("Check purple cursor visible", () => checkVisible(cursorBoxes[3].MenuCursor));
AddAssert("Check purple cursor at mouse", () => checkAtMouse(cursorBoxes[3].MenuCursor));
AddAssert("Check yellow cursor visible", () => checkVisible(cursorBoxes[5].MenuCursor));
AddAssert("Check yellow cursor at mouse", () => checkAtMouse(cursorBoxes[5].MenuCursor));
AddStep("Move out", moveOut);
AddAssert("Check purple cursor visible", () => checkVisible(cursorBoxes[3].Cursor));
AddAssert("Check yellow cursor visible", () => checkVisible(cursorBoxes[5].Cursor));
AddAssert("Check purple cursor visible", () => checkVisible(cursorBoxes[3].MenuCursor));
AddAssert("Check yellow cursor visible", () => checkVisible(cursorBoxes[5].MenuCursor));
}
/// <summary>
@ -159,13 +159,13 @@ namespace osu.Game.Tests.Visual.UserInterface
private void testUserOverrideWithLocal()
{
AddStep("Move to yellow-blue boundary", () => InputManager.MoveMouseTo(cursorBoxes[5].ScreenSpaceDrawQuad.TopRight - new Vector2(10)));
AddAssert("Check blue cursor visible", () => checkVisible(cursorBoxes[1].Cursor));
AddAssert("Check blue cursor at mouse", () => checkAtMouse(cursorBoxes[1].Cursor));
AddAssert("Check yellow cursor visible", () => checkVisible(cursorBoxes[5].Cursor));
AddAssert("Check yellow cursor at mouse", () => checkAtMouse(cursorBoxes[5].Cursor));
AddAssert("Check blue cursor visible", () => checkVisible(cursorBoxes[1].MenuCursor));
AddAssert("Check blue cursor at mouse", () => checkAtMouse(cursorBoxes[1].MenuCursor));
AddAssert("Check yellow cursor visible", () => checkVisible(cursorBoxes[5].MenuCursor));
AddAssert("Check yellow cursor at mouse", () => checkAtMouse(cursorBoxes[5].MenuCursor));
AddStep("Move out", moveOut);
AddAssert("Check blue cursor invisible", () => !checkVisible(cursorBoxes[1].Cursor));
AddAssert("Check yellow cursor visible", () => checkVisible(cursorBoxes[5].Cursor));
AddAssert("Check blue cursor invisible", () => !checkVisible(cursorBoxes[1].MenuCursor));
AddAssert("Check yellow cursor visible", () => checkVisible(cursorBoxes[5].MenuCursor));
}
/// <summary>
@ -191,7 +191,7 @@ namespace osu.Game.Tests.Visual.UserInterface
{
public bool SmoothTransition;
public CursorContainer Cursor { get; }
public CursorContainer MenuCursor { get; }
public bool ProvidingUserCursor { get; }
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => base.ReceivePositionalInputAt(screenSpacePos) || (SmoothTransition && !ProvidingUserCursor);
@ -218,7 +218,7 @@ namespace osu.Game.Tests.Visual.UserInterface
Origin = Anchor.Centre,
Text = providesUserCursor ? "User cursor" : "Local cursor"
},
Cursor = new TestCursorContainer
MenuCursor = new TestCursorContainer
{
State = { Value = providesUserCursor ? Visibility.Hidden : Visibility.Visible },
}

View File

@ -70,10 +70,10 @@ namespace osu.Game.Tournament
protected override void LoadComplete()
{
MenuCursorContainer.Cursor.AlwaysPresent = true; // required for tooltip display
GlobalCursorDisplay.MenuCursor.AlwaysPresent = true; // required for tooltip display
// we don't want to show the menu cursor as it would appear on stream output.
MenuCursorContainer.Cursor.Alpha = 0;
GlobalCursorDisplay.MenuCursor.Alpha = 0;
base.LoadComplete();

View File

@ -91,6 +91,7 @@ namespace osu.Game.Configuration
// Input
SetDefault(OsuSetting.MenuCursorSize, 1.0f, 0.5f, 2f, 0.01f);
SetDefault(OsuSetting.GameplayCursorSize, 1.0f, 0.1f, 2f, 0.01f);
SetDefault(OsuSetting.GameplayCursorDuringTouch, false);
SetDefault(OsuSetting.AutoCursorSize, false);
SetDefault(OsuSetting.MouseDisableButtons, false);
@ -292,6 +293,7 @@ namespace osu.Game.Configuration
MenuCursorSize,
GameplayCursorSize,
AutoCursorSize,
GameplayCursorDuringTouch,
DimLevel,
BlurLevel,
LightenDuringBreaks,

View File

@ -0,0 +1,92 @@
// 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.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Input;
using osu.Framework.Input.StateChanges;
using osu.Game.Configuration;
namespace osu.Game.Graphics.Cursor
{
/// <summary>
/// A container which provides the main <see cref="Cursor.MenuCursor"/>.
/// Also handles cases where a more localised cursor is provided by another component (via <see cref="IProvideCursor"/>).
/// </summary>
public class GlobalCursorDisplay : Container, IProvideCursor
{
/// <summary>
/// Control whether any cursor should be displayed.
/// </summary>
internal bool ShowCursor = true;
public CursorContainer MenuCursor { get; }
public bool ProvidingUserCursor => true;
protected override Container<Drawable> Content { get; } = new Container { RelativeSizeAxes = Axes.Both };
private Bindable<bool> showDuringTouch = null!;
private InputManager inputManager = null!;
private IProvideCursor? currentOverrideProvider;
[Resolved]
private OsuConfigManager config { get; set; } = null!;
public GlobalCursorDisplay()
{
AddRangeInternal(new Drawable[]
{
MenuCursor = new MenuCursor { State = { Value = Visibility.Hidden } },
Content = new Container { RelativeSizeAxes = Axes.Both }
});
}
protected override void LoadComplete()
{
base.LoadComplete();
inputManager = GetContainingInputManager();
showDuringTouch = config.GetBindable<bool>(OsuSetting.GameplayCursorDuringTouch);
}
protected override void Update()
{
base.Update();
var lastMouseSource = inputManager.CurrentState.Mouse.LastSource;
bool hasValidInput = lastMouseSource != null && (showDuringTouch.Value || lastMouseSource is not ISourcedFromTouch);
if (!hasValidInput || !ShowCursor)
{
currentOverrideProvider?.MenuCursor?.Hide();
currentOverrideProvider = null;
return;
}
IProvideCursor newOverrideProvider = this;
foreach (var d in inputManager.HoveredDrawables)
{
if (d is IProvideCursor p && p.ProvidingUserCursor)
{
newOverrideProvider = p;
break;
}
}
if (currentOverrideProvider == newOverrideProvider)
return;
currentOverrideProvider?.MenuCursor?.Hide();
newOverrideProvider.MenuCursor?.Show();
currentOverrideProvider = newOverrideProvider;
}
}
}

View File

@ -17,10 +17,10 @@ namespace osu.Game.Graphics.Cursor
/// The cursor provided by this <see cref="IDrawable"/>.
/// May be null if no cursor should be visible.
/// </summary>
CursorContainer Cursor { get; }
CursorContainer MenuCursor { get; }
/// <summary>
/// Whether <see cref="Cursor"/> should be displayed as the singular user cursor. This will temporarily hide any other user cursor.
/// Whether <see cref="MenuCursor"/> should be displayed as the singular user cursor. This will temporarily hide any other user cursor.
/// This value is checked every frame and may be used to control whether multiple cursors are displayed (e.g. watching replays).
/// </summary>
bool ProvidingUserCursor { get; }

View File

@ -1,83 +0,0 @@
// 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.
#nullable disable
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Input;
using osu.Framework.Input.StateChanges;
namespace osu.Game.Graphics.Cursor
{
/// <summary>
/// A container which provides a <see cref="MenuCursor"/> which can be overridden by hovered <see cref="Drawable"/>s.
/// </summary>
public class MenuCursorContainer : Container, IProvideCursor
{
protected override Container<Drawable> Content => content;
private readonly Container content;
/// <summary>
/// Whether any cursors can be displayed.
/// </summary>
internal bool CanShowCursor = true;
public CursorContainer Cursor { get; }
public bool ProvidingUserCursor => true;
public MenuCursorContainer()
{
AddRangeInternal(new Drawable[]
{
Cursor = new MenuCursor { State = { Value = Visibility.Hidden } },
content = new Container { RelativeSizeAxes = Axes.Both }
});
}
private InputManager inputManager;
protected override void LoadComplete()
{
base.LoadComplete();
inputManager = GetContainingInputManager();
}
private IProvideCursor currentTarget;
protected override void Update()
{
base.Update();
var lastMouseSource = inputManager.CurrentState.Mouse.LastSource;
bool hasValidInput = lastMouseSource != null && !(lastMouseSource is ISourcedFromTouch);
if (!hasValidInput || !CanShowCursor)
{
currentTarget?.Cursor?.Hide();
currentTarget = null;
return;
}
IProvideCursor newTarget = this;
foreach (var d in inputManager.HoveredDrawables)
{
if (d is IProvideCursor p && p.ProvidingUserCursor)
{
newTarget = p;
break;
}
}
if (currentTarget == newTarget)
return;
currentTarget?.Cursor?.Hide();
newTarget.Cursor?.Show();
currentTarget = newTarget;
}
}
}

View File

@ -34,6 +34,11 @@ namespace osu.Game.Localisation
/// </summary>
public static LocalisableString AutoCursorSize => new TranslatableString(getKey(@"auto_cursor_size"), @"Adjust gameplay cursor size based on current beatmap");
/// <summary>
/// "Show gameplay cursor during touch input"
/// </summary>
public static LocalisableString GameplayCursorDuringTouch => new TranslatableString(getKey(@"gameplay_cursor_during_touch"), @"Show gameplay cursor during touch input");
/// <summary>
/// "Beatmap skins"
/// </summary>

View File

@ -716,7 +716,7 @@ namespace osu.Game
// The next time this is updated is in UpdateAfterChildren, which occurs too late and results
// in the cursor being shown for a few frames during the intro.
// This prevents the cursor from showing until we have a screen with CursorVisible = true
MenuCursorContainer.CanShowCursor = menuScreen?.CursorVisible ?? false;
GlobalCursorDisplay.ShowCursor = menuScreen?.CursorVisible ?? false;
// todo: all archive managers should be able to be looped here.
SkinManager.PostNotification = n => Notifications.Post(n);
@ -1231,7 +1231,7 @@ namespace osu.Game
ScreenOffsetContainer.X = horizontalOffset;
overlayContent.X = horizontalOffset * 1.2f;
MenuCursorContainer.CanShowCursor = (ScreenStack.CurrentScreen as IOsuScreen)?.CursorVisible ?? false;
GlobalCursorDisplay.ShowCursor = (ScreenStack.CurrentScreen as IOsuScreen)?.CursorVisible ?? false;
}
private void screenChanged(IScreen current, IScreen newScreen)

View File

@ -138,7 +138,7 @@ namespace osu.Game
protected RealmKeyBindingStore KeyBindingStore { get; private set; }
protected MenuCursorContainer MenuCursorContainer { get; private set; }
protected GlobalCursorDisplay GlobalCursorDisplay { get; private set; }
protected MusicController MusicController { get; private set; }
@ -340,10 +340,10 @@ namespace osu.Game
RelativeSizeAxes = Axes.Both,
Child = CreateScalingContainer().WithChildren(new Drawable[]
{
(MenuCursorContainer = new MenuCursorContainer
(GlobalCursorDisplay = new GlobalCursorDisplay
{
RelativeSizeAxes = Axes.Both
}).WithChild(content = new OsuTooltipContainer(MenuCursorContainer.Cursor)
}).WithChild(content = new OsuTooltipContainer(GlobalCursorDisplay.MenuCursor)
{
RelativeSizeAxes = Axes.Both
}),

View File

@ -32,6 +32,11 @@ namespace osu.Game.Overlays.Settings.Sections.Gameplay
LabelText = SkinSettingsStrings.AutoCursorSize,
Current = config.GetBindable<bool>(OsuSetting.AutoCursorSize)
},
new SettingsCheckbox
{
LabelText = SkinSettingsStrings.GameplayCursorDuringTouch,
Current = config.GetBindable<bool>(OsuSetting.GameplayCursorDuringTouch)
},
};
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)

View File

@ -380,7 +380,7 @@ namespace osu.Game.Rulesets.UI
// only show the cursor when within the playfield, by default.
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Playfield.ReceivePositionalInputAt(screenSpacePos);
CursorContainer IProvideCursor.Cursor => Playfield.Cursor;
CursorContainer IProvideCursor.MenuCursor => Playfield.Cursor;
public override GameplayCursorContainer Cursor => Playfield.Cursor;

View File

@ -36,7 +36,7 @@ namespace osu.Game.Screens.Utility
public readonly Bindable<LatencyVisualMode> VisualMode = new Bindable<LatencyVisualMode>();
public CursorContainer? Cursor { get; private set; }
public CursorContainer? MenuCursor { get; private set; }
public bool ProvidingUserCursor => IsActiveArea.Value;
@ -91,7 +91,7 @@ namespace osu.Game.Screens.Utility
{
RelativeSizeAxes = Axes.Both,
},
Cursor = new LatencyCursorContainer
MenuCursor = new LatencyCursorContainer
{
RelativeSizeAxes = Axes.Both,
},
@ -105,7 +105,7 @@ namespace osu.Game.Screens.Utility
{
RelativeSizeAxes = Axes.Both,
},
Cursor = new LatencyCursorContainer
MenuCursor = new LatencyCursorContainer
{
RelativeSizeAxes = Axes.Both,
},
@ -119,7 +119,7 @@ namespace osu.Game.Screens.Utility
{
RelativeSizeAxes = Axes.Both,
},
Cursor = new LatencyCursorContainer
MenuCursor = new LatencyCursorContainer
{
RelativeSizeAxes = Axes.Both,
},

View File

@ -38,11 +38,11 @@ namespace osu.Game.Tests.Visual
protected OsuManualInputManagerTestScene()
{
MenuCursorContainer cursorContainer;
GlobalCursorDisplay cursorDisplay;
CompositeDrawable mainContent = cursorContainer = new MenuCursorContainer { RelativeSizeAxes = Axes.Both };
CompositeDrawable mainContent = cursorDisplay = new GlobalCursorDisplay { RelativeSizeAxes = Axes.Both };
cursorContainer.Child = content = new OsuTooltipContainer(cursorContainer.Cursor)
cursorDisplay.Child = content = new OsuTooltipContainer(cursorDisplay.MenuCursor)
{
RelativeSizeAxes = Axes.Both
};