mirror of
https://github.com/osukey/osukey.git
synced 2025-06-05 04:47:39 +09: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.Input.Events;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Configuration;
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Input;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Graphics.Cursor
|
namespace osu.Game.Graphics.Cursor
|
||||||
@ -35,6 +34,8 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
private Bindable<bool> cursorRotate = null!;
|
private Bindable<bool> cursorRotate = null!;
|
||||||
private Sample tapSample = null!;
|
private Sample tapSample = null!;
|
||||||
|
|
||||||
|
private MouseInputDetector mouseInputDetector = null!;
|
||||||
|
|
||||||
private bool visible;
|
private bool visible;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -46,10 +47,9 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
screenshotCursorVisibility.BindTo(screenshotManager.CursorVisibility);
|
screenshotCursorVisibility.BindTo(screenshotManager.CursorVisibility);
|
||||||
|
|
||||||
tapSample = audio.Samples.Get(@"UI/cursor-tap");
|
tapSample = audio.Samples.Get(@"UI/cursor-tap");
|
||||||
}
|
|
||||||
|
|
||||||
[Resolved]
|
Add(mouseInputDetector = new MouseInputDetector());
|
||||||
private OsuUserInputManager? inputManager { get; set; }
|
}
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuGame? game { get; set; }
|
private OsuGame? game { get; set; }
|
||||||
@ -61,11 +61,8 @@ namespace osu.Game.Graphics.Cursor
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
if (inputManager != null)
|
lastInputWasMouse.BindTo(mouseInputDetector.LastInputWasMouseSource);
|
||||||
{
|
lastInputWasMouse.BindValueChanged(_ => updateState(), true);
|
||||||
lastInputWasMouse.BindTo(inputManager.LastInputWasMouseSource);
|
|
||||||
lastInputWasMouse.BindValueChanged(_ => updateState(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (game != null)
|
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
|
private enum DragRotationState
|
||||||
{
|
{
|
||||||
NotDragging,
|
NotDragging,
|
||||||
|
@ -3,43 +3,17 @@
|
|||||||
|
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Input;
|
using osu.Framework.Input;
|
||||||
using osu.Framework.Input.StateChanges.Events;
|
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
|
|
||||||
namespace osu.Game.Input
|
namespace osu.Game.Input
|
||||||
{
|
{
|
||||||
public class OsuUserInputManager : UserInputManager
|
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()
|
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)
|
protected override MouseButtonEventManager CreateButtonEventManagerFor(MouseButton button)
|
||||||
{
|
{
|
||||||
switch (button)
|
switch (button)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user