Drag and drop modification

Godot Version

Godot v4.3

Question

I want to make an inventory system in my game. Is there a way to somehow change drag and drop functions to move items not by holding a mouse button, but by just clicking it once and move it to another slot? Or do i need to code my own functions to do that?

In theory using Control.force_drag() should work but the drag and drop behavior is sadly hardcoded here godot/scene/main/viewport.cpp at f63272561197b1f9c4a5045afa7acff675a88995 · godotengine/godot · GitHub to use the mouse left click so it won’t work because:

I’m using this code:

extends ColorRect


func _get_drag_data(at_position: Vector2) -> Variant:
	var cr = ColorRect.new()
	cr.color = color
	cr.custom_minimum_size = Vector2(100, 100)
	set_drag_preview(cr)
	return {"color": color, "src": self}

func _can_drop_data(at_position: Vector2, data: Variant) -> bool:
	printt(name, data is Dictionary and not data.get("src", null) == self)
	return data is Dictionary and not data.get("src", null) == self


func _drop_data(at_position: Vector2, data: Variant) -> void:
	color = data.get("color", Color.BLACK)


func _gui_input(event: InputEvent) -> void:
	if event is InputEventMouseButton:
		if event.pressed:
			get_viewport().gui_release_focus()
			var cr = ColorRect.new()
			cr.color = color
			cr.custom_minimum_size = Vector2(100, 100)
			force_drag({"color": color, "src": self}, cr)
			event.button_index = MOUSE_BUTTON_NONE


func _notification(what: int) -> void:
	match what:
		NOTIFICATION_DRAG_BEGIN:
			printt("drag begin", get_viewport().gui_get_drag_data())
		NOTIFICATION_DRAG_END:
			printt("drag end", get_viewport().gui_is_drag_successful())

You should open an issue if there isn’t one already.