Browse Source

Add option to convert project from Project Manager

kobewi 3 years ago
parent
commit
305d407dad
2 changed files with 61 additions and 1 deletions
  1. 58 1
      editor/project_manager.cpp
  2. 3 0
      editor/project_manager.h

+ 58 - 1
editor/project_manager.cpp

@@ -59,6 +59,8 @@
 #include "servers/navigation_server_3d.h"
 #include "servers/navigation_server_3d.h"
 #include "servers/physics_server_2d.h"
 #include "servers/physics_server_2d.h"
 
 
+constexpr int GODOT4_CONFIG_VERSION = 5;
+
 class ProjectDialog : public ConfirmationDialog {
 class ProjectDialog : public ConfirmationDialog {
 	GDCLASS(ProjectDialog, ConfirmationDialog);
 	GDCLASS(ProjectDialog, ConfirmationDialog);
 
 
@@ -1065,6 +1067,7 @@ public:
 	int refresh_project(const String &dir_path);
 	int refresh_project(const String &dir_path);
 	void add_project(const String &dir_path, bool favorite);
 	void add_project(const String &dir_path, bool favorite);
 	void save_config();
 	void save_config();
+	void set_project_version(const String &p_project_path, int version);
 
 
 private:
 private:
 	static void _bind_methods();
 	static void _bind_methods();
@@ -1673,6 +1676,15 @@ void ProjectList::save_config() {
 	_config.save(_config_path);
 	_config.save(_config_path);
 }
 }
 
 
+void ProjectList::set_project_version(const String &p_project_path, int p_version) {
+	for (ProjectList::Item &E : _projects) {
+		if (E.path == p_project_path) {
+			E.version = p_version;
+			break;
+		}
+	}
+}
+
 int ProjectList::get_project_count() const {
 int ProjectList::get_project_count() const {
 	return _projects.size();
 	return _projects.size();
 }
 }
@@ -2170,6 +2182,9 @@ void ProjectManager::_open_selected_projects_ask() {
 
 
 	Label *ask_update_label = ask_update_settings->get_label();
 	Label *ask_update_label = ask_update_settings->get_label();
 	ask_update_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_LEFT); // Reset in case of previous center align.
 	ask_update_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_LEFT); // Reset in case of previous center align.
+	full_convert_button->hide();
+
+	ask_update_settings->get_ok_button()->set_text("OK");
 
 
 	// Check if the config_version property was empty or 0
 	// Check if the config_version property was empty or 0
 	if (config_version == 0) {
 	if (config_version == 0) {
@@ -2179,7 +2194,11 @@ void ProjectManager::_open_selected_projects_ask() {
 	}
 	}
 	// Check if we need to convert project settings from an earlier engine version
 	// Check if we need to convert project settings from an earlier engine version
 	if (config_version < ProjectSettings::CONFIG_VERSION) {
 	if (config_version < ProjectSettings::CONFIG_VERSION) {
-		ask_update_settings->set_text(vformat(TTR("The following project settings file was generated by an older engine version, and needs to be converted for this version:\n\n%s\n\nDo you want to convert it?\nWarning: You won't be able to open the project with previous versions of the engine anymore."), conf));
+		if (config_version == GODOT4_CONFIG_VERSION - 1 && ProjectSettings::CONFIG_VERSION == GODOT4_CONFIG_VERSION) { // Conversion from Godot 3 to 4.
+			full_convert_button->show();
+		}
+		ask_update_settings->set_text(vformat(TTR("The following project settings file was generated by an older engine version, and needs to be converted for this version:\n\n%s\n\nDo you want to convert it? You can also convert the entire project (recommended if you are upgrading).\nWarning: You won't be able to open the project with previous versions of the engine anymore."), conf));
+		ask_update_settings->get_ok_button()->set_text(TTR("Convert project.godot"));
 		ask_update_settings->popup_centered();
 		ask_update_settings->popup_centered();
 		return;
 		return;
 	}
 	}
@@ -2223,6 +2242,32 @@ void ProjectManager::_open_selected_projects_ask() {
 	_open_selected_projects();
 	_open_selected_projects();
 }
 }
 
 
