2024-12-01 17:07:41 +00:00
|
|
|
|
|
|
|
using Godot;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Rokojori
|
|
|
|
{
|
2025-01-08 18:46:17 +00:00
|
|
|
[Tool]
|
2024-12-01 17:07:41 +00:00
|
|
|
[GlobalClass,Icon("res://addons/rokojori_action_library/Icons/RJSensor.svg")]
|
2025-01-08 18:46:17 +00:00
|
|
|
public partial class MouseMotionDelta : Sensor, iOnInputSensor
|
2024-12-01 17:07:41 +00:00
|
|
|
{
|
|
|
|
public enum MouseMotionType
|
|
|
|
{
|
|
|
|
Right,
|
|
|
|
Left,
|
|
|
|
Up,
|
|
|
|
Down
|
|
|
|
}
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public MouseMotionType motionType;
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
public float speedMultiply = 1;
|
|
|
|
|
|
|
|
float _lastInput = 0;
|
|
|
|
|
2025-01-08 18:46:17 +00:00
|
|
|
protected override void UpdateValue()
|
2024-12-01 17:07:41 +00:00
|
|
|
{
|
2025-01-08 18:46:17 +00:00
|
|
|
SetFloatValue( _lastInput );
|
2024-12-01 17:07:41 +00:00
|
|
|
_lastInput = 0;
|
|
|
|
}
|
|
|
|
|
2025-01-08 18:46:17 +00:00
|
|
|
public void _Input( InputEvent ev )
|
2024-12-01 17:07:41 +00:00
|
|
|
{
|
|
|
|
var mouseEvent = ev as InputEventMouseMotion ;
|
|
|
|
|
|
|
|
if ( mouseEvent == null )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var delta = mouseEvent.ScreenRelative;
|
|
|
|
var motion = 0f;
|
|
|
|
|
|
|
|
if ( MouseMotionType.Left == motionType)
|
|
|
|
{
|
|
|
|
motion = Mathf.Max( 0, -delta.X );
|
|
|
|
}
|
|
|
|
else if ( MouseMotionType.Right == motionType)
|
|
|
|
{
|
|
|
|
motion = Mathf.Max( 0, delta.X );
|
|
|
|
}
|
|
|
|
else if ( MouseMotionType.Up == motionType)
|
|
|
|
{
|
|
|
|
motion = Mathf.Max( 0, delta.Y );
|
|
|
|
}
|
|
|
|
if ( MouseMotionType.Down == motionType)
|
|
|
|
{
|
|
|
|
motion = Mathf.Max( 0, -delta.Y );
|
|
|
|
}
|
|
|
|
|
|
|
|
// RJLog.Log( "Motion:", motionType, motion * speedMultiply );
|
|
|
|
|
|
|
|
_lastInput = motion * speedMultiply;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|