using Godot; using Newlon.Resources; [Tool] public partial class DnDSeedpacket : TextureButton { [Signal] public delegate void SaveCallbackEventHandler(); [Export] private TextureRect preview; public PlantResource HeldResource; public override bool _CanDropData(Vector2 atPosition, Variant data) { if (data.VariantType == Variant.Type.Dictionary) { if ((string)data.AsGodotDictionary()["type"] == "files") { return ResourceLoader.Load(data.AsGodotDictionary()["files"].AsGodotArray()[0]) is PlantResource; } } return false; } public override void _DropData(Vector2 atPosition, Variant data) { HeldResource = ResourceLoader.Load(data.AsGodotDictionary()["files"].AsGodotArray()[0]) as PlantResource; Update(); } public override void _Pressed() { HeldResource = null; Update(); } private void Update() { RefreshTexture(); EmitSignal(SignalName.SaveCallback); } public void RefreshTexture() { if (HeldResource != null) { preview.Texture = HeldResource.Preview; } else { preview.Texture = null; } } }