Move mouse input detection inside MenuCursorContainer to allow testing

This commit is contained in:
Salman Ahmed 2022-10-15 00:18:24 +03:00
parent ba72f13f54
commit 06e6713237
2 changed files with 35 additions and 35 deletions

View File

@ -14,7 +14,6 @@ using osu.Framework.Graphics.Textures;
using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osu.Game.Configuration;
using osu.Game.Input;
using osuTK;
namespace osu.Game.Graphics.Cursor
@ -35,6 +34,8 @@ namespace osu.Game.Graphics.Cursor
private Bindable<bool> cursorRotate = null!;
private Sample tapSample = null!;
private MouseInputDetector mouseInputDetector = null!;
private bool visible;
[BackgroundDependencyLoader]
@ -46,10 +47,9 @@ namespace osu.Game.Graphics.Cursor
screenshotCursorVisibility.BindTo(screenshotManager.CursorVisibility);
tapSample = audio.Samples.Get(@"UI/cursor-tap");
}
[Resolved]
private OsuUserInputManager? inputManager { get; set; }
Add(mouseInputDetector = new MouseInputDetector());
}
[Resolved]
private OsuGame? game { get; set; }
@ -61,11 +61,8 @@ namespace osu.Game.Graphics.Cursor
{
base.LoadComplete();
if (inputManager != null)
{
lastInputWasMouse.BindTo(inputManager.LastInputWasMouseSource);
lastInputWasMouse.BindValueChanged(_ => updateState(), true);
}
lastInputWasMouse.BindTo(mouseInputDetector.LastInputWasMouseSource);
lastInputWasMouse.BindValueChanged(_ => updateState(), true);
if (game != null)
{
@ -247,6 +244,35 @@ namespace osu.Game.Graphics.Cursor
}
}
private class MouseInputDetector : Component
{
/// <summary>
/// Whether the last input applied to the game is sourced from mouse.
/// </summary>
public IBindable<bool> LastInputWasMouseSource => lastInputWasMouseSource;
private readonly Bindable<bool> lastInputWasMouseSource = new Bindable<bool>();
public MouseInputDetector()
{
RelativeSizeAxes = Axes.Both;
}
protected override bool Handle(UIEvent e)
{
switch (e)
{
case MouseEvent:
lastInputWasMouseSource.Value = true;
return false;
default:
lastInputWasMouseSource.Value = false;
return false;
}
}
}
private enum DragRotationState
{
NotDragging,

View File

@ -3,43 +3,17 @@
#nullable disable
using osu.Framework.Bindables;
using osu.Framework.Input;
using osu.Framework.Input.StateChanges.Events;
using osuTK.Input;
namespace osu.Game.Input
{
public class OsuUserInputManager : UserInputManager
{
/// <summary>
/// Whether the last input applied to the game is sourced from mouse.
/// </summary>
public IBindable<bool> LastInputWasMouseSource => lastInputWasMouseSource;
private readonly Bindable<bool> lastInputWasMouseSource = new Bindable<bool>();
internal OsuUserInputManager()
{
}
public override void HandleInputStateChange(InputStateChangeEvent inputStateChange)
{
switch (inputStateChange)
{
case ButtonStateChangeEvent<MouseButton>:
case MousePositionChangeEvent:
lastInputWasMouseSource.Value = true;
break;
default:
lastInputWasMouseSource.Value = false;
break;
}
base.HandleInputStateChange(inputStateChange);
}
protected override MouseButtonEventManager CreateButtonEventManagerFor(MouseButton button)
{
switch (button)