Files
You-Are-A-CEO/MeetingControl.cs
2026-07-27 22:36:11 +02:00

66 lines
1.5 KiB
C#

using Godot;
public sealed partial class MeetingControlDragData(MeetingControl meetingControl) : GodotObject
{
public MeetingControl MeetingControl { get; set; } = meetingControl;
}
[SceneTree]
public partial class MeetingControl : Control
{
[Export]
public MeetingPhysicsBox MeetingPhysicsBox;
public bool InSlot { get; set; }
public override void _Ready()
{
// TODO: make this more pretty
MeetingControlGfx.MeetingResource = MeetingPhysicsBox.MeetingResource;
}
public override Variant _GetDragData(Vector2 atPosition)
{
var preview = CreatePreview();
SetDragPreview(preview);
Visible = false;
InSlot = false;
return Variant.From(new MeetingControlDragData(this));
}
public void StartDrag()
{
var preview = CreatePreview();
var data = Variant.From(new MeetingControlDragData(this));
ForceDrag(data, preview);
}
public override void _Notification(int what)
{
if (what == NotificationDragEnd)
{
if (InSlot)
{
return;
}
FindParent("Main").AddChild(MeetingPhysicsBox);
MeetingPhysicsBox.Position = GetGlobalMousePosition();
QueueFree();
}
}
private Control CreatePreview()
{
var copy = Duplicate() as MeetingControl;
var preview = new Control();
preview.AddChild(copy);
copy.Position = new Vector2(-Size.X / 2, -Size.Y / 2);
return preview;
}
}