diff options
Diffstat (limited to 'editor/scene_tree_dock.cpp')
-rw-r--r-- | editor/scene_tree_dock.cpp | 154 |
1 files changed, 80 insertions, 74 deletions
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index f3e59932c4..f866a158f3 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -319,6 +319,14 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { editor->push_item(existing.ptr()); else { String path = selected->get_filename(); + if (path == "") { + String root_path = editor_data->get_edited_scene_root()->get_filename(); + if (root_path == "") { + path = "res://" + selected->get_name(); + } else { + path = root_path.get_base_dir() + "/" + selected->get_name(); + } + } script_create_dialog->config(selected->get_class(), path); script_create_dialog->popup_centered(); } @@ -435,8 +443,8 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { List<Node *> owned; node->get_owned_by(node->get_owner(), &owned); - Map<Node *, Node *> duplimap; - Node *dup = _duplicate(node, duplimap); + Map<const Node *, Node *> duplimap; + Node *dup = node->duplicate_from_editor(duplimap); ERR_CONTINUE(!dup); @@ -525,10 +533,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { if (p_confirm_override) { _delete_confirm(); - // hack, force 2d editor viewport to refresh after deletion - if (CanvasItemEditor *editor = CanvasItemEditor::get_singleton()) - editor->get_viewport_control()->update(); - } else { delete_dialog->set_text(TTR("Delete Node(s)?")); delete_dialog->popup_centered_minsize(); @@ -817,74 +821,6 @@ void SceneTreeDock::_node_renamed() { _node_selected(); } -Node *SceneTreeDock::_duplicate(Node *p_node, Map<Node *, Node *> &duplimap) { - - Node *node = NULL; - - if (p_node->get_filename() != "") { //an instance - - Ref<PackedScene> sd = ResourceLoader::load(p_node->get_filename()); - ERR_FAIL_COND_V(!sd.is_valid(), NULL); - node = sd->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); - ERR_FAIL_COND_V(!node, NULL); - node->set_scene_instance_load_placeholder(p_node->get_scene_instance_load_placeholder()); - } else { - Object *obj = ClassDB::instance(p_node->get_class()); - ERR_FAIL_COND_V(!obj, NULL); - node = Object::cast_to<Node>(obj); - if (!node) - memdelete(obj); - ERR_FAIL_COND_V(!node, NULL); - } - - List<PropertyInfo> plist; - - p_node->get_property_list(&plist); - - for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) - continue; - String name = E->get().name; - Variant value = p_node->get(name); - // Duplicate dictionaries and arrays, mainly needed for __meta__ - if (value.get_type() == Variant::DICTIONARY) { - value = Dictionary(value).copy(); - } else if (value.get_type() == Variant::ARRAY) { - value = Array(value).duplicate(); - } - node->set(name, value); - } - - List<Node::GroupInfo> group_info; - p_node->get_groups(&group_info); - for (List<Node::GroupInfo>::Element *E = group_info.front(); E; E = E->next()) { - - if (E->get().persistent) - node->add_to_group(E->get().name, true); - } - - node->set_name(p_node->get_name()); - duplimap[p_node] = node; - - for (int i = 0; i < p_node->get_child_count(); i++) { - - Node *child = p_node->get_child(i); - if (p_node->get_owner() != child->get_owner()) - continue; //don't bother with not in-scene nodes. - - Node *dup = _duplicate(child, duplimap); - if (!dup) { - memdelete(node); - return NULL; - } - - node->add_child(dup); - } - - return node; -} - void SceneTreeDock::_set_owners(Node *p_owner, const Array &p_nodes) { for (int i = 0; i < p_nodes.size(); i++) { @@ -1292,6 +1228,7 @@ void SceneTreeDock::_delete_confirm() { editor_data->get_undo_redo().add_do_method(editor, "set_edited_scene", (Object *)NULL); editor_data->get_undo_redo().add_undo_method(editor, "set_edited_scene", edited_scene); editor_data->get_undo_redo().add_undo_method(edited_scene, "set_owner", edited_scene->get_owner()); + editor_data->get_undo_redo().add_undo_method(scene_tree, "update_tree"); editor_data->get_undo_redo().add_undo_reference(edited_scene); } else { @@ -1337,6 +1274,12 @@ void SceneTreeDock::_delete_confirm() { } } editor_data->get_undo_redo().commit_action(); + + // hack, force 2d editor viewport to refresh after deletion + if (CanvasItemEditor *editor = CanvasItemEditor::get_singleton()) + editor->get_viewport_control()->update(); + + editor->push_item(NULL); } void SceneTreeDock::_selection_changed() { @@ -1404,6 +1347,7 @@ void SceneTreeDock::_create() { } else { editor_data->get_undo_redo().add_do_method(editor, "set_edited_scene", child); + editor_data->get_undo_redo().add_do_method(scene_tree, "update_tree"); editor_data->get_undo_redo().add_do_reference(child); editor_data->get_undo_redo().add_undo_method(editor, "set_edited_scene", (Object *)NULL); } @@ -1439,6 +1383,8 @@ void SceneTreeDock::_create() { for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; + if (E->get().name == "__meta__") + continue; newnode->set(E->get().name, n->get(E->get().name)); } @@ -1868,6 +1814,43 @@ void SceneTreeDock::open_script_dialog(Node *p_for_node) { _tool_selected(TOOL_ATTACH_SCRIPT); } +void SceneTreeDock::add_remote_tree_editor(Control *p_remote) { + ERR_FAIL_COND(remote_tree != NULL); + add_child(p_remote); + remote_tree = p_remote; + remote_tree->hide(); +} + +void SceneTreeDock::show_remote_tree() { + + button_hb->show(); + _remote_tree_selected(); +} + +void SceneTreeDock::hide_remote_tree() { + + button_hb->hide(); + _local_tree_selected(); +} + +void SceneTreeDock::_remote_tree_selected() { + + scene_tree->hide(); + if (remote_tree) + remote_tree->show(); + edit_remote->set_pressed(true); + edit_local->set_pressed(false); +} + +void SceneTreeDock::_local_tree_selected() { + + scene_tree->show(); + if (remote_tree) + remote_tree->hide(); + edit_remote->set_pressed(false); + edit_local->set_pressed(true); +} + void SceneTreeDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_tool_selected"), &SceneTreeDock::_tool_selected, DEFVAL(false)); @@ -1893,6 +1876,8 @@ void SceneTreeDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_tree_rmb"), &SceneTreeDock::_tree_rmb); ClassDB::bind_method(D_METHOD("_filter_changed"), &SceneTreeDock::_filter_changed); ClassDB::bind_method(D_METHOD("_focus_node"), &SceneTreeDock::_focus_node); + ClassDB::bind_method(D_METHOD("_remote_tree_selected"), &SceneTreeDock::_remote_tree_selected); + ClassDB::bind_method(D_METHOD("_local_tree_selected"), &SceneTreeDock::_local_tree_selected); ClassDB::bind_method(D_METHOD("instance"), &SceneTreeDock::instance); } @@ -1963,7 +1948,28 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel button_clear_script = tb; tb->hide(); + button_hb = memnew(HBoxContainer); + vbc->add_child(button_hb); + + edit_remote = memnew(ToolButton); + button_hb->add_child(edit_remote); + edit_remote->set_h_size_flags(SIZE_EXPAND_FILL); + edit_remote->set_text(TTR("Remote")); + edit_remote->set_toggle_mode(true); + edit_remote->connect("pressed", this, "_remote_tree_selected"); + + edit_local = memnew(ToolButton); + button_hb->add_child(edit_local); + edit_local->set_h_size_flags(SIZE_EXPAND_FILL); + edit_local->set_text(TTR("Local")); + edit_local->set_toggle_mode(true); + edit_local->connect("pressed", this, "_local_tree_selected"); + + remote_tree = NULL; + button_hb->hide(); + scene_tree = memnew(SceneTreeEditor(false, true, true)); + vbc->add_child(scene_tree); scene_tree->set_v_size_flags(SIZE_EXPAND | SIZE_FILL); scene_tree->connect("rmb_pressed", this, "_tree_rmb"); |