37 lines
904 B
C#
37 lines
904 B
C#
using Godot;
|
|
using Godot.Collections;
|
|
|
|
[Tool]
|
|
public partial class DnDCard : PanelContainer
|
|
{
|
|
private Variant tempData;
|
|
private PackedScene packedScene;
|
|
private Node instantiated;
|
|
|
|
[Signal] public delegate void DnDDroppedEventHandler(PackedScene scene);
|
|
|
|
public override void _Notification(int what)
|
|
{
|
|
if (what == NotificationDragBegin)
|
|
{
|
|
tempData = GetViewport().GuiGetDragData();
|
|
}
|
|
else if (what == NotificationDragEnd && GetGlobalRect().HasPoint(GetGlobalMousePosition()))
|
|
{
|
|
var loaded = ResourceLoader.Load(tempData.AsGodotDictionary()["files"].AsStringArray()[0]);
|
|
if (loaded is PackedScene scene)
|
|
{
|
|
packedScene = scene;
|
|
EmitSignal(SignalName.DnDDropped, packedScene);
|
|
}
|
|
}
|
|
}
|
|
private void Refresh()
|
|
{
|
|
if (instantiated != null) instantiated.QueueFree();
|
|
instantiated = packedScene.Instantiate();
|
|
GetNode("SubViewport").AddChild(instantiated);
|
|
}
|
|
|
|
|
|
}
|