Przeglądaj źródła

create dialog search preferrence fixes: #11697

toger5 8 lat temu
rodzic
commit
3f423342f4
3 zmienionych plików z 34 dodań i 7 usunięć
  1. 18 6
      editor/create_dialog.cpp
  2. 4 1
      editor/create_dialog.h
  3. 12 0
      editor/scene_tree_dock.cpp

+ 18 - 6
editor/create_dialog.cpp

@@ -168,8 +168,11 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p
 		item->set_custom_color(0, get_color("disabled_font_color", "Editor"));
 		item->set_custom_color(0, get_color("disabled_font_color", "Editor"));
 		item->set_selectable(0, false);
 		item->set_selectable(0, false);
 	} else {
 	} else {
+		bool is_search_subsequence = search_box->get_text().is_subsequence_ofi(p_type);
+		String to_select_type = *to_select ? (*to_select)->get_text(0) : "";
+		bool current_item_is_preffered = ClassDB::is_parent_class(p_type, preferred_search_result_type) && !ClassDB::is_parent_class(to_select_type, preferred_search_result_type);
 
 
-		if ((!*to_select && (search_box->get_text().is_subsequence_ofi(p_type))) || search_box->get_text() == p_type) {
+		if (((!*to_select || current_item_is_preffered) && is_search_subsequence) || search_box->get_text() == p_type) {
 			*to_select = item;
 			*to_select = item;
 		}
 		}
 	}
 	}
@@ -361,6 +364,19 @@ void CreateDialog::set_base_type(const String &p_base) {
 	_update_search();
 	_update_search();
 }
 }
 
 
+String CreateDialog::get_base_type() const {
+
+	return base_type;
+}
+
+void CreateDialog::set_preferred_search_result_type(const String &p_preferred_type) {
+	preferred_search_result_type = p_preferred_type;
+}
+
+String CreateDialog::get_preferred_search_result_type() {
+
+	return preferred_search_result_type;
+}
 String CreateDialog::get_selected_type() {
 String CreateDialog::get_selected_type() {
 
 
 	TreeItem *selected = search_options->get_selected();
 	TreeItem *selected = search_options->get_selected();
@@ -411,11 +427,6 @@ Object *CreateDialog::instance_selected() {
 	return NULL;
 	return NULL;
 }
 }
 
 
-String CreateDialog::get_base_type() const {
-
-	return base_type;
-}
-
 void CreateDialog::_item_selected() {
 void CreateDialog::_item_selected() {
 
 
 	TreeItem *item = search_options->get_selected();
 	TreeItem *item = search_options->get_selected();
@@ -654,6 +665,7 @@ CreateDialog::CreateDialog() {
 	search_options->connect("cell_selected", this, "_item_selected");
 	search_options->connect("cell_selected", this, "_item_selected");
 	//search_options->set_hide_root(true);
 	//search_options->set_hide_root(true);
 	base_type = "Object";
 	base_type = "Object";
+	preferred_search_result_type = "";
 
 
 	help_bit = memnew(EditorHelpBit);
 	help_bit = memnew(EditorHelpBit);
 	vbc->add_margin_child(TTR("Description:"), help_bit);
 	vbc->add_margin_child(TTR("Description:"), help_bit);

+ 4 - 1
editor/create_dialog.h

@@ -53,7 +53,7 @@ class CreateDialog : public ConfirmationDialog {
 	LineEdit *search_box;
 	LineEdit *search_box;
 	Tree *search_options;
 	Tree *search_options;
 	String base_type;
 	String base_type;
-
+	String preferred_search_result_type;
 	EditorHelpBit *help_bit;
 	EditorHelpBit *help_bit;
 
 
 	void _item_selected();
 	void _item_selected();
@@ -93,6 +93,9 @@ public:
 	void set_base_type(const String &p_base);
 	void set_base_type(const String &p_base);
 	String get_base_type() const;
 	String get_base_type() const;
 
 
+	void set_preferred_search_result_type(const String &p_preferred_type);
+	String get_preferred_search_result_type();
+
 	void popup_create(bool p_dontclear);
 	void popup_create(bool p_dontclear);
 
 
 	CreateDialog();
 	CreateDialog();

+ 12 - 0
editor/scene_tree_dock.cpp

@@ -270,6 +270,18 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
 	switch (p_tool) {
 	switch (p_tool) {
 
 
 		case TOOL_NEW: {
 		case TOOL_NEW: {
+
+			String preferred = "";
+			Node *current_edited_scene_root = EditorNode::get_singleton()->get_edited_scene();
+
+			if (current_edited_scene_root) {
+
+				if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Node2D"))
+					preferred = "Node2D";
+				else if (ClassDB::is_parent_class(current_edited_scene_root->get_class_name(), "Spatial"))
+					preferred = "Spatial";
+			}
+			create_dialog->set_preferred_search_result_type(preferred);
 			create_dialog->popup_create(true);
 			create_dialog->popup_create(true);
 		} break;
 		} break;
 		case TOOL_INSTANCE: {
 		case TOOL_INSTANCE: {