mirror of
https://github.com/ppy/osu
synced 2025-01-20 13:00:54 +00:00
Move mouse input detection inside MenuCursorContainer
to allow testing
This commit is contained in:
parent
ba72f13f54
commit
06e6713237
@ -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,
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user