From 93d342b7450d2ec45ef2baa064499291d8f85929 Mon Sep 17 00:00:00 2001 From: Thomas ten Cate Date: Fri, 7 Feb 2025 15:17:06 +0100 Subject: [PATCH] Allow dragging items onto array property editor Add Element button Instead of having to first click the button, then drag the item into the new slot, this allows just dragging the item onto the button directly. The button is highlighted as a valid drop target to signal this. --- editor/editor_properties_array_dict.cpp | 15 +++++++++++++++ editor/editor_properties_array_dict.h | 1 + 2 files changed, 16 insertions(+) diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index 4f97b6b1fe..0c68f6c924 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -460,6 +460,8 @@ void EditorPropertyArray::update_property() { button_add_item = EditorInspector::create_inspector_action_button(TTR("Add Element")); button_add_item->set_button_icon(get_editor_theme_icon(SNAME("Add"))); button_add_item->connect(SceneStringName(pressed), callable_mp(this, &EditorPropertyArray::_add_element)); + button_add_item->connect(SceneStringName(draw), callable_mp(this, &EditorPropertyArray::_button_add_item_draw)); + SET_DRAG_FORWARDING_CD(button_add_item, EditorPropertyArray); button_add_item->set_disabled(is_read_only()); vbox->add_child(button_add_item); @@ -551,6 +553,13 @@ void EditorPropertyArray::_button_draw() { } } +void EditorPropertyArray::_button_add_item_draw() { + if (dropping) { + Color color = get_theme_color(SNAME("accent_color"), EditorStringName(Editor)); + button_add_item->draw_rect(Rect2(Point2(), button_add_item->get_size()), color, false); + } +} + bool EditorPropertyArray::_is_drop_valid(const Dictionary &p_drag_data) const { if (is_read_only()) { return false; @@ -766,6 +775,9 @@ void EditorPropertyArray::_notification(int p_what) { if (_is_drop_valid(get_viewport()->gui_get_drag_data())) { dropping = true; edit->queue_redraw(); + if (button_add_item) { + button_add_item->queue_redraw(); + } } } } break; @@ -774,6 +786,9 @@ void EditorPropertyArray::_notification(int p_what) { if (dropping) { dropping = false; edit->queue_redraw(); + if (button_add_item) { + button_add_item->queue_redraw(); + } } } break; } diff --git a/editor/editor_properties_array_dict.h b/editor/editor_properties_array_dict.h index a7ec912e1a..f5fcc59025 100644 --- a/editor/editor_properties_array_dict.h +++ b/editor/editor_properties_array_dict.h @@ -163,6 +163,7 @@ protected: virtual void _remove_pressed(int p_index); virtual void _button_draw(); + virtual void _button_add_item_draw(); virtual bool _is_drop_valid(const Dictionary &p_drag_data) const; virtual bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; virtual void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from);