Selaa lähdekoodia

Merge pull request #2928 from akien-mga/pr-subscene-icon-in-dock

Moved subscene creation from scene menu to an icon on the scene dock
Rémi Verschelde 9 vuotta sitten
vanhempi
commit
d64a9526cd

+ 0 - 134
tools/editor/editor_node.cpp

@@ -1194,75 +1194,6 @@ void EditorNode::_dialog_action(String p_file) {
 			save_translatable_strings(p_file);
 
 		} break;
-		case FILE_SAVE_SUBSCENE: {
-
-			List<Node*> selection = editor_selection->get_selected_node_list();
-
-			if (selection.size()!=1) {
-
-				current_option=-1;
-				//confirmation->get_cancel()->hide();
-				accept->get_ok()->set_text("I see..");
-				accept->set_text("This operation requieres a single selected node.");
-				accept->popup_centered_minsize();
-				break;
-			}
-
-			Node *base = selection.front()->get();
-
-			Map<Node*,Node*> reown;
-			reown[editor_data.get_edited_scene_root()]=base;
-			Node *copy = base->duplicate_and_reown(reown);
-			if (copy) {
-
-				Ref<PackedScene> sdata = memnew( PackedScene );
-				Error err = sdata->pack(copy);
-				memdelete(copy);
-
-				if (err!=OK) {
-
-
-					current_option=-1;
-					//accept->get_cancel()->hide();
-					accept->get_ok()->set_text("I see..");
-					accept->set_text("Couldn't save subscene. Likely dependencies (instances) couldn't be satisfied.");
-					accept->popup_centered_minsize();
-					return;
-				}
-
-				int flg=0;
-				if (EditorSettings::get_singleton()->get("on_save/compress_binary_resources"))
-					flg|=ResourceSaver::FLAG_COMPRESS;
-				if (EditorSettings::get_singleton()->get("on_save/save_paths_as_relative"))
-					flg|=ResourceSaver::FLAG_RELATIVE_PATHS;
-
-
-				err = ResourceSaver::save(p_file,sdata,flg);
-				if (err!=OK) {
-
-					current_option=-1;
-					//confirmation->get_cancel()->hide();
-					accept->get_ok()->set_text("I see..");
-					accept->set_text("Error saving scene.");
-					accept->popup_centered_minsize();
-					break;
-				}
-		//EditorFileSystem::get_singleton()->update_file(p_file,sdata->get_type());
-
-            } else {
-
-				current_option=-1;
-				//confirmation->get_cancel()->hide();
-				accept->get_ok()->set_text("I see..");
-				accept->set_text("Error duplicating scene to save it.");
-				accept->popup_centered_minsize();
-				break;
-
-			}
-
-
-		} break;
-
 
 		case FILE_SAVE_SCENE:
 		case FILE_SAVE_AS_SCENE: {
@@ -2241,70 +2172,6 @@ void EditorNode::_menu_option_confirm(int p_option,bool p_confirmed) {
 			file->set_title("Save Translatable Strings");
 			file->popup_centered_ratio();
 
-
-		} break;
-
-		case FILE_SAVE_SUBSCENE: {
-
-			Node *scene = editor_data.get_edited_scene_root();
-
-			if (!scene) {
-
-				current_option=-1;
-				//confirmation->get_cancel()->hide();
-				accept->get_ok()->set_text("I see..");
-				accept->set_text("This operation can't be done without a scene.");
-				accept->popup_centered_minsize();
-				break;
-			}
-
-
-			List<Node*> selection = editor_selection->get_selected_node_list();
-
-			if (selection.size()!=1) {
-
-				current_option=-1;
-				//confirmation->get_cancel()->hide();
-				accept->get_ok()->set_text("I see..");
-				accept->set_text("This operation requieres a single selected node.");
-				accept->popup_centered_minsize();
-				break;
-			}
-
-			Node *tocopy = selection.front()->get();
-
-			if (tocopy!=editor_data.get_edited_scene_root() && tocopy->get_filename()!="") {
-
-
-				current_option=-1;
-				//confirmation->get_cancel()->hide();
-				accept->get_ok()->set_text("I see..");
-				accept->set_text("This operation can't be done on instanced scenes.");
-				accept->popup_centered_minsize();
-				break;
-			}
-
-			file->set_mode(EditorFileDialog::MODE_SAVE_FILE);
-
-			List<String> extensions;
-			Ref<PackedScene> sd = memnew( PackedScene );
-			ResourceSaver::get_recognized_extensions(sd,&extensions);
-			file->clear_filters();
-			for(int i=0;i<extensions.size();i++) {
-
-				file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper());
-			}
-
-
-			String existing;
-			if (extensions.size()) {
-				existing="new_scene."+extensions.front()->get().to_lower();
-			}
-			file->set_current_path(existing);
-
-
-			file->popup_centered_ratio();
-			file->set_title("Save Sub-Scene As..");
 		} break;
 		case FILE_SAVE_OPTIMIZED: {
 			Node *scene = editor_data.get_edited_scene_root();
@@ -5202,7 +5069,6 @@ EditorNode::EditorNode() {
 	pm_export->set_name("Export");
 	p->add_child(pm_export);
 	p->add_submenu_item("Convert To..","Export");
-	pm_export->add_item("Subscene..",FILE_SAVE_SUBSCENE);
 	pm_export->add_item("Translatable Strings..",FILE_DUMP_STRINGS);
 	pm_export->add_separator();
 	pm_export->add_item("MeshLibrary..",FILE_EXPORT_MESH_LIBRARY);

+ 3 - 5
tools/editor/editor_node.h

@@ -100,13 +100,12 @@ typedef void (*EditorNodeInitCallback)();
 class EditorNode : public Node {
 
 	OBJ_TYPE( EditorNode, Node );
-	
+
 	enum {
-		
-		HISTORY_SIZE=64	
+		HISTORY_SIZE=64
 	};
+
 	enum MenuOptions {
-	
 		FILE_NEW_SCENE,
 		FILE_NEW_INHERITED_SCENE,
 		FILE_OPEN_SCENE,
@@ -119,7 +118,6 @@ class EditorNode : public Node {
 		FILE_EXPORT_MESH_LIBRARY,
 		FILE_EXPORT_TILESET,
 		FILE_SAVE_OPTIMIZED,
-		FILE_SAVE_SUBSCENE,
 		FILE_DUMP_STRINGS,
 		FILE_OPEN_RECENT,
 		FILE_OPEN_OLD_SCENE,

BIN
tools/editor/icons/icon_create_new_scene_from.png


+ 121 - 1
tools/editor/scene_tree_dock.cpp

@@ -35,6 +35,7 @@
 #include "tools/editor/plugins/canvas_item_editor_plugin.h"
 #include "script_editor_debugger.h"
 #include "tools/editor/plugins/script_editor_plugin.h"
+#include "core/io/resource_saver.h"
 #include "multi_node_edit.h"
 
 void SceneTreeDock::_unhandled_key_input(InputEvent p_event) {
@@ -485,7 +486,54 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
 				delete_dialog->popup_centered_minsize();
 			}
 
+		} break;
+		case TOOL_NEW_SCENE_FROM: {
+
+			Node *scene = editor_data->get_edited_scene_root();
 
+			if (!scene) {
+				accept->get_ok()->set_text("I see..");
+				accept->set_text("This operation can't be done without a scene.");
+				accept->popup_centered_minsize();
+				break;
+			}
+
+			List<Node*> selection = editor_selection->get_selected_node_list();
+
+			if (selection.size()!=1) {
+				accept->get_ok()->set_text("I see..");
+				accept->set_text("This operation requires a single selected node.");
+				accept->popup_centered_minsize();
+				break;
+			}
+
+			Node *tocopy = selection.front()->get();
+
+			if (tocopy!=editor_data->get_edited_scene_root() && tocopy->get_filename()!="") {
+				accept->get_ok()->set_text("I see..");
+				accept->set_text("This operation can't be done on instanced scenes.");
+				accept->popup_centered_minsize();
+				break;
+			}
+
+			new_scene_from_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
+
+			List<String> extensions;
+			Ref<PackedScene> sd = memnew( PackedScene );
+			ResourceSaver::get_recognized_extensions(sd,&extensions);
+			new_scene_from_dialog->clear_filters();
+			for(int i=0;i<extensions.size();i++) {
+				new_scene_from_dialog->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper());
+			}
+
+			String existing;
+			if (extensions.size()) {
+				existing="new_scene."+extensions.front()->get().to_lower();
+			}
+			new_scene_from_dialog->set_current_path(existing);
+
+			new_scene_from_dialog->popup_centered_ratio();
+			new_scene_from_dialog->set_title("Save New Scene As..");
 
 		} break;
 
@@ -520,6 +568,7 @@ void SceneTreeDock::_notification(int p_what) {
 				"MoveDown",
 				"Duplicate",
 				"Reparent",
+				"CreateNewSceneFrom",
 				"MultiNodeEdit",
 				"Remove",
 			};
@@ -1140,6 +1189,7 @@ void SceneTreeDock::_update_tool_buttons() {
 	tool_buttons[TOOL_DUPLICATE]->set_disabled(disable_root);
 	tool_buttons[TOOL_REPARENT]->set_disabled(disable_root);
 	tool_buttons[TOOL_ERASE]->set_disabled(disable);
+	tool_buttons[TOOL_NEW_SCENE_FROM]->set_disabled(disable_root);
 	tool_buttons[TOOL_MULTI_EDIT]->set_disabled(EditorNode::get_singleton()->get_editor_selection()->get_selection().size()<2);
 
 
@@ -1326,6 +1376,59 @@ void SceneTreeDock::_import_subscene() {
 */
 }
 
+void SceneTreeDock::_new_scene_from(String p_file) {
+
+	List<Node*> selection = editor_selection->get_selected_node_list();
+
+	if (selection.size()!=1) {
+		accept->get_ok()->set_text("I see..");
+		accept->set_text("This operation requires a single selected node.");
+		accept->popup_centered_minsize();
+		return;
+	}
+
+	Node *base = selection.front()->get();
+
+	Map<Node*,Node*> reown;
+	reown[editor_data->get_edited_scene_root()]=base;
+	Node *copy = base->duplicate_and_reown(reown);
+	if (copy) {
+
+		Ref<PackedScene> sdata = memnew( PackedScene );
+		Error err = sdata->pack(copy);
+		memdelete(copy);
+
+		if (err!=OK) {
+			accept->get_ok()->set_text("I see..");
+			accept->set_text("Couldn't save new scene. Likely dependencies (instances) couldn't be satisfied.");
+			accept->popup_centered_minsize();
+			return;
+		}
+
+		int flg=0;
+		if (EditorSettings::get_singleton()->get("on_save/compress_binary_resources"))
+			flg|=ResourceSaver::FLAG_COMPRESS;
+		if (EditorSettings::get_singleton()->get("on_save/save_paths_as_relative"))
+			flg|=ResourceSaver::FLAG_RELATIVE_PATHS;
+
+
+		err = ResourceSaver::save(p_file,sdata,flg);
+		if (err!=OK) {
+			accept->get_ok()->set_text("I see..");
+			accept->set_text("Error saving scene.");
+			accept->popup_centered_minsize();
+			return;
+		}
+
+	} else {
+		accept->get_ok()->set_text("I see..");
+		accept->set_text("Error duplicating scene to save it.");
+		accept->popup_centered_minsize();
+		return;
+	}
+
+}
+
 void SceneTreeDock::_bind_methods() {
 
 	ObjectTypeDB::bind_method(_MD("_tool_selected"),&SceneTreeDock::_tool_selected);
@@ -1343,6 +1446,7 @@ void SceneTreeDock::_bind_methods() {
 	ObjectTypeDB::bind_method(_MD("_node_prerenamed"),&SceneTreeDock::_node_prerenamed);
 	ObjectTypeDB::bind_method(_MD("_import_subscene"),&SceneTreeDock::_import_subscene);
 	ObjectTypeDB::bind_method(_MD("_selection_changed"),&SceneTreeDock::_selection_changed);
+	ObjectTypeDB::bind_method(_MD("_new_scene_from"),&SceneTreeDock::_new_scene_from);
 
 	ObjectTypeDB::bind_method(_MD("instance"),&SceneTreeDock::instance);
 }
@@ -1415,9 +1519,10 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec
 	scene_tree->set_undo_redo(&editor_data->get_undo_redo());
 	scene_tree->set_editor_selection(editor_selection);
 
+
 	HBoxContainer *hbc_bottom = memnew( HBoxContainer );
 	vbc->add_child(hbc_bottom);
-
+	hbc_bottom->add_constant_override("separation", 0);
 
 	tb = memnew( ToolButton );
 	tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_MOVE_UP, false));
@@ -1445,6 +1550,12 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec
 
 	hbc_bottom->add_spacer();
 
+	tb = memnew( ToolButton );
+	tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_NEW_SCENE_FROM, false));
+	tb->set_tooltip("Create New Scene From Node(s)");
+	hbc_bottom->add_child(tb);
+	tool_buttons[TOOL_NEW_SCENE_FROM]=tb;
+
 	tb = memnew( ToolButton );
 	tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_MULTI_EDIT, false));
 	tb->set_tooltip("Multi-Edit Selected Nodes");
