drag_drop_script.gd 990 B

1234567891011121314151617181920212223242526272829303132
  1. extends ColorPickerButton
  2. # Returns the data to pass from an object when you click and drag away from
  3. # this object. Also calls set_drag_preview() to show the mouse dragging
  4. # something so the user knows that the operation is working.
  5. func _get_drag_data(_pos):
  6. # Use another colorpicker as drag preview.
  7. var cpb = ColorPickerButton.new()
  8. cpb.color = color
  9. cpb.size = Vector2(80.0, 50.0)
  10. # Allows us to center the color picker on the mouse
  11. var preview = Control.new()
  12. preview.add_child(cpb)
  13. cpb.position = -0.5 * cpb.size
  14. # Sets what the user will see they are dragging
  15. set_drag_preview(preview)
  16. # Return color as drag data.
  17. return color
  18. # Returns a boolean by examining the data being dragged to see if it's valid
  19. # to drop here.
  20. func _can_drop_data(_pos, data):
  21. return typeof(data) == TYPE_COLOR
  22. # Takes the data being dragged and processes it. In this case, we are
  23. # assigning a new color to the target color picker button.
  24. func _drop_data(_pos, data):
  25. color = data