1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 20:12:57 +08:00

Adapt signature change of event handlers

This commit is contained in:
ekrctb 2018-09-19 20:52:57 +09:00
parent 99fc04c8af
commit 50091252e2
40 changed files with 94 additions and 103 deletions

View File

@ -6,10 +6,10 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Input.States;
using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Objects.Types;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Game.Skinning; using osu.Game.Skinning;
using OpenTK;
namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
{ {
@ -102,23 +102,23 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
}; };
} }
private InputState lastState; private Vector2? lastScreenSpaceMousePosition;
protected override bool OnMouseDown(MouseDownEvent e) protected override bool OnMouseDown(MouseDownEvent e)
{ {
lastState = state; lastScreenSpaceMousePosition = e.ScreenSpaceMousePosition;
return base.OnMouseDown(e); return base.OnMouseDown(e);
} }
protected override bool OnMouseUp(MouseUpEvent e) protected override bool OnMouseUp(MouseUpEvent e)
{ {
lastState = state; lastScreenSpaceMousePosition = e.ScreenSpaceMousePosition;
return base.OnMouseUp(e); return base.OnMouseUp(e);
} }
protected override bool OnMouseMove(MouseMoveEvent e) protected override bool OnMouseMove(MouseMoveEvent e)
{ {
lastState = e; lastScreenSpaceMousePosition = e.ScreenSpaceMousePosition;
return base.OnMouseMove(e); return base.OnMouseMove(e);
} }
@ -155,8 +155,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
{ {
// Make sure to use the base version of ReceivePositionalInputAt so that we correctly check the position. // Make sure to use the base version of ReceivePositionalInputAt so that we correctly check the position.
Tracking = canCurrentlyTrack Tracking = canCurrentlyTrack
&& lastState != null && lastScreenSpaceMousePosition.HasValue
&& ReceivePositionalInputAt(lastState.Mouse.NativeState.Position) && ReceivePositionalInputAt(lastScreenSpaceMousePosition.Value)
&& (drawableSlider?.OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false); && (drawableSlider?.OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false);
} }
} }

View File

@ -70,7 +70,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
protected override bool OnMouseMove(MouseMoveEvent e) protected override bool OnMouseMove(MouseMoveEvent e)
{ {
mousePosition = Parent.ToLocalSpace(e.Mouse.NativeState.Position); mousePosition = Parent.ToLocalSpace(e.ScreenSpaceMousePosition);
return base.OnMouseMove(e); return base.OnMouseMove(e);
} }

View File

@ -5,7 +5,6 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Input.States;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Osu namespace osu.Game.Rulesets.Osu
@ -36,13 +35,11 @@ namespace osu.Game.Rulesets.Osu
{ {
} }
protected override bool OnKeyDown(KeyDownEvent e) => AllowUserPresses && base.OnKeyDown(e); protected override bool Handle(UIEvent e)
protected override bool OnKeyUp(KeyUpEvent e) => AllowUserPresses && base.OnKeyUp(e); {
protected override bool OnJoystickPress(InputState state, JoystickEventArgs args) => AllowUserPresses && base.OnJoystickPress(args); if (!AllowUserPresses) return false;
protected override bool OnJoystickRelease(InputState state, JoystickEventArgs args) => AllowUserPresses && base.OnJoystickRelease(args); return base.Handle(e);
protected override bool OnMouseDown(MouseDownEvent e) => AllowUserPresses && base.OnMouseDown(e); }
protected override bool OnMouseUp(MouseUpEvent e) => AllowUserPresses && base.OnMouseUp(e);
protected override bool OnScroll(ScrollEvent e) => AllowUserPresses && base.OnScroll(e);
} }
} }

View File