@@ -1465,12 +1576,15 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec
 	groups_editor = memnew( GroupsEditor );
 	add_child(groups_editor);
 	groups_editor->set_undo_redo(&editor_data->get_undo_redo());
+
 	connect_dialog = memnew( ConnectionsDialog(p_editor) );
 	add_child(connect_dialog);
 	connect_dialog->set_undoredo(&editor_data->get_undo_redo());
+
 	script_create_dialog = memnew( ScriptCreateDialog );
 	add_child(script_create_dialog);
 	script_create_dialog->connect("script_created",this,"_script_created");
+
 	reparent_dialog = memnew( ReparentDialog );
 	add_child(reparent_dialog);
 	reparent_dialog->connect("reparent",this,"_node_reparent");
@@ -1486,10 +1600,16 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelec
 	delete_dialog = memnew( ConfirmationDialog );
 	add_child(delete_dialog);
 	delete_dialog->connect("confirmed",this,"_delete_confirm");
+
 	import_subscene_dialog = memnew( EditorSubScene );
 	add_child(import_subscene_dialog);
 	import_subscene_dialog->connect("subscene_selected",this,"_import_subscene");
 
+	new_scene_from_dialog = memnew( EditorFileDialog );
+	new_scene_from_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
+	add_child(new_scene_from_dialog);
+	new_scene_from_dialog->connect("file_selected",this,"_new_scene_from");
+
 	first_enter=true;
 
 

+ 4 - 0
tools/editor/scene_tree_dock.h

@@ -62,6 +62,7 @@ class SceneTreeDock : public VBoxContainer {
 		TOOL_MOVE_DOWN,
 		TOOL_DUPLICATE,
 		TOOL_REPARENT,
+		TOOL_NEW_SCENE_FROM,
 		TOOL_MULTI_EDIT,
 		TOOL_ERASE,
 		TOOL_BUTTON_MAX
@@ -90,6 +91,7 @@ class SceneTreeDock : public VBoxContainer {
 	ReparentDialog *reparent_dialog;
 	EditorFileDialog *file;
 	EditorSubScene *import_subscene_dialog;
+	EditorFileDialog *new_scene_from_dialog;
 
 	bool first_enter;
 
@@ -119,6 +121,8 @@ class SceneTreeDock : public VBoxContainer {
 
 	void _import_subscene();
 
+	void _new_scene_from(String p_file);
+
 	bool _validate_no_foreign();
 	void _selection_changed();