Browse Source

Merge pull request #41036 from nathanfranke/default-2d-editor

Make default main screen plugin work even if 2D and 3D are disabled in editor features
Rémi Verschelde 4 years ago
parent
commit
c2083160b1
2 changed files with 25 additions and 7 deletions
  1. 23 7
      editor/editor_node.cpp
  2. 2 0
      editor/editor_node.h

+ 23 - 7
editor/editor_node.cpp

@@ -524,6 +524,26 @@ void EditorNode::_update_from_settings() {
 	RS::get_singleton()->light_projectors_set_filter(RS::LightProjectorFilter(int(GLOBAL_GET("rendering/textures/light_projectors/filter"))));
 }
 
+void EditorNode::_select_default_main_screen_plugin() {
+	if (EDITOR_3D < main_editor_buttons.size() && main_editor_buttons[EDITOR_3D]->is_visible()) {
+		// If the 3D editor is enabled, use this as the default.
+		_editor_select(EDITOR_3D);
+		return;
+	}
+
+	// Switch to the first main screen plugin that is enabled. Usually this is
+	// 2D, but may be subsequent ones if 2D is disabled in the feature profile.
+	for (int i = 0; i < main_editor_buttons.size(); i++) {
+		Button *editor_button = main_editor_buttons[i];
+		if (editor_button->is_visible()) {
+			_editor_select(i);
+			return;
+		}
+	}
+
+	_editor_select(-1);
+}
+
 void EditorNode::_notification(int p_what) {
 	switch (p_what) {
 		case NOTIFICATION_PROCESS: {
@@ -613,11 +633,7 @@ void EditorNode::_notification(int p_what) {
 
 			feature_profile_manager->notify_changed();
 
-			if (!main_editor_buttons[EDITOR_3D]->is_visible()) { //may be hidden due to feature profile
-				_editor_select(EDITOR_2D);
-			} else {
-				_editor_select(EDITOR_3D);
-			}
+			_select_default_main_screen_plugin();
 
 			// Save the project after opening to mark it as last modified, except in headless mode.
 			if (DisplayServer::get_singleton()->window_can_draw()) {
@@ -3100,9 +3116,10 @@ void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed
 		tb->set_flat(true);
 		tb->set_toggle_mode(true);
 		tb->connect("pressed", callable_mp(singleton, &EditorNode::_editor_select), varray(singleton->main_editor_buttons.size()));
+		tb->set_name(p_editor->get_name());
 		tb->set_text(p_editor->get_name());
-		Ref<Texture2D> icon = p_editor->get_icon();
 
+		Ref<Texture2D> icon = p_editor->get_icon();
 		if (icon.is_valid()) {
 			tb->set_icon(icon);
 		} else if (singleton->gui_base->has_theme_icon(p_editor->get_name(), "EditorIcons")) {
@@ -3112,7 +3129,6 @@ void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed
 		tb->add_theme_font_override("font", singleton->gui_base->get_theme_font(SNAME("main_button_font"), SNAME("EditorFonts")));
 		tb->add_theme_font_size_override("font_size", singleton->gui_base->get_theme_font_size(SNAME("main_button_font_size"), SNAME("EditorFonts")));
 
-		tb->set_name(p_editor->get_name());
 		singleton->main_editor_buttons.push_back(tb);
 		singleton->main_editor_button_vb->add_child(tb);
 		singleton->editor_table.push_back(p_editor);

+ 2 - 0
editor/editor_node.h

@@ -682,6 +682,8 @@ private:
 	bool immediate_dialog_confirmed = false;
 	void _immediate_dialog_confirmed();
 
+	void _select_default_main_screen_plugin();
+
 protected:
 	void _notification(int p_what);