@ -119,7 +119,7 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
protected override bool OnMouseMove(MouseMoveEvent e) protected override bool OnMouseMove(MouseMoveEvent e)
{ {
Vector2 pos = e.Mouse.NativeState.Position; Vector2 pos = e.ScreenSpaceMousePosition;
if (lastPosition == null) if (lastPosition == null)
{ {

View File

@ -184,7 +184,7 @@ namespace osu.Game.Tests.Visual
/// </summary> /// </summary>
/// <param name="cursorContainer">The cursor to check.</param> /// <param name="cursorContainer">The cursor to check.</param>
private bool checkAtMouse(CursorContainer cursorContainer) private bool checkAtMouse(CursorContainer cursorContainer)
=> Precision.AlmostEquals(InputManager.CurrentState.Mouse.NativeState.Position, cursorContainer.ToScreenSpace(cursorContainer.ActiveCursor.DrawPosition)); => Precision.AlmostEquals(InputManager.CurrentState.Mouse.Position, cursorContainer.ToScreenSpace(cursorContainer.ActiveCursor.DrawPosition));
private class CustomCursorBox : Container, IProvideCursor private class CustomCursorBox : Container, IProvideCursor
{ {

View File

@ -61,7 +61,7 @@ namespace osu.Game.Graphics.Containers
protected override bool OnClick(ClickEvent e) protected override bool OnClick(ClickEvent e)
{ {
if (!base.ReceivePositionalInputAt(state.Mouse.NativeState.Position)) if (!base.ReceivePositionalInputAt(e.ScreenSpaceMousePosition))
{ {
State = Visibility.Hidden; State = Visibility.Hidden;
return true; return true;

View File

@ -3,7 +3,6 @@
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Input.States;
using OpenTK.Input; using OpenTK.Input;
namespace osu.Game.Graphics.Containers namespace osu.Game.Graphics.Containers
@ -21,7 +20,7 @@ namespace osu.Game.Graphics.Containers
/// </summary> /// </summary>
public double DistanceDecayOnRightMouseScrollbar = 0.02; public double DistanceDecayOnRightMouseScrollbar = 0.02;
private bool shouldPerformRightMouseScroll(InputState state) => RightMouseScrollbar && state.Mouse.IsPressed(MouseButton.Right); private bool shouldPerformRightMouseScroll(MouseButtonEvent e) => RightMouseScrollbar && e.Button == MouseButton.Right;
private void scrollToRelative(float value) => ScrollTo(Clamp((value - Scrollbar.DrawSize[ScrollDim] / 2) / Scrollbar.Size[ScrollDim]), true, DistanceDecayOnRightMouseScrollbar); private void scrollToRelative(float value) => ScrollTo(Clamp((value - Scrollbar.DrawSize[ScrollDim] / 2) / Scrollbar.Size[ScrollDim]), true, DistanceDecayOnRightMouseScrollbar);
@ -31,9 +30,9 @@ namespace osu.Game.Graphics.Containers
protected override bool OnMouseDown(MouseDownEvent e) protected override bool OnMouseDown(MouseDownEvent e)
{ {
if (shouldPerformRightMouseScroll(state)) if (shouldPerformRightMouseScroll(e))
{ {
scrollToRelative(state.Mouse.Position[ScrollDim]); scrollToRelative(e.MousePosition[ScrollDim]);
return true; return true;
} }
@ -44,7 +43,7 @@ namespace osu.Game.Graphics.Containers
{ {
if (mouseScrollBarDragging) if (mouseScrollBarDragging)
{ {
scrollToRelative(e.Mouse.Position[ScrollDim]); scrollToRelative(e.MousePosition[ScrollDim]);
return true; return true;
} }

View File

@ -67,7 +67,7 @@ namespace osu.Game.Graphics.Containers
if (parallaxEnabled) if (parallaxEnabled)
{ {
Vector2 offset = (input.CurrentState.Mouse == null ? Vector2.Zero : ToLocalSpace(input.CurrentState.Mouse.NativeState.Position) - DrawSize / 2) * ParallaxAmount; Vector2 offset = (input.CurrentState.Mouse == null ? Vector2.Zero : ToLocalSpace(input.CurrentState.Mouse.Position) - DrawSize / 2) * ParallaxAmount;
double elapsed = MathHelper.Clamp(Clock.ElapsedFrameTime, 0, 1000); double elapsed = MathHelper.Clamp(Clock.ElapsedFrameTime, 0, 1000);

View File

@ -43,7 +43,7 @@ namespace osu.Game.Graphics.Cursor
{ {
if (dragRotationState != DragRotationState.NotDragging) if (dragRotationState != DragRotationState.NotDragging)
{ {
var position = e.Mouse.Position; var position = e.MousePosition;
var distance = Vector2Extensions.Distance(position, positionMouseDown); var distance = Vector2Extensions.Distance(position, positionMouseDown);
// don't start rotating until we're moved a minimum distance away from the mouse down location, // don't start rotating until we're moved a minimum distance away from the mouse down location,
// else it can have an annoying effect. // else it can have an annoying effect.
@ -52,7 +52,7 @@ namespace osu.Game.Graphics.Cursor
// don't rotate when distance is zero to avoid NaN // don't rotate when distance is zero to avoid NaN
if (dragRotationState == DragRotationState.Rotating && distance > 0) if (dragRotationState == DragRotationState.Rotating && distance > 0)
{ {
Vector2 offset = e.Mouse.Position - positionMouseDown; Vector2 offset = e.MousePosition - positionMouseDown;
float degrees = (float)MathHelper.RadiansToDegrees(Math.Atan2(-offset.X, offset.Y)) + 24.3f; float degrees = (float)MathHelper.RadiansToDegrees(Math.Atan2(-offset.X, offset.Y)) + 24.3f;
// Always rotate in the direction of least distance // Always rotate in the direction of least distance
@ -83,14 +83,14 @@ namespace osu.Game.Graphics.Cursor
if (e.Button == MouseButton.Left && cursorRotate) if (e.Button == MouseButton.Left && cursorRotate)
{ {
dragRotationState = DragRotationState.DragStarted; dragRotationState = DragRotationState.DragStarted;
positionMouseDown = state.Mouse.Position; positionMouseDown = e.MousePosition;
} }
return base.OnMouseDown(e); return base.OnMouseDown(e);
} }
protected override bool OnMouseUp(MouseUpEvent e) protected override bool OnMouseUp(MouseUpEvent e)
{ {
if (!state.Mouse.HasMainButtonPressed) if (!e.CurrentState.Mouse.HasMainButtonPressed)
{ {
activeCursor.AdditiveLayer.FadeOutFromOne(500, Easing.OutQuint); activeCursor.AdditiveLayer.FadeOutFromOne(500, Easing.OutQuint);
activeCursor.ScaleTo(1, 500, Easing.OutElastic); activeCursor.ScaleTo(1, 500, Easing.OutElastic);

View File

@ -34,7 +34,8 @@ namespace osu.Game.Graphics.UserInterface
protected override bool OnKeyDown(KeyDownEvent e) protected override bool OnKeyDown(KeyDownEvent e)
{ {
if (!state.Keyboard.ControlPressed && !state.Keyboard.ShiftPressed) var keyboard = e.CurrentState.Keyboard;
if (!keyboard.ControlPressed && !keyboard.ShiftPressed)
{ {
switch (e.Key) switch (e.Key)
{ {
@ -56,7 +57,7 @@ namespace osu.Game.Graphics.UserInterface
} }
} }
if (state.Keyboard.ShiftPressed) if (keyboard.ShiftPressed)
{ {
switch (e.Key) switch (e.Key)
{ {

View File

@ -206,10 +206,7 @@ namespace osu.Game.Overlays
{ {
if (isDragging) if (isDragging)
{ {
Trace.Assert(e.Mouse.PositionMouseDown != null); double targetChatHeight = startDragChatHeight - (e.MousePosition.Y - e.MouseDownPosition.Y) / Parent.DrawSize.Y;
// ReSharper disable once PossibleInvalidOperationException
double targetChatHeight = startDragChatHeight - (e.Mouse.Position.Y - e.Mouse.PositionMouseDown.Value.Y) / Parent.DrawSize.Y;
// If the channel selection screen is shown, mind its minimum height // If the channel selection screen is shown, mind its minimum height
if (channelSelection.State == Visibility.Visible && targetChatHeight > 1f - channel_selection_min_height) if (channelSelection.State == Visibility.Visible && targetChatHeight > 1f - channel_selection_min_height)

View File

@ -11,14 +11,12 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Input.States;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Input; using osu.Game.Input;
using OpenTK.Graphics; using OpenTK.Graphics;
using OpenTK.Input; using OpenTK.Input;
using JoystickEventArgs = osu.Framework.Input.EventArgs.JoystickEventArgs;
namespace osu.Game.Overlays.KeyBinding namespace osu.Game.Overlays.KeyBinding
{ {
@ -166,14 +164,14 @@ namespace osu.Game.Overlays.KeyBinding
} }
} }
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(state)); bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState));
return true; return true;
} }
protected override bool OnMouseUp(MouseUpEvent e) protected override bool OnMouseUp(MouseUpEvent e)
{ {
// don't do anything until the last button is released. // don't do anything until the last button is released.
if (!HasFocus || state.Mouse.Buttons.Any()) if (!HasFocus || e.CurrentState.Mouse.HasAnyButtonPressed)
return base.OnMouseUp(e); return base.OnMouseUp(e);
if (bindTarget.IsHovered) if (bindTarget.IsHovered)
@ -189,7 +187,7 @@ namespace osu.Game.Overlays.KeyBinding
{ {
if (bindTarget.IsHovered) if (bindTarget.IsHovered)
{ {
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e, e.Mouse.ScrollDelta)); bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState, e.ScrollDelta));
finalise(); finalise();
return true; return true;
} }
@ -207,7 +205,7 @@ namespace osu.Game.Overlays.KeyBinding
{ {
case Key.Delete: case Key.Delete:
{ {
if (state.Keyboard.ShiftPressed) if (e.CurrentState.Keyboard.ShiftPressed)
{ {
bindTarget.UpdateKeyCombination(InputKey.None); bindTarget.UpdateKeyCombination(InputKey.None);
finalise(); finalise();
@ -218,7 +216,7 @@ namespace osu.Game.Overlays.KeyBinding
} }
} }
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(state)); bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState));
if (!isModifier(e.Key)) finalise(); if (!isModifier(e.Key)) finalise();
return true; return true;
@ -232,21 +230,21 @@ namespace osu.Game.Overlays.KeyBinding
return true; return true;
} }
protected override bool OnJoystickPress(InputState state, JoystickEventArgs args) protected override bool OnJoystickPress(JoystickPressEvent e)
{ {
if (!HasFocus) if (!HasFocus)
return false; return false;
bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(state)); bindTarget.UpdateKeyCombination(KeyCombination.FromInputState(e.CurrentState));
finalise(); finalise();
return true; return true;
} }
protected override bool OnJoystickRelease(InputState state, JoystickEventArgs args) protected override bool OnJoystickRelease(JoystickReleaseEvent e)
{ {
if (!HasFocus) if (!HasFocus)
return base.OnJoystickRelease(args); return base.OnJoystickRelease(e);
finalise(); finalise();
return true; return true;

View File

@ -183,7 +183,7 @@ namespace osu.Game.Overlays
protected override void OnFocusLost(FocusLostEvent e) protected override void OnFocusLost(FocusLostEvent e)
{ {
if (e.Keyboard.Keys.Contains(Key.Escape)) dismiss(); if (e.CurrentState.Keyboard.IsPressed(Key.Escape)) dismiss();
} }
private const double initial_duration = 400; private const double initial_duration = 400;

View File

@ -159,7 +159,7 @@ namespace osu.Game.Overlays.Mods
scaleContainer.ScaleTo(1, 500, Easing.OutElastic); scaleContainer.ScaleTo(1, 500, Easing.OutElastic);
// only trigger the event if we are inside the area of the button // only trigger the event if we are inside the area of the button
if (Contains(ToScreenSpace(state.Mouse.Position - Position))) if (Contains(e.ScreenSpaceMousePosition))
{ {
switch (e.Button) switch (e.Button)
{ {

View File

@ -60,7 +60,7 @@ namespace osu.Game.Overlays.Mods
{ {
var index = Array.IndexOf(ToggleKeys, e.Key); var index = Array.IndexOf(ToggleKeys, e.Key);
if (index > -1 && index < buttons.Length) if (index > -1 && index < buttons.Length)
buttons[index].SelectNext(state.Keyboard.ShiftPressed ? -1 : 1); buttons[index].SelectNext(e.CurrentState.Keyboard.ShiftPressed ? -1 : 1);
} }
return base.OnKeyDown(e); return base.OnKeyDown(e);

View File

@ -117,14 +117,14 @@ namespace osu.Game.Overlays.Music
protected override bool OnDragStart(DragStartEvent e) protected override bool OnDragStart(DragStartEvent e)
{ {
nativeDragPosition = e.Mouse.NativeState.Position; nativeDragPosition = e.ScreenSpaceMousePosition;
draggedItem = items.FirstOrDefault(d => d.IsDraggable); draggedItem = items.FirstOrDefault(d => d.IsDraggable);
return draggedItem != null || base.OnDragStart(e); return draggedItem != null || base.OnDragStart(e);
} }
protected override bool OnDrag(DragEvent e) protected override bool OnDrag(DragEvent e)
{ {
nativeDragPosition = e.Mouse.NativeState.Position; nativeDragPosition = e.ScreenSpaceMousePosition;
if (draggedItem == null) if (draggedItem == null)
return base.OnDrag(e); return base.OnDrag(e);
return true; return true;
@ -132,7 +132,7 @@ namespace osu.Game.Overlays.Music
protected override bool OnDragEnd(DragEndEvent e) protected override bool OnDragEnd(DragEndEvent e)
{ {
nativeDragPosition = e.Mouse.NativeState.Position; nativeDragPosition = e.ScreenSpaceMousePosition;
var handled = draggedItem != null || base.OnDragEnd(e); var handled = draggedItem != null || base.OnDragEnd(e);
draggedItem = null; draggedItem = null;

View File

@ -457,20 +457,14 @@ namespace osu.Game.Overlays
private class DragContainer : Container private class DragContainer : Container
{ {
private Vector2 dragStart;
protected override bool OnDragStart(DragStartEvent e) protected override bool OnDragStart(DragStartEvent e)
{ {
base.OnDragStart(e);
dragStart = e.Mouse.Position;
return true; return true;
} }
protected override bool OnDrag(DragEvent e) protected override bool OnDrag(DragEvent e)
{ {
if (base.OnDrag(e)) return true; Vector2 change = e.MousePosition - e.MouseDownPosition;
Vector2 change = e.Mouse.Position - dragStart;
// Diminish the drag distance as we go further to simulate "rubber band" feeling. // Diminish the drag distance as we go further to simulate "rubber band" feeling.
change *= change.Length <= 0 ? 0 : (float)Math.Pow(change.Length, 0.7f) / change.Length; change *= change.Length <= 0 ? 0 : (float)Math.Pow(change.Length, 0.7f) / change.Length;

View File

@ -141,7 +141,7 @@ namespace osu.Game.Overlays.Profile.Header
{ {
if (ranks?.Length > 1) if (ranks?.Length > 1)
{ {
graph.UpdateBallPosition(e.Mouse.Position.X); graph.UpdateBallPosition(e.MousePosition.X);
graph.ShowBall(); graph.ShowBall();
} }
return base.OnHover(e); return base.OnHover(e);
@ -150,7 +150,7 @@ namespace osu.Game.Overlays.Profile.Header
protected override bool OnMouseMove(MouseMoveEvent e) protected override bool OnMouseMove(MouseMoveEvent e)
{ {
if (ranks?.Length > 1) if (ranks?.Length > 1)
graph.UpdateBallPosition(e.Mouse.Position.X); graph.UpdateBallPosition(e.MousePosition.X);
return base.OnMouseMove(e); return base.OnMouseMove(e);
} }

View File

@ -89,7 +89,7 @@ namespace osu.Game.Overlays.Toolbar
{ {
base.OnKeyDown(e); base.OnKeyDown(e);
if (state.Keyboard.ControlPressed && !e.Repeat && e.Key >= Key.Number1 && e.Key <= Key.Number9) if (e.CurrentState.Keyboard.ControlPressed && !e.Repeat && e.Key >= Key.Number1 && e.Key <= Key.Number9)
{ {
int requested = e.Key - Key.Number1; int requested = e.Key - Key.Number1;

View File

@ -241,7 +241,7 @@ namespace osu.Game.Overlays.Volume
protected override bool OnScroll(ScrollEvent e) protected override bool OnScroll(ScrollEvent e)
{ {
adjust(e.Mouse.ScrollDelta.Y, e.Mouse.HasPreciseScroll); adjust(e.ScrollDelta.Y, e.IsPrecise);
return true; return true;
} }

View File

@ -37,7 +37,7 @@ namespace osu.Game.Rulesets.Edit
/// <summary> /// <summary>
/// Invoked when this <see cref="HitObjectMask"/> has requested drag. /// Invoked when this <see cref="HitObjectMask"/> has requested drag.
/// </summary> /// </summary>
public event Action<HitObjectMask, InputState> DragRequested; public event Action<HitObjectMask, Vector2, InputState> DragRequested;
/// <summary> /// <summary>
/// The <see cref="DrawableHitObject"/> which this <see cref="HitObjectMask"/> applies to. /// The <see cref="DrawableHitObject"/> which this <see cref="HitObjectMask"/> applies to.
@ -102,7 +102,7 @@ namespace osu.Game.Rulesets.Edit
if (State == SelectionState.NotSelected) if (State == SelectionState.NotSelected)
{ {
SelectionRequested?.Invoke(this, state); SelectionRequested?.Invoke(this, e.CurrentState);
selectionRequested = true; selectionRequested = true;
} }
@ -114,7 +114,7 @@ namespace osu.Game.Rulesets.Edit
if (State == SelectionState.Selected && !selectionRequested) if (State == SelectionState.Selected && !selectionRequested)
{ {
selectionRequested = true; selectionRequested = true;
SelectionRequested?.Invoke(this, e); SelectionRequested?.Invoke(this, e.CurrentState);
return true; return true;
} }
@ -125,7 +125,7 @@ namespace osu.Game.Rulesets.Edit
protected override bool OnDrag(DragEvent e) protected override bool OnDrag(DragEvent e)
{ {
DragRequested?.Invoke(this, e); DragRequested?.Invoke(this, e.Delta, e.CurrentState);
return true; return true;
} }

View File

@ -18,6 +18,9 @@ using osu.Game.Input.Handlers;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using OpenTK.Input; using OpenTK.Input;
using static osu.Game.Input.Handlers.ReplayInputHandler; using static osu.Game.Input.Handlers.ReplayInputHandler;
using JoystickState = osu.Framework.Input.States.JoystickState;
using KeyboardState = osu.Framework.Input.States.KeyboardState;
using MouseState = osu.Framework.Input.States.MouseState;
namespace osu.Game.Rulesets.UI namespace osu.Game.Rulesets.UI
{ {
@ -35,13 +38,7 @@ namespace osu.Game.Rulesets.UI
protected override InputState CreateInitialState() protected override InputState CreateInitialState()
{ {
var state = base.CreateInitialState(); var state = base.CreateInitialState();
return new RulesetInputManagerInputState<T> return new RulesetInputManagerInputState<T>(state.Mouse, state.Keyboard, state.Joystick);
{
Mouse = state.Mouse,
Keyboard = state.Keyboard,
Joystick = state.Joystick,
LastReplayState = null
};
} }
protected readonly KeyBindingContainer<T> KeyBindingContainer; protected readonly KeyBindingContainer<T> KeyBindingContainer;
@ -275,5 +272,10 @@ namespace osu.Game.Rulesets.UI
where T : struct where T : struct
{ {
public ReplayState<T> LastReplayState; public ReplayState<T> LastReplayState;
public RulesetInputManagerInputState(MouseState mouse = null, KeyboardState keyboard = null, JoystickState joystick = null)
: base(mouse, keyboard, joystick)
{
}
} }
} }

View File

@ -33,13 +33,13 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
protected override bool OnDragEnd(DragEndEvent e) => true; protected override bool OnDragEnd(DragEndEvent e) => true;
protected override bool OnDrag(DragEvent e) protected override bool OnDrag(DragEvent e)
{ {
seekToPosition(e.Mouse.NativeState.Position); seekToPosition(e.ScreenSpaceMousePosition);
return true; return true;
} }
protected override bool OnMouseDown(MouseDownEvent e) protected override bool OnMouseDown(MouseDownEvent e)
{ {
seekToPosition(state.Mouse.NativeState.Position); seekToPosition(e.ScreenSpaceMousePosition);
return true; return true;
} }

View File

@ -184,7 +184,7 @@ namespace osu.Game.Screens.Edit
protected override bool OnScroll(ScrollEvent e) protected override bool OnScroll(ScrollEvent e)
{ {
if (e.Mouse.ScrollDelta.X + e.Mouse.ScrollDelta.Y > 0) if (e.ScrollDelta.X + e.ScrollDelta.Y > 0)
clock.SeekBackward(!clock.IsRunning); clock.SeekBackward(!clock.IsRunning);
else else
clock.SeekForward(!clock.IsRunning); clock.SeekForward(!clock.IsRunning);

View File

@ -13,7 +13,6 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Input.States;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using OpenTK; using OpenTK;
@ -264,20 +263,20 @@ namespace osu.Game.Screens.Edit.Screens.Compose
protected override bool OnClick(ClickEvent e) protected override bool OnClick(ClickEvent e)
{ {
handleMouseInput(e); handleMouseInput(e.ScreenSpaceMousePosition);
return true; return true;
} }
protected override bool OnDrag(DragEvent e) protected override bool OnDrag(DragEvent e)
{ {
handleMouseInput(e); handleMouseInput(e.ScreenSpaceMousePosition);
return true; return true;
} }
private void handleMouseInput(InputState state) private void handleMouseInput(Vector2 screenSpaceMousePosition)
{ {
// copied from SliderBar so we can do custom spacing logic. // copied from SliderBar so we can do custom spacing logic.
var xPosition = (ToLocalSpace(state?.Mouse.NativeState.Position ?? Vector2.Zero).X - RangePadding) / UsableWidth; var xPosition = (ToLocalSpace(screenSpaceMousePosition).X - RangePadding) / UsableWidth;
CurrentNumber.Value = availableDivisors.OrderBy(d => Math.Abs(getMappedPosition(d) - xPosition)).First(); CurrentNumber.Value = availableDivisors.OrderBy(d => Math.Abs(getMappedPosition(d) - xPosition)).First();
OnUserChange(); OnUserChange();

View File

@ -64,8 +64,8 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
protected override bool OnDrag(DragEvent e) protected override bool OnDrag(DragEvent e)
{ {
var dragPosition = e.Mouse.NativeState.Position; var dragPosition = e.ScreenSpaceMousePosition;
var dragStartPosition = e.Mouse.NativeState.PositionMouseDown ?? dragPosition; var dragStartPosition = e.ScreenSpaceMouseDownPosition;
var dragQuad = new Quad(dragStartPosition.X, dragStartPosition.Y, dragPosition.X - dragStartPosition.X, dragPosition.Y - dragStartPosition.Y); var dragQuad = new Quad(dragStartPosition.X, dragStartPosition.Y, dragPosition.X - dragStartPosition.X, dragPosition.Y - dragStartPosition.Y);

View File

@ -8,6 +8,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input.States; using osu.Framework.Input.States;
using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Edit;
using OpenTK;
using RectangleF = osu.Framework.Graphics.Primitives.RectangleF; using RectangleF = osu.Framework.Graphics.Primitives.RectangleF;
namespace osu.Game.Screens.Edit.Screens.Compose.Layers namespace osu.Game.Screens.Edit.Screens.Compose.Layers
@ -32,7 +33,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
/// <summary> /// <summary>
/// Invoked when any <see cref="HitObjectMask"/> requests drag. /// Invoked when any <see cref="HitObjectMask"/> requests drag.
/// </summary> /// </summary>
public event Action<HitObjectMask, InputState> MaskDragRequested; public event Action<HitObjectMask, Vector2, InputState> MaskDragRequested;
private IEnumerable<HitObjectMask> aliveMasks => AliveInternalChildren.Cast<HitObjectMask>(); private IEnumerable<HitObjectMask> aliveMasks => AliveInternalChildren.Cast<HitObjectMask>();
@ -103,7 +104,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
} }
private void onSelectionRequested(HitObjectMask mask, InputState state) => MaskSelectionRequested?.Invoke(mask, state); private void onSelectionRequested(HitObjectMask mask, InputState state) => MaskSelectionRequested?.Invoke(mask, state);
private void onDragRequested(HitObjectMask mask, InputState state) => MaskDragRequested?.Invoke(mask, state); private void onDragRequested(HitObjectMask mask, Vector2 delta, InputState state) => MaskDragRequested?.Invoke(mask, delta, state);
protected override int Compare(Drawable x, Drawable y) protected override int Compare(Drawable x, Drawable y)
{ {

View File

@ -54,7 +54,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
#region User Input Handling #region User Input Handling
public void HandleDrag(HitObjectMask m, InputState state) public void HandleDrag(HitObjectMask m, Vector2 delta, InputState state)
{ {
// Todo: Various forms of snapping // Todo: Various forms of snapping
@ -63,7 +63,7 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Layers
switch (mask.HitObject.HitObject) switch (mask.HitObject.HitObject)
{ {
case IHasEditablePosition editablePosition: case IHasEditablePosition editablePosition:
editablePosition.OffsetPosition(state.Mouse.Delta); editablePosition.OffsetPosition(delta);
break; break;
} }
} }

View File

@ -99,11 +99,11 @@ namespace osu.Game.Screens.Edit.Screens.Compose.Timeline
protected override bool OnScroll(ScrollEvent e) protected override bool OnScroll(ScrollEvent e)
{ {
if (e.Mouse.HasPreciseScroll) if (e.IsPrecise)
// for now, we don't support zoom when using a precision scroll device. this needs gesture support. // for now, we don't support zoom when using a precision scroll device. this needs gesture support.
return base.OnScroll(e); return base.OnScroll(e);
setZoomTarget(zoomTarget + e.Mouse.ScrollDelta.Y, zoomedContent.ToLocalSpace(e.Mouse.NativeState.Position).X); setZoomTarget(zoomTarget + e.ScrollDelta.Y, zoomedContent.ToLocalSpace(e.ScreenSpaceMousePosition).X);
return true; return true;
} }

View File

@ -205,7 +205,8 @@ namespace osu.Game.Screens.Menu
protected override bool OnKeyDown(KeyDownEvent e) protected override bool OnKeyDown(KeyDownEvent e)
{ {
if (e.Repeat || state.Keyboard.ControlPressed || state.Keyboard.ShiftPressed || state.Keyboard.AltPressed) var keyboard = e.CurrentState.Keyboard;
if (e.Repeat || keyboard.ControlPressed || keyboard.ShiftPressed || keyboard.AltPressed)
return false; return false;
if (triggerKey == e.Key && triggerKey != Key.Unknown) if (triggerKey == e.Key && triggerKey != Key.Unknown)

View File

@ -201,7 +201,8 @@ namespace osu.Game.Screens.Menu
protected override bool OnKeyDown(KeyDownEvent e) protected override bool OnKeyDown(KeyDownEvent e)
{ {
if (!e.Repeat && state.Keyboard.ControlPressed && state.Keyboard.ShiftPressed && e.Key == Key.D) var keyboard = e.CurrentState.Keyboard;
if (!e.Repeat && keyboard.ControlPressed && keyboard.ShiftPressed && e.Key == Key.D)
{ {
Push(new Drawings()); Push(new Drawings());
return true; return true;

View File

@ -295,7 +295,7 @@ namespace osu.Game.Screens.Play
if (e.Repeat || e.Key != Key.Enter || !Selected) if (e.Repeat || e.Key != Key.Enter || !Selected)
return false; return false;
OnClick(state); Click();
return true; return true;
} }
} }

View File

@ -56,7 +56,7 @@ namespace osu.Game.Screens.Play.HUD
{ {
if (e.Repeat) return false; if (e.Repeat) return false;
if (state.Keyboard.ControlPressed) if (e.CurrentState.Keyboard.ControlPressed)
{ {
if (e.Key == Key.H && ReplayLoaded) if (e.Key == Key.H && ReplayLoaded)
{ {

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System; using System;
using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -62,7 +63,7 @@ namespace osu.Game.Screens.Play.HUD
protected override bool OnMouseMove(MouseMoveEvent e) protected override bool OnMouseMove(MouseMoveEvent e)
{ {
positionalAdjust = Vector2.Distance(e.Mouse.NativeState.Position, button.ScreenSpaceDrawQuad.Centre) / 200; positionalAdjust = Vector2.Distance(e.ScreenSpaceMousePosition, button.ScreenSpaceDrawQuad.Centre) / 200;
return base.OnMouseMove(e); return base.OnMouseMove(e);
} }
@ -182,14 +183,14 @@ namespace osu.Game.Screens.Play.HUD
protected override bool OnMouseDown(MouseDownEvent e) protected override bool OnMouseDown(MouseDownEvent e)
{ {
if (!pendingAnimation && state.Mouse.Buttons.Count() == 1) if (!pendingAnimation && e.CurrentState.Mouse.Buttons.Count() == 1)
BeginConfirm(); BeginConfirm();
return true; return true;
} }
protected override bool OnMouseUp(MouseUpEvent e) protected override bool OnMouseUp(MouseUpEvent e)
{ {
if (!state.Mouse.Buttons.Any()) if (!e.CurrentState.Mouse.Buttons.Any())
AbortConfirm(); AbortConfirm();
return true; return true;
} }

View File

@ -155,7 +155,7 @@ namespace osu.Game.Screens.Play
{ {
if (e.Repeat) return false; if (e.Repeat) return false;
if (state.Keyboard.ShiftPressed) if (e.CurrentState.Keyboard.ShiftPressed)
{ {
switch (e.Key) switch (e.Key)
{ {

View File

@ -130,7 +130,7 @@ namespace osu.Game.Screens.Play
protected override bool OnMouseMove(MouseMoveEvent e) protected override bool OnMouseMove(MouseMoveEvent e)
{ {
if (!e.Mouse.HasAnyButtonPressed) if (!e.CurrentState.Mouse.HasAnyButtonPressed)
fadeContainer.State = Visibility.Visible; fadeContainer.State = Visibility.Visible;
return base.OnMouseMove(e); return base.OnMouseMove(e);
} }

View File

@ -127,7 +127,7 @@ namespace osu.Game.Screens.Select
{ {
if (!e.Repeat && e.Key == Hotkey) if (!e.Repeat && e.Key == Hotkey)
{ {
OnClick(state); Click();
return true; return true;
} }

View File

@ -77,7 +77,7 @@ namespace osu.Game.Screens.Select.Options
{ {
if (!e.Repeat && e.Key == HotKey) if (!e.Repeat && e.Key == HotKey)
{ {
OnClick(state); Click();
return true; return true;
} }

View File

@ -560,7 +560,7 @@ namespace osu.Game.Screens.Select
switch (e.Key) switch (e.Key)
{ {
case Key.Delete: case Key.Delete:
if (state.Keyboard.ShiftPressed) if (e.CurrentState.Keyboard.ShiftPressed)
{ {
if (!Beatmap.IsDefault) if (!Beatmap.IsDefault)
delete(Beatmap.Value.BeatmapSetInfo); delete(Beatmap.Value.BeatmapSetInfo);

View File

@ -58,7 +58,7 @@ namespace osu.Game.Tests.Visual
protected override bool OnScroll(ScrollEvent e) protected override bool OnScroll(ScrollEvent e)
{ {
if (e.Mouse.ScrollDelta.Y > 0) if (e.ScrollDelta.Y > 0)
Clock.SeekBackward(true); Clock.SeekBackward(true);
else else
Clock.SeekForward(true); Clock.SeekForward(true);