32 lines
701 B
C#
32 lines
701 B
C#
using Godot;
|
|
|
|
namespace Newlon.Components.Plants;
|
|
|
|
public partial class DragAction : Node
|
|
{
|
|
[Signal] public delegate void DragBeginEventHandler();
|
|
[Signal] public delegate void DragEndEventHandler();
|
|
private bool dragging = false;
|
|
|
|
public override void _Ready()
|
|
{
|
|
GetParent<Area2D>().InputEvent += OnInputEvent;
|
|
}
|
|
public void OnInputEvent(Node viewport, InputEvent @event, long shape_index)
|
|
{
|
|
if (@event.IsActionPressed("primary_action"))
|
|
{
|
|
dragging = true;
|
|
EmitSignal(SignalName.DragBegin);
|
|
}
|
|
}
|
|
public override void _Input(InputEvent @event)
|
|
{
|
|
if (dragging && @event.IsActionReleased("primary_action"))
|
|
{
|
|
dragging = false;
|
|
EmitSignal(SignalName.DragEnd);
|
|
}
|
|
}
|
|
|
|
}
|