diff options
Diffstat (limited to 'editor/project_manager.cpp')
-rw-r--r-- | editor/project_manager.cpp | 136 |
1 files changed, 35 insertions, 101 deletions
diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index 0be1f6d85b..134f238bb6 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -102,7 +102,6 @@ private: FileDialog *fdialog; FileDialog *fdialog_install; OptionButton *vcs_metadata_selection; - CheckBox *create_default_environment; String zip_path; String zip_title; AcceptDialog *dialog_error; @@ -162,7 +161,7 @@ private: } } - if (valid_path == "") { + if (valid_path.is_empty()) { set_message(TTR("The path specified doesn't exist."), MESSAGE_ERROR); memdelete(d); get_ok_button()->set_disabled(true); @@ -176,7 +175,7 @@ private: valid_install_path = install_path->get_text().strip_edges(); } - if (valid_install_path == "") { + if (valid_install_path.is_empty()) { set_message(TTR("The path specified doesn't exist."), MESSAGE_ERROR, INSTALL_PATH); memdelete(d); get_ok_button()->set_disabled(true); @@ -185,7 +184,7 @@ private: } if (mode == MODE_IMPORT || mode == MODE_RENAME) { - if (valid_path != "" && !d->file_exists("project.godot")) { + if (!valid_path.is_empty() && !d->file_exists("project.godot")) { if (valid_path.ends_with(".zip")) { FileAccess *src_f = nullptr; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); @@ -226,7 +225,7 @@ private: d->list_dir_begin(); is_folder_empty = true; String n = d->get_next(); - while (n != String()) { + while (!n.is_empty()) { if (!n.begins_with(".")) { // Allow `.`, `..` (reserved current/parent folder names) // and hidden files/folders to be present. @@ -266,7 +265,7 @@ private: d->list_dir_begin(); is_folder_empty = true; String n = d->get_next(); - while (n != String()) { + while (!n.is_empty()) { if (!n.begins_with(".")) { // Allow `.`, `..` (reserved current/parent folder names) // and hidden files/folders to be present. @@ -296,16 +295,16 @@ private: void _path_text_changed(const String &p_path) { String sp = _test_path(); - if (sp != "") { + if (!sp.is_empty()) { // If the project name is empty or default, infer the project name from the selected folder name - if (project_name->get_text().strip_edges() == "" || project_name->get_text().strip_edges() == TTR("New Game Project")) { + if (project_name->get_text().strip_edges().is_empty() || project_name->get_text().strip_edges() == TTR("New Game Project")) { sp = sp.replace("\\", "/"); int lidx = sp.rfind("/"); if (lidx != -1) { sp = sp.substr(lidx + 1, sp.length()).capitalize(); } - if (sp == "" && mode == MODE_IMPORT) { + if (sp.is_empty() && mode == MODE_IMPORT) { sp = TTR("Imported Project"); } @@ -314,7 +313,7 @@ private: } } - if (created_folder_path != "" && created_folder_path != p_path) { + if (!created_folder_path.is_empty() && created_folder_path != p_path) { _remove_created_folder(); } } @@ -383,7 +382,7 @@ private: void _create_folder() { const String project_name_no_edges = project_name->get_text().strip_edges(); - if (project_name_no_edges == "" || created_folder_path != "" || project_name_no_edges.ends_with(".")) { + if (project_name_no_edges.is_empty() || !created_folder_path.is_empty() || project_name_no_edges.ends_with(".")) { set_message(TTR("Invalid project name."), MESSAGE_WARNING); return; } @@ -418,7 +417,7 @@ private: _test_path(); - if (p_text.strip_edges() == "") { + if (p_text.strip_edges().is_empty()) { set_message(TTR("It would be a good idea to name your project."), MESSAGE_ERROR); } } @@ -433,7 +432,7 @@ private: if (mode == MODE_RENAME) { String dir2 = _test_path(); - if (dir2 == "") { + if (dir2.is_empty()) { set_message(TTR("Invalid project path (changed anything?)."), MESSAGE_ERROR); return; } @@ -495,31 +494,10 @@ private: initial_settings["application/config/name"] = project_name->get_text().strip_edges(); initial_settings["application/config/icon"] = "res://icon.png"; - if (create_default_environment->is_pressed()) { - initial_settings["rendering/environment/defaults/default_environment"] = "res://default_env.tres"; - } - if (ProjectSettings::get_singleton()->save_custom(dir.plus_file("project.godot"), initial_settings, Vector<String>(), false) != OK) { set_message(TTR("Couldn't create project.godot in project path."), MESSAGE_ERROR); } else { ResourceSaver::save(dir.plus_file("icon.png"), create_unscaled_default_project_icon()); - FileAccess *f; - if (create_default_environment->is_pressed()) { - f = FileAccess::open(dir.plus_file("default_env.tres"), FileAccess::WRITE); - if (!f) { - set_message(TTR("Couldn't create default_env.tres in project path."), MESSAGE_ERROR); - } else { - f->store_line("[gd_resource type=\"Environment\" load_steps=2 format=2]"); - f->store_line(""); - f->store_line("[sub_resource type=\"Sky\" id=\"1\"]"); - f->store_line(""); - f->store_line("[resource]"); - f->store_line("background_mode = 2"); - f->store_line("sky = SubResource( \"1\" )"); - memdelete(f); - } - } - EditorVCSInterface::create_vcs_metadata_files(EditorVCSInterface::VCSMetadata(vcs_metadata_selection->get_selected()), dir); } } else if (mode == MODE_INSTALL) { @@ -568,7 +546,7 @@ private: String path = fname; - if (path == String() || path == zip_root || !zip_root.is_subsequence_of(path)) { + if (path.is_empty() || path == zip_root || !zip_root.is_subsequence_of(path)) { // } else if (path.ends_with("/")) { // a dir @@ -639,7 +617,7 @@ private: } void _remove_created_folder() { - if (created_folder_path != "") { + if (!created_folder_path.is_empty()) { DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); d->remove(created_folder_path); memdelete(d); @@ -739,7 +717,7 @@ public: } else { fav_dir = EditorSettings::get_singleton()->get("filesystem/directories/default_project_path"); - if (fav_dir != "") { + if (!fav_dir.is_empty()) { project_path->set_text(fav_dir); fdialog->set_current_dir(fav_dir); } else { @@ -872,7 +850,7 @@ public: iphb->add_child(install_browse); msg = memnew(Label); - msg->set_align(Label::ALIGN_CENTER); + msg->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); vb->add_child(msg); // rasterizer selection @@ -926,8 +904,8 @@ public: l->set_text(TTR("The renderer can be changed later, but scenes may need to be adjusted.")); // Add some extra spacing to separate it from the list above and the buttons below. l->set_custom_minimum_size(Size2(0, 40) * EDSCALE); - l->set_align(Label::ALIGN_CENTER); - l->set_valign(Label::VALIGN_CENTER); + l->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); + l->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER); l->set_modulate(Color(1, 1, 1, 0.7)); rasterizer_container->add_child(l); @@ -945,10 +923,6 @@ public: Control *spacer = memnew(Control); spacer->set_h_size_flags(Control::SIZE_EXPAND_FILL); default_files_container->add_child(spacer); - create_default_environment = memnew(CheckBox); - create_default_environment->set_text("Create Default Environment"); - create_default_environment->set_pressed(true); - default_files_container->add_child(create_default_environment); fdialog = memnew(FileDialog); fdialog->set_access(FileDialog::ACCESS_FILESYSTEM); @@ -1184,7 +1158,7 @@ void ProjectList::load_project_icon(int p_index) { Ref<Texture2D> default_icon = get_theme_icon(SNAME("DefaultProjectIcon"), SNAME("EditorIcons")); Ref<Texture2D> icon; - if (item.icon != "") { + if (!item.icon.is_empty()) { Ref<Image> img; img.instantiate(); Error err = img->load(item.icon.replace_first("res://", item.path + "/")); @@ -1217,7 +1191,7 @@ ProjectList::Item ProjectList::load_project_data(const String &p_property_key, b String project_name = TTR("Unnamed Project"); if (cf_err == OK) { String cf_project_name = static_cast<String>(cf->get_value("application", "config/name", "")); - if (cf_project_name != "") { + if (!cf_project_name.is_empty()) { project_name = cf_project_name.xml_unescape(); } config_version = (int)cf->get_value("", "config_version", 0); @@ -1233,46 +1207,6 @@ ProjectList::Item ProjectList::load_project_data(const String &p_property_key, b const String main_scene = cf->get_value("application", "run/main_scene", ""); PackedStringArray project_features = cf->get_value("application", "config/features", PackedStringArray()); - bool project_features_dirty = false; - // If there is no feature list currently present, force one to generate. - if (project_features.is_empty()) { - project_features = ProjectSettings::get_required_features(); - project_features_dirty = true; - } - // Check the rendering API. - const String rendering_api = cf->get_value("rendering", "quality/driver/driver_name", ""); - if (rendering_api != "") { - // Add the rendering API as a project feature if it doesn't already exist. - if (!project_features.has(rendering_api)) { - project_features.append(rendering_api); - project_features_dirty = true; - } - } - // Check for the existence of a csproj file. - if (FileAccess::exists(path.plus_file(project_name + ".csproj"))) { - // If there is a csproj file, add the C# feature if it doesn't already exist. - if (!project_features.has("C#")) { - project_features.append("C#"); - project_features_dirty = true; - } - } else { - // If there isn't a csproj file, remove the C# feature if it exists. - if (project_features.has("C#")) { - project_features.remove_at(project_features.find("C#")); - project_features_dirty = true; - } - } - if (project_features_dirty) { - project_features.sort(); - // Write the updated feature list, but only if the project config version is the same. - // Never write to project files with a different config version! - if (config_version == ProjectSettings::CONFIG_VERSION) { - ProjectSettings *ps = ProjectSettings::get_singleton(); - ps->load_custom(conf); - ps->set("application/config/features", project_features); - ps->save_custom(conf); - } - } PackedStringArray unsupported_features = ProjectSettings::get_unsupported_features(project_features); uint64_t last_edited = 0; @@ -1427,7 +1361,7 @@ void ProjectList::create_project_item_control(int p_index) { favorite->set_mouse_filter(MOUSE_FILTER_PASS); favorite->connect("pressed", callable_mp(this, &ProjectList::_favorite_pressed), varray(hb)); favorite_box->add_child(favorite); - favorite_box->set_alignment(BoxContainer::ALIGN_CENTER); + favorite_box->set_alignment(BoxContainer::ALIGNMENT_CENTER); hb->add_child(favorite_box); hb->favorite_button = favorite; hb->set_is_favorite(item.favorite); @@ -1470,11 +1404,11 @@ void ProjectList::create_project_item_control(int p_index) { int length = unsupported_features_str.length(); if (length > 0) { Label *unsupported_label = memnew(Label(unsupported_features_str)); - unsupported_label->set_custom_minimum_size(Size2(length * 15, 10)); + unsupported_label->set_custom_minimum_size(Size2(length * 15, 10) * EDSCALE); unsupported_label->add_theme_font_override("font", get_theme_font(SNAME("title"), SNAME("EditorFonts"))); unsupported_label->add_theme_color_override("font_color", get_theme_color(SNAME("warning_color"), SNAME("Editor"))); unsupported_label->set_clip_text(true); - unsupported_label->set_align(Label::ALIGN_RIGHT); + unsupported_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_RIGHT); title_hb->add_child(unsupported_label); Control *spacer = memnew(Control()); spacer->set_custom_minimum_size(Size2(10, 10)); @@ -1539,7 +1473,7 @@ void ProjectList::sort_projects() { Item &item = _projects.write[i]; bool visible = true; - if (_search_term != "") { + if (!_search_term.is_empty()) { String search_path; if (_search_term.find("/") != -1) { // Search path will match the whole path @@ -1851,7 +1785,7 @@ void ProjectList::_panel_input(const Ref<InputEvent> &p_ev, Node *p_hb) { const Item &clicked_project = _projects[clicked_index]; if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) { - if (mb->is_shift_pressed() && _selected_project_keys.size() > 0 && _last_clicked != "" && clicked_project.project_key != _last_clicked) { + if (mb->is_shift_pressed() && _selected_project_keys.size() > 0 && !_last_clicked.is_empty() && clicked_project.project_key != _last_clicked) { int anchor_index = -1; for (int i = 0; i < _projects.size(); ++i) { const Item &p = _projects[i]; @@ -2200,7 +2134,7 @@ void ProjectManager::_open_selected_projects_ask() { PackedStringArray unsupported_features = project.unsupported_features; Label *ask_update_label = ask_update_settings->get_label(); - ask_update_label->set_align(Label::ALIGN_LEFT); // Reset in case of previous center align. + ask_update_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_LEFT); // Reset in case of previous center align. // Check if the config_version property was empty or 0 if (config_version == 0) { @@ -2244,7 +2178,7 @@ void ProjectManager::_open_selected_projects_ask() { warning_message += vformat(TTR("Warning: This project uses the following features not supported by this build of Godot:\n\n%s\n\n"), unsupported_features_str); } warning_message += TTR("Open anyway? Project will be modified."); - ask_update_label->set_align(Label::ALIGN_CENTER); + ask_update_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); ask_update_settings->set_text(warning_message); ask_update_settings->popup_centered(); return; @@ -2259,7 +2193,7 @@ void ProjectManager::_run_project_confirm() { for (int i = 0; i < selected_list.size(); ++i) { const String &selected_main = selected_list[i].main_scene; - if (selected_main == "") { + if (selected_main.is_empty()) { run_error_diag->set_text(TTR("Can't run project: no main scene defined.\nPlease edit the project and set the main scene in the Project Settings under the \"Application\" category.")); run_error_diag->popup_centered(); continue; @@ -2312,7 +2246,7 @@ void ProjectManager::_scan_dir(const String &path, List<String> *r_projects) { ERR_FAIL_COND_MSG(error != OK, "Could not scan directory at: " + path); da->list_dir_begin(); String n = da->get_next(); - while (n != String()) { + while (!n.is_empty()) { if (da->current_is_dir() && !n.begins_with(".")) { _scan_dir(da->get_current_dir().plus_file(n), r_projects); } else if (n == "project.godot") { @@ -2454,7 +2388,7 @@ void ProjectManager::_files_dropped(PackedStringArray p_files, int p_screen) { if (dir->change_dir(folders[0]) == OK) { dir->list_dir_begin(); String file = dir->get_next(); - while (confirm && file != String()) { + while (confirm && !file.is_empty()) { if (!dir->current_is_dir() && file.ends_with("project.godot")) { confirm = false; } @@ -2603,7 +2537,7 @@ ProjectManager::ProjectManager() { tabs = memnew(TabContainer); center_box->add_child(tabs); tabs->set_anchors_and_offsets_preset(Control::PRESET_WIDE); - tabs->set_tab_align(TabContainer::ALIGN_LEFT); + tabs->set_tab_alignment(TabContainer::ALIGNMENT_LEFT); tabs->connect("tab_changed", callable_mp(this, &ProjectManager::_on_tab_changed)); HBoxContainer *projects_hb = memnew(HBoxContainer); @@ -2661,7 +2595,7 @@ ProjectManager::ProjectManager() { _project_list = memnew(ProjectList); _project_list->connect(ProjectList::SIGNAL_SELECTION_CHANGED, callable_mp(this, &ProjectManager::_update_project_buttons)); _project_list->connect(ProjectList::SIGNAL_PROJECT_ASK_OPEN, callable_mp(this, &ProjectManager::_open_selected_projects_ask)); - _project_list->set_enable_h_scroll(false); + _project_list->set_horizontal_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED); pc->add_child(_project_list); } @@ -2732,7 +2666,7 @@ ProjectManager::ProjectManager() { { // Version info and language options settings_hb = memnew(HBoxContainer); - settings_hb->set_alignment(BoxContainer::ALIGN_END); + settings_hb->set_alignment(BoxContainer::ALIGNMENT_END); settings_hb->set_h_grow_direction(Control::GROW_DIRECTION_BEGIN); settings_hb->set_anchors_and_offsets_preset(Control::PRESET_TOP_RIGHT); @@ -2783,7 +2717,7 @@ ProjectManager::ProjectManager() { for (int i = 0; i < editor_languages.size(); i++) { String lang = editor_languages[i]; String lang_name = TranslationServer::get_singleton()->get_locale_name(lang); - language_btn->add_item(lang_name + " [" + lang + "]", i); + language_btn->add_item(vformat("[%s] %s", lang, lang_name), i); language_btn->set_item_metadata(i, lang); if (current_lang == lang) { language_btn->select(i); @@ -2892,7 +2826,7 @@ ProjectManager::ProjectManager() { } String autoscan_path = EditorSettings::get_singleton()->get("filesystem/directories/autoscan_project_path"); - if (autoscan_path != "") { + if (!autoscan_path.is_empty()) { if (dir_access->dir_exists(autoscan_path)) { _scan_begin(autoscan_path); } else { |