48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using Godot;
|
|
using Newlon.Resources;
|
|
|
|
|
|
[Tool]
|
|
public partial class ZE_GridItem : Control
|
|
{
|
|
private ZombieResource resource;
|
|
public int index;
|
|
[Signal] public delegate void ResourceChangedEventHandler(ZombieResource resource, int index);
|
|
public void SetData(ZombieResource data)
|
|
{
|
|
resource = data;
|
|
UpdateContent();
|
|
}
|
|
private void UpdateContent()
|
|
{
|
|
if (resource == null)
|
|
{
|
|
GetNode<TextureRect>("Texture").Texture = null;
|
|
return;
|
|
}
|
|
GetNode<TextureRect>("Texture").Texture = resource.Preview;
|
|
}
|
|
|
|
public override Variant _GetDragData(Vector2 atPosition)
|
|
{
|
|
return resource;
|
|
}
|
|
public override bool _CanDropData(Vector2 atPosition, Variant data)
|
|
{
|
|
return data.AsGodotObject() is ZombieResource;
|
|
}
|
|
public override void _DropData(Vector2 atPosition, Variant data)
|
|
{
|
|
SetData((ZombieResource)data.AsGodotObject());
|
|
EmitSignal(SignalName.ResourceChanged, resource, index);
|
|
}
|
|
public override void _GuiInput(InputEvent @event)
|
|
{
|
|
if (@event is InputEventMouseButton buttonEvent && buttonEvent.ButtonIndex == MouseButton.Right )
|
|
{
|
|
SetData(null);
|
|
EmitSignal(SignalName.ResourceChanged, resource, index);
|
|
}
|
|
}
|
|
|
|
}
|