drag and drop UI
This commit is contained in:
@@ -1,15 +1,65 @@
|
||||
using Godot;
|
||||
|
||||
public sealed partial class MeetingControlDragData : GodotObject { }
|
||||
|
||||
public partial class MeetingControl : PanelContainer
|
||||
public sealed partial class MeetingControlDragData(MeetingControl meetingControl) : GodotObject
|
||||
{
|
||||
public MeetingControl MeetingControl { get; set; } = meetingControl;
|
||||
}
|
||||
|
||||
[SceneTree]
|
||||
public partial class MeetingControl : Control
|
||||
{
|
||||
[Export]
|
||||
public Meeting Meeting;
|
||||
|
||||
public bool InSlot { get; set; }
|
||||
|
||||
public override Variant _GetDragData(Vector2 atPosition)
|
||||
{
|
||||
GD.Print("CONTROL DRAG");
|
||||
var copy = Duplicate() as MeetingControl;
|
||||
SetDragPreview(copy);
|
||||
var preview = CreatePreview();
|
||||
SetDragPreview(preview);
|
||||
GD.Print("asdasdasdasd as dasd");
|
||||
Visible = false;
|
||||
|
||||
return Variant.From(new MeetingControlDragData());
|
||||
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)
|
||||
{
|
||||
GD.Print("Drag End");
|
||||
|
||||
if (InSlot)
|
||||
{
|
||||
GD.Print("Dropped in Slot");
|
||||
return;
|
||||
}
|
||||
|
||||
GD.Print("Dropped somewhere");
|
||||
|
||||
FindParent("Main").AddChild(Meeting);
|
||||
Meeting.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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user