Esempio n. 1
0
void SceneTreeDock::_create() {


	if (current_option==TOOL_NEW) {

		Node *parent=NULL;


		if (edited_scene) {

			parent = scene_tree->get_selected();
			ERR_FAIL_COND(!parent);
		} else {

			parent = scene_root;
			ERR_FAIL_COND(!parent);

		}

		Object *c = create_dialog->instance_selected();

		ERR_FAIL_COND(!c);
		Node *child=c->cast_to<Node>();
		ERR_FAIL_COND(!child);

		editor_data->get_undo_redo().create_action("Create Node");

		if (edited_scene) {
			editor_data->get_undo_redo().add_do_method(parent,"add_child",child);
			editor_data->get_undo_redo().add_do_method(child,"set_owner",edited_scene);
			editor_data->get_undo_redo().add_do_method(editor_selection,"clear");
			editor_data->get_undo_redo().add_do_method(editor_selection,"add_node",child);
			editor_data->get_undo_redo().add_do_reference(child);
			editor_data->get_undo_redo().add_undo_method(parent,"remove_child",child);
		} else {

			editor_data->get_undo_redo().add_do_method(editor,"set_edited_scene",child);
			editor_data->get_undo_redo().add_do_reference(child);
			editor_data->get_undo_redo().add_undo_method(editor,"set_edited_scene",(Object*)NULL);

		}

		editor_data->get_undo_redo().commit_action();
		editor->push_item(c);

		if (c->cast_to<Control>()) {
			//make editor more comfortable, so some controls don't appear super shrunk
			Control *ct = c->cast_to<Control>();

			Size2 ms = ct->get_minimum_size();
			if (ms.width<4)
				ms.width=40;
			if (ms.height<4)
				ms.height=40;
			ct->set_size(ms);
		}


	} else if (current_option==TOOL_REPLACE) {
		Node * n = scene_tree->get_selected();
		ERR_FAIL_COND(!n);

		Object *c = create_dialog->instance_selected();

		ERR_FAIL_COND(!c);
		Node *newnode=c->cast_to<Node>();
		ERR_FAIL_COND(!newnode);

		List<PropertyInfo> pinfo;
		n->get_property_list(&pinfo);

		for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
			if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
				continue;
			newnode->set(E->get().name,n->get(E->get().name));
		}

		editor->push_item(NULL);

		//reconnect signals
		List<MethodInfo> sl;

		n->get_signal_list(&sl);
		for (List<MethodInfo>::Element *E=sl.front();E;E=E->next()) {

			List<Object::Connection> cl;
			n->get_signal_connection_list(E->get().name,&cl);

			for(List<Object::Connection>::Element *F=cl.front();F;F=F->next()) {

				Object::Connection &c=F->get();
				if (!(c.flags&Object::CONNECT_PERSIST))
					continue;
				newnode->connect(c.signal,c.target,c.method,varray(),Object::CONNECT_PERSIST);
			}

		}


		String newname=n->get_name();
		n->replace_by(newnode,true);


		if (n==edited_scene) {
			edited_scene=newnode;
			editor->set_edited_scene(newnode);
		}




		editor_data->get_undo_redo().clear_history();
		memdelete(n);
		newnode->set_name(newname);
		editor->push_item(newnode);

		_update_tool_buttons();

	}

}
Esempio n. 2
0
void SceneTreeDock::_delete_confirm() {

	List<Node*> remove_list = editor_selection->get_selected_node_list();

	if (remove_list.empty())
		return;


	if (editor->get_editor_plugin_over())
		editor->get_editor_plugin_over()->make_visible(false);

	editor_data->get_undo_redo().create_action("Remove Node(s)");

	bool entire_scene=false;

	for(List<Node*>::Element *E=remove_list.front();E;E=E->next()) {

		if (E->get()==edited_scene) {
			entire_scene=true;
		}
	}

	if (entire_scene) {

		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_reference(edited_scene);

	} else {

		remove_list.sort_custom<Node::Comparator>(); //sort nodes to keep positions
		List<Pair<NodePath,NodePath> > path_renames;


		//delete from animation
		for(List<Node*>::Element *E=remove_list.front();E;E=E->next()) {
			Node *n = E->get();
			if (!n->is_inside_scene() || !n->get_parent())
				continue;

			fill_path_renames(n,NULL,&path_renames);

		}

		perform_node_renames(NULL,&path_renames);
		//delete for read
		for(List<Node*>::Element *E=remove_list.front();E;E=E->next()) {
			Node *n = E->get();
			if (!n->is_inside_scene() || !n->get_parent())
				continue;

			List<Node*> owned;
			n->get_owned_by(n->get_owner(),&owned);
			Array owners;
			for(List<Node*>::Element *E=owned.front();E;E=E->next()) {

				owners.push_back(E->get());
			}


			editor_data->get_undo_redo().add_do_method(n->get_parent(),"remove_child",n);
			editor_data->get_undo_redo().add_undo_method(n->get_parent(),"add_child",n);
			editor_data->get_undo_redo().add_undo_method(n->get_parent(),"move_child",n,n->get_index());
			if (editor->get_animation_editor()->get_root()==n)
				editor_data->get_undo_redo().add_undo_method(editor->get_animation_editor(),"set_root",n);
			editor_data->get_undo_redo().add_undo_method(this,"_set_owners",edited_scene,owners);
			//editor_data->get_undo_redo().add_undo_method(n,"set_owner",n->get_owner());
			editor_data->get_undo_redo().add_undo_reference(n);
		}


	}
	editor_data->get_undo_redo().commit_action();
	_update_tool_buttons();

}
Esempio n. 3
0
void SceneTreeDock::set_selected(Node *p_node) {

	scene_tree->set_selected(p_node,false);
	_update_tool_buttons();
}
Esempio n. 4
0
void SceneTreeDock::set_selected(Node *p_node, bool p_emit_selected ) {

	scene_tree->set_selected(p_node,p_emit_selected);
	_update_tool_buttons();
}
Esempio n. 5
0
void SceneTreeDock::_create() {


	if (current_option==TOOL_NEW) {

		Node *parent=NULL;


		if (edited_scene) {
			// If root exists in edited scene
			parent = scene_tree->get_selected();
			if( !parent )
				parent = edited_scene;

		} else {
			// If no root exist in edited scene
			parent = scene_root;
			ERR_FAIL_COND(!parent);
		}

		Object *c = create_dialog->instance_selected();

		ERR_FAIL_COND(!c);
		Node *child=c->cast_to<Node>();
		ERR_FAIL_COND(!child);

		editor_data->get_undo_redo().create_action("Create Node");

		if (edited_scene) {

			editor_data->get_undo_redo().add_do_method(parent,"add_child",child);
			editor_data->get_undo_redo().add_do_method(child,"set_owner",edited_scene);
			editor_data->get_undo_redo().add_do_method(editor_selection,"clear");
			editor_data->get_undo_redo().add_do_method(editor_selection,"add_node",child);
			editor_data->get_undo_redo().add_do_reference(child);
			editor_data->get_undo_redo().add_undo_method(parent,"remove_child",child);


			String new_name = parent->validate_child_name(child->get_type());
			ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
			editor_data->get_undo_redo().add_do_method(sed,"live_debug_create_node",edited_scene->get_path_to(parent),child->get_type(),new_name);
			editor_data->get_undo_redo().add_undo_method(sed,"live_debug_remove_node",NodePath(String(edited_scene->get_path_to(parent))+"/"+new_name));

		} else {

			editor_data->get_undo_redo().add_do_method(editor,"set_edited_scene",child);
			editor_data->get_undo_redo().add_do_reference(child);
			editor_data->get_undo_redo().add_undo_method(editor,"set_edited_scene",(Object*)NULL);

		}

		editor_data->get_undo_redo().commit_action();
		editor->push_item(c);

		if (c->cast_to<Control>()) {
			//make editor more comfortable, so some controls don't appear super shrunk
			Control *ct = c->cast_to<Control>();

			Size2 ms = ct->get_minimum_size();
			if (ms.width<4)
				ms.width=40;
			if (ms.height<4)
				ms.height=40;
			ct->set_size(ms);
		}


	} else if (current_option==TOOL_REPLACE) {
		Node * n = scene_tree->get_selected();
		ERR_FAIL_COND(!n);

		Object *c = create_dialog->instance_selected();

		ERR_FAIL_COND(!c);
		Node *newnode=c->cast_to<Node>();
		ERR_FAIL_COND(!newnode);

		List<PropertyInfo> pinfo;
		n->get_property_list(&pinfo);

		for(List<PropertyInfo>::Element *E=pinfo.front();E;E=E->next()) {
			if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
				continue;
			newnode->set(E->get().name,n->get(E->get().name));
		}

		editor->push_item(NULL);

		//reconnect signals
		List<MethodInfo> sl;

		n->get_signal_list(&sl);
		for (List<MethodInfo>::Element *E=sl.front();E;E=E->next()) {

			List<Object::Connection> cl;
			n->get_signal_connection_list(E->get().name,&cl);

			for(List<Object::Connection>::Element *F=cl.front();F;F=F->next()) {

				Object::Connection &c=F->get();
				if (!(c.flags&Object::CONNECT_PERSIST))
					continue;
				newnode->connect(c.signal,c.target,c.method,varray(),Object::CONNECT_PERSIST);
			}

		}

		String newname=n->get_name();
		n->replace_by(newnode,true);

		if (n==edited_scene) {
			edited_scene=newnode;
			editor->set_edited_scene(newnode);
		}

		//small hack to make collisionshapes and other kind of nodes to work
		for(int i=0;i<newnode->get_child_count();i++) {
			Node *c=newnode->get_child(i);
			c->call("set_transform", c->call("get_transform") );
		}
		editor_data->get_undo_redo().clear_history();
		newnode->set_name(newname);

		editor->push_item(newnode);

		memdelete(n);

		_update_tool_buttons();

	}

}