Procházet zdrojové kódy

Project Manager: Fix crash on resize with assetlib disabled

Follow-up to #61215.

(cherry picked from commit 6f5be1f1f0db5e6cf4923899ecc0c4e9d593661d)
Rémi Verschelde před 3 roky
rodič
revize
1b297eb047
2 změnil soubory, kde provedl 28 přidání a 21 odebrání
  1. 26 19
      editor/project_manager.cpp
  2. 2 2
      editor/project_manager.h

+ 26 - 19
editor/project_manager.cpp

@@ -1769,30 +1769,35 @@ void ProjectManager::_notification(int p_what) {
 			Engine::get_singleton()->set_editor_hint(false);
 			Engine::get_singleton()->set_editor_hint(false);
 		} break;
 		} break;
 		case NOTIFICATION_RESIZED: {
 		case NOTIFICATION_RESIZED: {
-			if (open_templates->is_visible()) {
+			if (open_templates && open_templates->is_visible()) {
 				open_templates->popup_centered_minsize();
 				open_templates->popup_centered_minsize();
 			}
 			}
-			real_t size = get_size().x / EDSCALE;
-			asset_library->set_columns(size < 1000 ? 1 : 2);
-			// Adjust names of tabs to fit the new size.
-			if (size < 650) {
-				local_projects_hb->set_name(TTR("Local"));
-				asset_library->set_name(TTR("Asset Library"));
-			} else {
-				local_projects_hb->set_name(TTR("Local Projects"));
-				asset_library->set_name(TTR("Asset Library Projects"));
+			if (asset_library) {
+				real_t size = get_size().x / EDSCALE;
+				asset_library->set_columns(size < 1000 ? 1 : 2);
+				// Adjust names of tabs to fit the new size.
+				if (size < 650) {
+					local_projects_hb->set_name(TTR("Local"));
+					asset_library->set_name(TTR("Asset Library"));
+				} else {
+					local_projects_hb->set_name(TTR("Local Projects"));
+					asset_library->set_name(TTR("Asset Library Projects"));
+				}
 			}
 			}
 		} break;
 		} break;
 		case NOTIFICATION_READY: {
 		case NOTIFICATION_READY: {
-			if (_project_list->get_project_count() == 0 && StreamPeerSSL::is_available()) {
-				open_templates->popup_centered_minsize();
-			}
-
 			if (_project_list->get_project_count() >= 1) {
 			if (_project_list->get_project_count() >= 1) {
 				// Focus on the search box immediately to allow the user
 				// Focus on the search box immediately to allow the user
 				// to search without having to reach for their mouse
 				// to search without having to reach for their mouse
 				project_filter->search_box->grab_focus();
 				project_filter->search_box->grab_focus();
 			}
 			}
+
+			if (asset_library) {
+				// Suggest browsing asset library to get templates/demos.
+				if (open_templates && _project_list->get_project_count() == 0) {
+					open_templates->popup_centered_minsize();
+				}
+			}
 		} break;
 		} break;
 		case NOTIFICATION_VISIBILITY_CHANGED: {
 		case NOTIFICATION_VISIBILITY_CHANGED: {
 			set_process_unhandled_input(is_visible_in_tree());
 			set_process_unhandled_input(is_visible_in_tree());
@@ -2766,11 +2771,13 @@ ProjectManager::ProjectManager() {
 	dialog_error = memnew(AcceptDialog);
 	dialog_error = memnew(AcceptDialog);
 	gui_base->add_child(dialog_error);
 	gui_base->add_child(dialog_error);
 
 
-	open_templates = memnew(ConfirmationDialog);
-	open_templates->set_text(TTR("You currently don't have any projects.\nWould you like to explore official example projects in the Asset Library?"));
-	open_templates->get_ok()->set_text(TTR("Open Asset Library"));
-	open_templates->connect("confirmed", this, "_open_asset_library");
-	add_child(open_templates);
+	if (asset_library) {
+		open_templates = memnew(ConfirmationDialog);
+		open_templates->set_text(TTR("You currently don't have any projects.\nWould you like to explore official example projects in the Asset Library?"));
+		open_templates->get_ok()->set_text(TTR("Open Asset Library"));
+		open_templates->connect("confirmed", this, "_open_asset_library");
+		add_child(open_templates);
+	}
 
 
 	about = memnew(EditorAbout);
 	about = memnew(EditorAbout);
 	add_child(about);
 	add_child(about);

+ 2 - 2
editor/project_manager.h

@@ -53,7 +53,7 @@ class ProjectManager : public Control {
 	Button *run_btn;
 	Button *run_btn;
 	Button *about_btn;
 	Button *about_btn;
 
 
-	EditorAssetLibrary *asset_library;
+	EditorAssetLibrary *asset_library = nullptr;
 
 
 	ProjectListFilter *project_filter;
 	ProjectListFilter *project_filter;
 	ProjectListFilter *project_order_filter;
 	ProjectListFilter *project_order_filter;
@@ -71,7 +71,7 @@ class ProjectManager : public Control {
 	ConfirmationDialog *multi_run_ask;
 	ConfirmationDialog *multi_run_ask;
 	ConfirmationDialog *multi_scan_ask;
 	ConfirmationDialog *multi_scan_ask;
 	ConfirmationDialog *ask_update_settings;
 	ConfirmationDialog *ask_update_settings;
-	ConfirmationDialog *open_templates;
+	ConfirmationDialog *open_templates = nullptr;
 	EditorAbout *about;
 	EditorAbout *about;
 	AcceptDialog *run_error_diag;
 	AcceptDialog *run_error_diag;
 	AcceptDialog *dialog_error;
 	AcceptDialog *dialog_error;