+void ProjectManager::_perform_full_project_conversion() {
+	Vector<ProjectList::Item> selected_list = _project_list->get_selected_projects();
+	if (selected_list.is_empty()) {
+		return;
+	}
+
+	const String &path = selected_list[0].path;
+
+	print_line("Converting project: " + path);
+
+	Ref<ConfigFile> cf;
+	cf.instantiate();
+	cf->load(path.path_join("project.godot"));
+	cf->set_value("", "config_version", GODOT4_CONFIG_VERSION);
+	cf->save(path.path_join("project.godot"));
+	_project_list->set_project_version(path, GODOT4_CONFIG_VERSION);
+
+	List<String> args;
+	args.push_back("--path");
+	args.push_back(path);
+	args.push_back("--convert-3to4");
+
+	Error err = OS::get_singleton()->create_instance(args);
+	ERR_FAIL_COND(err);
+}
+
 void ProjectManager::_run_project_confirm() {
 void ProjectManager::_run_project_confirm() {
 	Vector<ProjectList::Item> selected_list = _project_list->get_selected_projects();
 	Vector<ProjectList::Item> selected_list = _project_list->get_selected_projects();
 
 
@@ -2824,8 +2869,20 @@ ProjectManager::ProjectManager() {
 
 
 		ask_update_settings = memnew(ConfirmationDialog);
 		ask_update_settings = memnew(ConfirmationDialog);
 		ask_update_settings->get_ok_button()->connect("pressed", callable_mp(this, &ProjectManager::_confirm_update_settings));
 		ask_update_settings->get_ok_button()->connect("pressed", callable_mp(this, &ProjectManager::_confirm_update_settings));
+		full_convert_button = ask_update_settings->add_button("Perform Full Project Conversion", false);
 		add_child(ask_update_settings);
 		add_child(ask_update_settings);
 
 
+		ask_full_convert_dialog = memnew(ConfirmationDialog);
+		ask_full_convert_dialog->set_autowrap(true);
+		ask_full_convert_dialog->set_text(TTR(R"(This option will perform full project conversion, updating scenes and scripts from Godot 3.x to work in Godot 4.0. Note that this is a best-effort conversion, i.e. it makes upgrading the project easier, but it will not open out-of-the-box and will still require manual adjustments.
+
+IMPORTANT: Make sure to backup your project before converting, as this operation makes it impossible to open in older versions of Godot.)"));
+		ask_full_convert_dialog->connect("confirmed", callable_mp(this, &ProjectManager::_perform_full_project_conversion));
+		add_child(ask_full_convert_dialog);
+
+		full_convert_button->connect("pressed", callable_mp((Window *)ask_update_settings, &ConfirmationDialog::hide));
+		full_convert_button->connect("pressed", callable_mp((Window *)ask_full_convert_dialog, &ConfirmationDialog::popup_centered_ratio).bind(0.2));
+
 		npdialog = memnew(ProjectDialog);
 		npdialog = memnew(ProjectDialog);
 		npdialog->connect("projects_updated", callable_mp(this, &ProjectManager::_on_projects_updated));
 		npdialog->connect("projects_updated", callable_mp(this, &ProjectManager::_on_projects_updated));
 		npdialog->connect("project_created", callable_mp(this, &ProjectManager::_on_project_created));
 		npdialog->connect("project_created", callable_mp(this, &ProjectManager::_on_project_created));

+ 3 - 0
editor/project_manager.h

@@ -87,6 +87,7 @@ class ProjectManager : public Control {
 	ConfirmationDialog *multi_open_ask = nullptr;
 	ConfirmationDialog *multi_open_ask = nullptr;
 	ConfirmationDialog *multi_run_ask = nullptr;
 	ConfirmationDialog *multi_run_ask = nullptr;
 	ConfirmationDialog *multi_scan_ask = nullptr;
 	ConfirmationDialog *multi_scan_ask = nullptr;
+	ConfirmationDialog *ask_full_convert_dialog = nullptr;
 	ConfirmationDialog *ask_update_settings = nullptr;
 	ConfirmationDialog *ask_update_settings = nullptr;
 	ConfirmationDialog *open_templates = nullptr;
 	ConfirmationDialog *open_templates = nullptr;
 	EditorAbout *about = nullptr;
 	EditorAbout *about = nullptr;
@@ -97,6 +98,7 @@ class ProjectManager : public Control {
 	AcceptDialog *dialog_error = nullptr;
 	AcceptDialog *dialog_error = nullptr;
 	ProjectDialog *npdialog = nullptr;
 	ProjectDialog *npdialog = nullptr;
 
 
+	Button *full_convert_button = nullptr;
 	OptionButton *language_btn = nullptr;
 	OptionButton *language_btn = nullptr;
 	LinkButton *version_btn = nullptr;
 	LinkButton *version_btn = nullptr;
 
 
@@ -106,6 +108,7 @@ class ProjectManager : public Control {
 	void _run_project_confirm();
 	void _run_project_confirm();
 	void _open_selected_projects();
 	void _open_selected_projects();
 	void _open_selected_projects_ask();
 	void _open_selected_projects_ask();
+	void _perform_full_project_conversion();
 	void _import_project();
 	void _import_project();
 	void _new_project();
 	void _new_project();
 	void _rename_project();
 	void _rename_project();