Bladeren bron

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.
Thomas ten Cate 6 maanden geleden
bovenliggende
commit
93d342b745
2 gewijzigde bestanden met toevoegingen van 16 en 0 verwijderingen
  1. 15 0
      editor/editor_properties_array_dict.cpp
  2. 1 0
      editor/editor_properties_array_dict.h

+ 15 - 0
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;
 	}

+ 1 - 0
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);