From 36c1b019facba3c4928d7966670ff5ae5aba5a4f Mon Sep 17 00:00:00 2001 From: Thomas ten Cate Date: Fri, 7 Feb 2025 10:33:30 +0100 Subject: [PATCH] Highlight Node and NodePath properties as valid drop targets This was already done for Resource properties; this just makes things consistent. --- editor/editor_properties.cpp | 22 ++++++++++++++++++++++ editor/editor_properties.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 398f1383622..1aedb6ac361 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -2732,6 +2732,13 @@ void EditorPropertyNodePath::_node_assign() { scene_tree->popup_scenetree_dialog(n, get_base_node()); } +void EditorPropertyNodePath::_assign_draw() { + if (dropping) { + Color color = get_theme_color(SNAME("accent_color"), EditorStringName(Editor)); + assign->draw_rect(Rect2(Point2(), assign->get_size()), color, false); + } +} + void EditorPropertyNodePath::_update_menu() { const NodePath &np = _get_node_path(); @@ -2909,6 +2916,20 @@ void EditorPropertyNodePath::_notification(int p_what) { menu->get_popup()->set_item_icon(ACTION_EDIT, get_editor_theme_icon(SNAME("Edit"))); menu->get_popup()->set_item_icon(ACTION_SELECT, get_editor_theme_icon(SNAME("ExternalLink"))); } break; + + case NOTIFICATION_DRAG_BEGIN: { + if (!is_read_only() && is_drop_valid(get_viewport()->gui_get_drag_data())) { + dropping = true; + assign->queue_redraw(); + } + } break; + + case NOTIFICATION_DRAG_END: { + if (dropping) { + dropping = false; + assign->queue_redraw(); + } + } break; } } @@ -2949,6 +2970,7 @@ EditorPropertyNodePath::EditorPropertyNodePath() { assign->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); assign->set_expand_icon(true); assign->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyNodePath::_node_assign)); + assign->connect(SceneStringName(draw), callable_mp(this, &EditorPropertyNodePath::_assign_draw)); SET_DRAG_FORWARDING_CD(assign, EditorPropertyNodePath); hbc->add_child(assign); diff --git a/editor/editor_properties.h b/editor/editor_properties.h index 81415b7e100..6435825c676 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -628,10 +628,12 @@ class EditorPropertyNodePath : public EditorProperty { SceneTreeDialog *scene_tree = nullptr; bool use_path_from_scene_root = false; bool editing_node = false; + bool dropping = false; Vector valid_types; void _node_selected(const NodePath &p_path, bool p_absolute = true); void _node_assign(); + void _assign_draw(); Node *get_base_node(); void _update_menu(); void _menu_option(int p_idx);