/**************************************************************************/ /* create_dialog.cpp */ /**************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /**************************************************************************/ /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ /* "Software"), to deal in the Software without restriction, including */ /* without limitation the rights to use, copy, modify, merge, publish, */ /* distribute, sublicense, and/or sell copies of the Software, and to */ /* permit persons to whom the Software is furnished to do so, subject to */ /* the following conditions: */ /* */ /* The above copyright notice and this permission notice shall be */ /* included in all copies or substantial portions of the Software. */ /* */ /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ #include "create_dialog.h" #include "core/object/class_db.h" #include "editor/editor_feature_profile.h" #include "editor/editor_node.h" #include "editor/editor_paths.h" #include "editor/editor_settings.h" #include "editor/editor_string_names.h" #include "editor/themes/editor_scale.h" void CreateDialog::popup_create(bool p_dont_clear, bool p_replace_mode, const String &p_current_type, const String &p_current_name) { _fill_type_list(); icon_fallback = search_options->has_theme_icon(base_type, EditorStringName(EditorIcons)) ? base_type : "Object"; if (p_dont_clear) { search_box->select_all(); } else { search_box->clear(); } if (p_replace_mode) { search_box->set_text(p_current_type); } search_box->grab_focus(); _update_search(); if (p_replace_mode) { set_title(vformat(TTR("Change Type of \"%s\""), p_current_name)); set_ok_button_text(TTR("Change")); } else { set_title(vformat(TTR("Create New %s"), base_type)); set_ok_button_text(TTR("Create")); } _load_favorites_and_history(); _save_and_update_favorite_list(); // Restore valid window bounds or pop up at default size. Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "create_new_node", Rect2()); if (saved_size != Rect2()) { popup(saved_size); } else { popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8); } } void CreateDialog::_fill_type_list() { List complete_type_list; ClassDB::get_class_list(&complete_type_list); ScriptServer::get_global_class_list(&complete_type_list); EditorData &ed = EditorNode::get_editor_data(); for (List::Element *I = complete_type_list.front(); I; I = I->next()) { StringName type = I->get(); if (!_should_hide_type(type)) { type_list.push_back(type); if (!ed.get_custom_types().has(type)) { continue; } const Vector &ct = ed.get_custom_types()[type]; for (int i = 0; i < ct.size(); i++) { custom_type_parents[ct[i].name] = type; custom_type_indices[ct[i].name] = i; type_list.push_back(ct[i].name); } } } type_list.sort_custom(); } bool CreateDialog::_is_type_preferred(const String &p_type) const { if (ClassDB::class_exists(p_type)) { return ClassDB::is_parent_class(p_type, preferred_search_result_type); } return EditorNode::get_editor_data().script_class_is_parent(p_type, preferred_search_result_type); } void CreateDialog::_script_button_clicked(TreeItem *p_item, int p_column, int p_button_id, MouseButton p_mouse_button_index) { if (p_mouse_button_index != MouseButton::LEFT) { return; } // The id of opening-script button is 1. if (p_button_id != 1) { return; } String scr_path = ScriptServer::get_global_class_path(p_item->get_text(0)); Ref