1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 11:23:00 +08:00

Rename MenuCursorContainer and clean up code

This commit is contained in:
Dean Herbert 2022-07-26 14:11:52 +09:00
parent ee0c67e114
commit ef10145d6f
10 changed files with 80 additions and 82 deletions

View File

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

View File

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

View File

@ -70,10 +70,10 @@ namespace osu.Game.Tournament
protected override void LoadComplete() 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. // 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(); base.LoadComplete();

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -15,48 +13,48 @@ using osu.Game.Configuration;
namespace osu.Game.Graphics.Cursor namespace osu.Game.Graphics.Cursor
{ {
/// <summary> /// <summary>
/// A container which provides a <see cref="MenuCursor"/>. /// A container which provides the main <see cref="Cursor.MenuCursor"/>.
/// It also handles cases where a more localised cursor is provided by another component (via <see cref="IProvideCursor"/>). /// Also handles cases where a more localised cursor is provided by another component (via <see cref="IProvideCursor"/>).
/// </summary> /// </summary>
public class MenuCursorContainer : Container, IProvideCursor public class GlobalCursorDisplay : Container, IProvideCursor
{ {
protected override Container<Drawable> Content => content;
private readonly Container content;
/// <summary> /// <summary>
/// Whether any cursors can be displayed. /// Control whether any cursor should be displayed.
/// </summary> /// </summary>
internal bool CanShowCursor = true; internal bool ShowCursor = true;
public CursorContainer MenuCursor { get; }
public CursorContainer Cursor { get; }
public bool ProvidingUserCursor => true; public bool ProvidingUserCursor => true;
public MenuCursorContainer() 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[] AddRangeInternal(new Drawable[]
{ {
Cursor = new MenuCursor { State = { Value = Visibility.Hidden } }, MenuCursor = new MenuCursor { State = { Value = Visibility.Hidden } },
content = new Container { RelativeSizeAxes = Axes.Both } Content = new Container { RelativeSizeAxes = Axes.Both }
}); });
} }
private Bindable<bool> showDuringTouch;
private InputManager inputManager;
[Resolved]
private OsuConfigManager config { get; set; }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
inputManager = GetContainingInputManager();
inputManager = GetContainingInputManager();
showDuringTouch = config.GetBindable<bool>(OsuSetting.GameplayCursorDuringTouch); showDuringTouch = config.GetBindable<bool>(OsuSetting.GameplayCursorDuringTouch);
} }
private IProvideCursor currentTarget;
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
@ -64,31 +62,31 @@ namespace osu.Game.Graphics.Cursor
var lastMouseSource = inputManager.CurrentState.Mouse.LastSource; var lastMouseSource = inputManager.CurrentState.Mouse.LastSource;
bool hasValidInput = lastMouseSource != null && (showDuringTouch.Value || lastMouseSource is not ISourcedFromTouch); bool hasValidInput = lastMouseSource != null && (showDuringTouch.Value || lastMouseSource is not ISourcedFromTouch);
if (!hasValidInput || !CanShowCursor) if (!hasValidInput || !ShowCursor)
{ {
currentTarget?.Cursor?.Hide(); currentOverrideProvider?.MenuCursor?.Hide();
currentTarget = null; currentOverrideProvider = null;
return; return;
} }
IProvideCursor newTarget = this; IProvideCursor newOverrideProvider = this;
foreach (var d in inputManager.HoveredDrawables) foreach (var d in inputManager.HoveredDrawables)
{ {
if (d is IProvideCursor p && p.ProvidingUserCursor) if (d is IProvideCursor p && p.ProvidingUserCursor)
{ {
newTarget = p; newOverrideProvider = p;
break; break;
} }
} }
if (currentTarget == newTarget) if (currentOverrideProvider == newOverrideProvider)
return; return;
currentTarget?.Cursor?.Hide(); currentOverrideProvider?.MenuCursor?.Hide();
newTarget.Cursor?.Show(); newOverrideProvider.MenuCursor?.Show();
currentTarget = newTarget; currentOverrideProvider = newOverrideProvider;
} }
} }
} }

View File

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

View File

@ -716,7 +716,7 @@ namespace osu.Game
// The next time this is updated is in UpdateAfterChildren, which occurs too late and results // 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. // 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 // 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. // todo: all archive managers should be able to be looped here.
SkinManager.PostNotification = n => Notifications.Post(n); SkinManager.PostNotification = n => Notifications.Post(n);
@ -1231,7 +1231,7 @@ namespace osu.Game
ScreenOffsetContainer.X = horizontalOffset; ScreenOffsetContainer.X = horizontalOffset;
overlayContent.X = horizontalOffset * 1.2f; 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) private void screenChanged(IScreen current, IScreen newScreen)

View File

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

View File

@ -380,7 +380,7 @@ namespace osu.Game.Rulesets.UI
// only show the cursor when within the playfield, by default. // only show the cursor when within the playfield, by default.
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Playfield.ReceivePositionalInputAt(screenSpacePos); 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; 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 readonly Bindable<LatencyVisualMode> VisualMode = new Bindable<LatencyVisualMode>();
public CursorContainer? Cursor { get; private set; } public CursorContainer? MenuCursor { get; private set; }
public bool ProvidingUserCursor => IsActiveArea.Value; public bool ProvidingUserCursor => IsActiveArea.Value;
@ -91,7 +91,7 @@ namespace osu.Game.Screens.Utility
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}, },
Cursor = new LatencyCursorContainer MenuCursor = new LatencyCursorContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}, },
@ -105,7 +105,7 @@ namespace osu.Game.Screens.Utility
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}, },
Cursor = new LatencyCursorContainer MenuCursor = new LatencyCursorContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}, },
@ -119,7 +119,7 @@ namespace osu.Game.Screens.Utility
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}, },
Cursor = new LatencyCursorContainer MenuCursor = new LatencyCursorContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
}, },

View File

@ -38,11 +38,11 @@ namespace osu.Game.Tests.Visual
protected OsuManualInputManagerTestScene() 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 RelativeSizeAxes = Axes.Both
}; };