77 lines
1.8 KiB
C#
77 lines
1.8 KiB
C#
using System;
|
|
using Godot;
|
|
|
|
public partial class Meeting : RigidBody2D
|
|
{
|
|
private bool _mouseInside;
|
|
private bool _isDragging;
|
|
private Vector2 _dragTarget;
|
|
|
|
public override void _Ready()
|
|
{
|
|
FreezeMode = FreezeModeEnum.Kinematic;
|
|
|
|
MouseEntered += () =>
|
|
{
|
|
_mouseInside = true;
|
|
CanSleep = false;
|
|
};
|
|
MouseExited += () =>
|
|
{
|
|
_mouseInside = false;
|
|
CanSleep = true;
|
|
};
|
|
}
|
|
|
|
public override void _UnhandledInput(InputEvent @event)
|
|
{
|
|
// TODO: probably memory problem
|
|
if (@event is InputEventMouse mouseEvent)
|
|
{
|
|
if (_mouseInside)
|
|
{
|
|
if (mouseEvent.IsPressed() && mouseEvent.ButtonMask == MouseButtonMask.Left)
|
|
{
|
|
GD.Print("Start Dragging");
|
|
StartDragging();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void _PhysicsProcess(double delta)
|
|
{
|
|
_dragTarget = GetGlobalMousePosition();
|
|
}
|
|
|
|
public override void _IntegrateForces(PhysicsDirectBodyState2D state)
|
|
{
|
|
if (!_isDragging)
|
|
return;
|
|
|
|
var t = state.Transform;
|
|
t.Origin = _dragTarget;
|
|
|
|
state.Transform = t;
|
|
state.LinearVelocity = Vector2.Zero;
|
|
state.AngularVelocity = 0;
|
|
}
|
|
|
|
private void StartDragging()
|
|
{
|
|
LinearVelocity = Vector2.Zero;
|
|
AngularVelocity = 0;
|
|
RotationDegrees = 0;
|
|
|
|
var meetingControl = Instantiator.Instantiate<MeetingControl>();
|
|
meetingControl.Meeting = this;
|
|
|
|
GetParent().AddChild(meetingControl);
|
|
meetingControl.StartDrag();
|
|
|
|
meetingControl.Position = new Vector2(-5000, -5000);
|
|
|
|
GetParent().RemoveChild(this);
|
|
}
|
|
}
|