mirror of
https://github.com/godotengine/godot.git
synced 2024-11-10 14:12:51 +00:00
Moved subscene creation from scene menu to an icon on the scene dock
Based on @Fiona's PR #2220. The previous "subscene" concept is also renamed to "new scene", as those subscene are just like regular scenes.
This commit is contained in:
parent
ed4738fbed
commit
20efb48101
@ -1162,75 +1162,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: {
|
||||
@ -2141,70 +2072,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();
|
||||
@ -4972,7 +4839,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);
|
||||
|
@ -99,13 +99,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,
|
||||
@ -118,7 +117,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
Normal file
BIN
tools/editor/icons/icon_create_new_scene_from.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 521 B |
@ -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",
|
||||
};
|
||||
@ -1103,6 +1152,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);
|
||||
|
||||
|
||||
@ -1284,6 +1334,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);
|
||||
@ -1301,6 +1404,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);
|
||||
}
|
||||
@ -1403,6 +1507,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");
|
||||
@ -1423,12 +1533,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");
|
||||
@ -1444,10 +1557,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;
|
||||
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user