2014-02-10 09:10:30 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* scene_tree_dock.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2016-01-01 21:50:53 +08:00
|
|
|
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
2014-02-10 09:10:30 +08:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#include "scene_tree_dock.h"
|
|
|
|
#include "editor_node.h"
|
|
|
|
#include "globals.h"
|
|
|
|
#include "os/keyboard.h"
|
|
|
|
#include "scene/resources/packed_scene.h"
|
|
|
|
#include "editor_settings.h"
|
2014-05-08 13:43:19 +08:00
|
|
|
#include "tools/editor/plugins/canvas_item_editor_plugin.h"
|
2015-08-02 23:29:37 +08:00
|
|
|
#include "script_editor_debugger.h"
|
|
|
|
#include "tools/editor/plugins/script_editor_plugin.h"
|
2015-11-28 04:42:48 +08:00
|
|
|
#include "core/io/resource_saver.h"
|
2015-08-25 11:08:45 +08:00
|
|
|
#include "multi_node_edit.h"
|
2016-01-18 07:03:57 +08:00
|
|
|
#include "tools/editor/plugins/animation_player_editor_plugin.h"
|
|
|
|
#include "animation_editor.h"
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2016-05-11 22:46:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-10 20:09:09 +08:00
|
|
|
void SceneTreeDock::_unhandled_key_input(InputEvent p_event) {
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
uint32_t sc = p_event.key.get_scancode_with_modifiers();
|
|
|
|
if (!p_event.key.pressed || p_event.key.echo)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch(sc) {
|
|
|
|
case KEY_MASK_CMD|KEY_A: { _tool_selected(TOOL_NEW); } break;
|
|
|
|
case KEY_MASK_CMD|KEY_D: { _tool_selected(TOOL_DUPLICATE); } break;
|
|
|
|
case KEY_MASK_CMD|KEY_UP: { _tool_selected(TOOL_MOVE_UP); } break;
|
|
|
|
case KEY_MASK_CMD|KEY_DOWN: { _tool_selected(TOOL_MOVE_DOWN); } break;
|
2014-05-09 18:50:48 +08:00
|
|
|
case KEY_MASK_SHIFT|KEY_DELETE: { _tool_selected(TOOL_ERASE, true); } break;
|
2014-02-10 09:10:30 +08:00
|
|
|
case KEY_DELETE: { _tool_selected(TOOL_ERASE); } break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-12 07:57:52 +08:00
|
|
|
void SceneTreeDock::instance(const String& p_file) {
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
Node *parent = scene_tree->get_selected();
|
|
|
|
if (!parent || !edited_scene) {
|
|
|
|
|
|
|
|
current_option=-1;
|
|
|
|
//accept->get_cancel()->hide();
|
2016-05-04 09:25:37 +08:00
|
|
|
accept->get_ok()->set_text(TTR("Ok :( "));
|
|
|
|
accept->set_text(TTR("No parent to instance a child at."));
|
2015-04-09 01:02:13 +08:00
|
|
|
accept->popup_centered_minsize();
|
2016-05-12 07:57:52 +08:00
|
|
|
return;
|
2014-02-10 09:10:30 +08:00
|
|
|
};
|
|
|
|
|
2016-05-12 07:57:52 +08:00
|
|
|
ERR_FAIL_COND(!parent);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2016-05-12 07:57:52 +08:00
|
|
|
Vector<String> scenes;
|
|
|
|
scenes.push_back(p_file);
|
|
|
|
instance_scenes(scenes,parent,-1);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2016-05-12 07:57:52 +08:00
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2016-05-12 07:57:52 +08:00
|
|
|
void SceneTreeDock::instance_scenes(const Vector<String>& p_files,Node* parent,int p_pos) {
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2015-01-20 04:47:50 +08:00
|
|
|
|
|
|
|
|
2016-05-12 07:57:52 +08:00
|
|
|
ERR_FAIL_COND(!parent);
|
2015-01-20 22:05:22 +08:00
|
|
|
|
2016-05-12 07:57:52 +08:00
|
|
|
|
|
|
|
Vector<Node*> instances;
|
|
|
|
|
|
|
|
bool error=false;
|
|
|
|
|
|
|
|
for(int i=0;i<p_files.size();i++) {
|
|
|
|
|
|
|
|
Ref<PackedScene> sdata = ResourceLoader::load(p_files[i]);
|
|
|
|
if (!sdata.is_valid()) {
|
|
|
|
current_option=-1;
|
|
|
|
//accept->get_cancel()->hide();
|
|
|
|
accept->get_ok()->set_text(TTR("Ugh"));
|
|
|
|
accept->set_text(String(TTR("Error loading scene from "))+p_files[i]);
|
2015-04-09 01:02:13 +08:00
|
|
|
accept->popup_centered_minsize();
|
2016-05-12 07:57:52 +08:00
|
|
|
error=true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Node*instanced_scene=sdata->instance(true);
|
|
|
|
if (!instanced_scene) {
|
|
|
|
current_option=-1;
|
|
|
|
//accept->get_cancel()->hide();
|
|
|
|
accept->get_ok()->set_text(TTR("Ugh"));
|
|
|
|
accept->set_text(String(TTR("Error instancing scene from "))+p_files[i]);
|
|
|
|
accept->popup_centered_minsize();
|
|
|
|
error=true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (edited_scene->get_filename()!="") {
|
|
|
|
|
|
|
|
if (_cyclical_dependency_exists(edited_scene->get_filename(), instanced_scene)) {
|
|
|
|
|
|
|
|
accept->get_ok()->set_text(TTR("Ok"));
|
|
|
|
accept->set_text(String(TTR("Cannot instance the scene '"))+p_files[i]+String(TTR("' because the current scene exists within one of its' nodes.")));
|
|
|
|
accept->popup_centered_minsize();
|
|
|
|
error=true;
|
|
|
|
break;
|
|
|
|
}
|
2015-01-20 22:05:22 +08:00
|
|
|
}
|
2016-05-12 07:57:52 +08:00
|
|
|
|
|
|
|
instanced_scene->set_filename( Globals::get_singleton()->localize_path(p_files[i]) );
|
|
|
|
|
|
|
|
instances.push_back(instanced_scene);
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
2016-05-12 07:57:52 +08:00
|
|
|
if (error) {
|
|
|
|
for(int i=0;i<instances.size();i++) {
|
|
|
|
memdelete(instances[i]);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-10-10 20:09:09 +08:00
|
|
|
//instanced_scene->generate_instance_state();
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2016-05-12 07:57:52 +08:00
|
|
|
editor_data->get_undo_redo().create_action(TTR("Instance Scene(s)"));
|
2015-08-02 23:29:37 +08:00
|
|
|
|
2016-05-12 07:57:52 +08:00
|
|
|
for(int i=0;i<instances.size();i++) {
|
2015-08-02 23:29:37 +08:00
|
|
|
|
2016-05-12 07:57:52 +08:00
|
|
|
Node* instanced_scene=instances[i];
|
2015-08-02 23:29:37 +08:00
|
|
|
|
2016-05-12 07:57:52 +08:00
|
|
|
editor_data->get_undo_redo().add_do_method(parent,"add_child",instanced_scene);
|
|
|
|
if (p_pos>=0) {
|
|
|
|
editor_data->get_undo_redo().add_do_method(parent,"move_child",instanced_scene,p_pos+i);
|
|
|
|
}
|
|
|
|
editor_data->get_undo_redo().add_do_method(instanced_scene,"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",instanced_scene);
|
|
|
|
editor_data->get_undo_redo().add_do_reference(instanced_scene);
|
|
|
|
editor_data->get_undo_redo().add_undo_method(parent,"remove_child",instanced_scene);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2016-05-12 07:57:52 +08:00
|
|
|
String new_name = parent->validate_child_name(instanced_scene->get_name());
|
|
|
|
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
|
|
|
|
editor_data->get_undo_redo().add_do_method(sed,"live_debug_instance_node",edited_scene->get_path_to(parent),p_files[i],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));
|
|
|
|
}
|
|
|
|
|
|
|
|
editor_data->get_undo_redo().commit_action();
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-20 04:47:50 +08:00
|
|
|
bool SceneTreeDock::_cyclical_dependency_exists(const String& p_target_scene_path, Node* p_desired_node) {
|
|
|
|
int childCount = p_desired_node->get_child_count();
|
|
|
|
|
|
|
|
if (p_desired_node->get_filename()==p_target_scene_path) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=0;i<childCount;i++) {
|
|
|
|
Node* child=p_desired_node->get_child(i);
|
|
|
|
|
|
|
|
if(_cyclical_dependency_exists(p_target_scene_path,child)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-11 13:08:32 +08:00
|
|
|
static String _get_name_num_separator() {
|
|
|
|
switch(EditorSettings::get_singleton()->get("scenetree_editor/duplicate_node_name_num_separator").operator int()) {
|
|
|
|
case 0: return "";
|
|
|
|
case 1: return " ";
|
|
|
|
case 2: return "_";
|
|
|
|
case 3: return "-";
|
|
|
|
}
|
|
|
|
return " ";
|
|
|
|
}
|
|
|
|
|
2014-05-09 18:50:48 +08:00
|
|
|
void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
current_option=p_tool;
|
|
|
|
|
|
|
|
switch(p_tool) {
|
|
|
|
|
|
|
|
case TOOL_NEW: {
|
|
|
|
|
2014-09-03 10:13:40 +08:00
|
|
|
|
2015-10-10 20:09:09 +08:00
|
|
|
//if (!_validate_no_foreign())
|
|
|
|
// break;
|
2014-02-10 09:10:30 +08:00
|
|
|
create_dialog->popup_centered_ratio();
|
|
|
|
} break;
|
|
|
|
case TOOL_INSTANCE: {
|
|
|
|
|
|
|
|
Node *scene = edited_scene;
|
|
|
|
|
|
|
|
if (!scene) {
|
|
|
|
|
|
|
|
current_option=-1;
|
|
|
|
//confirmation->get_cancel()->hide();
|
2016-05-04 09:25:37 +08:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
2014-02-10 09:10:30 +08:00
|
|
|
accept->set_text("This operation can't be done without a tree root.");
|
2015-04-09 01:02:13 +08:00
|
|
|
accept->popup_centered_minsize();
|
2014-02-10 09:10:30 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-10-10 20:09:09 +08:00
|
|
|
//if (!_validate_no_foreign())
|
|
|
|
// break;
|
2014-09-03 10:13:40 +08:00
|
|
|
|
2015-06-06 20:44:38 +08:00
|
|
|
file->set_mode(EditorFileDialog::MODE_OPEN_FILE);
|
2014-02-10 09:10:30 +08:00
|
|
|
List<String> extensions;
|
|
|
|
ResourceLoader::get_recognized_extensions_for_type("PackedScene",&extensions);
|
|
|
|
file->clear_filters();
|
|
|
|
for(int i=0;i<extensions.size();i++) {
|
|
|
|
|
|
|
|
file->add_filter("*."+extensions[i]+" ; "+extensions[i].to_upper());
|
|
|
|
}
|
|
|
|
|
|
|
|
//file->set_current_path(current_path);
|
|
|
|
file->popup_centered_ratio();
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case TOOL_REPLACE: {
|
|
|
|
|
|
|
|
create_dialog->popup_centered_ratio();
|
|
|
|
} break;
|
|
|
|
case TOOL_CONNECT: {
|
|
|
|
|
|
|
|
Node *current = scene_tree->get_selected();
|
|
|
|
if (!current)
|
|
|
|
break;
|
|
|
|
|
2015-10-10 20:09:09 +08:00
|
|
|
//if (!_validate_no_foreign())
|
|
|
|
// break;
|
2014-02-10 09:10:30 +08:00
|
|
|
connect_dialog->popup_centered_ratio();
|
|
|
|
connect_dialog->set_node(current);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case TOOL_GROUP: {
|
|
|
|
|
|
|
|
Node *current = scene_tree->get_selected();
|
|
|
|
if (!current)
|
|
|
|
break;
|
2015-10-10 20:09:09 +08:00
|
|
|
//if (!_validate_no_foreign())
|
|
|
|
// break;
|
2014-02-10 09:10:30 +08:00
|
|
|
groups_editor->set_current(current);
|
|
|
|
groups_editor->popup_centered_ratio();
|
|
|
|
} break;
|
|
|
|
case TOOL_SCRIPT: {
|
|
|
|
|
|
|
|
Node *selected = scene_tree->get_selected();
|
|
|
|
if (!selected)
|
|
|
|
break;
|
|
|
|
|
2015-10-10 20:09:09 +08:00
|
|
|
//if (!_validate_no_foreign())
|
|
|
|
// break;
|
2014-09-03 10:13:40 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
Ref<Script> existing = selected->get_script();
|
|
|
|
if (existing.is_valid())
|
|
|
|
editor->push_item(existing.ptr());
|
|
|
|
else {
|
|
|
|
String path = selected->get_filename();
|
|
|
|
script_create_dialog->config(selected->get_type(),path);
|
|
|
|
script_create_dialog->popup_centered(Size2(300,290));
|
|
|
|
//script_create_dialog->popup_centered_minsize();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case TOOL_MOVE_UP:
|
|
|
|
case TOOL_MOVE_DOWN: {
|
|
|
|
|
|
|
|
if (!scene_tree->get_selected())
|
|
|
|
break;
|
|
|
|
|
2014-09-03 10:13:40 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
if (scene_tree->get_selected()==edited_scene) {
|
|
|
|
|
|
|
|
|
|
|
|
current_option=-1;
|
|
|
|
//accept->get_cancel()->hide();
|
2016-05-04 09:25:37 +08:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
2014-02-10 09:10:30 +08:00
|
|
|
accept->set_text("This operation can't be done on the tree root.");
|
2015-04-09 01:02:13 +08:00
|
|
|
accept->popup_centered_minsize();
|
2014-02-10 09:10:30 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-03 10:13:40 +08:00
|
|
|
if (!_validate_no_foreign())
|
|
|
|
break;
|
|
|
|
|
2014-12-18 10:38:24 +08:00
|
|
|
bool MOVING_DOWN = (p_tool == TOOL_MOVE_DOWN);
|
|
|
|
bool MOVING_UP = !MOVING_DOWN;
|
|
|
|
|
2014-12-18 12:46:03 +08:00
|
|
|
Node *common_parent = scene_tree->get_selected()->get_parent();
|
2014-12-18 10:38:24 +08:00
|
|
|
List<Node*> selection = editor_selection->get_selected_node_list();
|
|
|
|
selection.sort_custom<Node::Comparator>(); // sort by index
|
|
|
|
if (MOVING_DOWN)
|
|
|
|
selection.invert();
|
|
|
|
|
2014-12-18 12:46:03 +08:00
|
|
|
int lowest_id = common_parent->get_child_count() - 1;
|
|
|
|
int highest_id = 0;
|
2014-12-18 10:38:24 +08:00
|
|
|
for (List<Node*>::Element *E = selection.front(); E; E = E->next()) {
|
|
|
|
int index = E->get()->get_index();
|
|
|
|
|
2014-12-18 12:46:03 +08:00
|
|
|
if (index > highest_id) highest_id = index;
|
|
|
|
if (index < lowest_id) lowest_id = index;
|
|
|
|
|
|
|
|
if (E->get()->get_parent() != common_parent)
|
|
|
|
common_parent = NULL;
|
2014-12-18 10:38:24 +08:00
|
|
|
}
|
|
|
|
|
2014-12-18 12:46:03 +08:00
|
|
|
if (!common_parent || (MOVING_DOWN && highest_id >= common_parent->get_child_count() - MOVING_DOWN) || (MOVING_UP && lowest_id == 0))
|
|
|
|
break; // one or more nodes can not be moved
|
2014-12-18 10:38:24 +08:00
|
|
|
|
2016-05-04 09:25:37 +08:00
|
|
|
if (selection.size() == 1) editor_data->get_undo_redo().create_action(TTR("Move Node In Parent"));
|
|
|
|
if (selection.size() > 1) editor_data->get_undo_redo().create_action(TTR("Move Nodes In Parent"));
|
2014-12-18 12:52:27 +08:00
|
|
|
|
2014-12-18 10:38:24 +08:00
|
|
|
for (int i = 0; i < selection.size(); i++) {
|
|
|
|
Node *top_node = selection[i];
|
|
|
|
Node *bottom_node = selection[selection.size() - 1 - i];
|
2016-01-18 07:03:57 +08:00
|
|
|
|
2014-12-18 10:38:24 +08:00
|
|
|
ERR_FAIL_COND(!top_node->get_parent());
|
|
|
|
ERR_FAIL_COND(!bottom_node->get_parent());
|
|
|
|
|
|
|
|
int top_node_pos = top_node->get_index();
|
|
|
|
int bottom_node_pos = bottom_node->get_index();
|
|
|
|
|
|
|
|
int top_node_pos_next = top_node_pos + (MOVING_DOWN ? 1 : -1);
|
|
|
|
int bottom_node_pos_next = bottom_node_pos + (MOVING_DOWN ? 1 : -1);
|
|
|
|
|
|
|
|
editor_data->get_undo_redo().add_do_method(top_node->get_parent(), "move_child", top_node, top_node_pos_next);
|
|
|
|
editor_data->get_undo_redo().add_undo_method(bottom_node->get_parent(), "move_child", bottom_node, bottom_node_pos);
|
|
|
|
}
|
|
|
|
|
2014-12-18 12:52:27 +08:00
|
|
|
editor_data->get_undo_redo().commit_action();
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case TOOL_DUPLICATE: {
|
|
|
|
|
|
|
|
if (!edited_scene)
|
|
|
|
break;
|
|
|
|
|
2014-09-03 10:13:40 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
if (editor_selection->is_selected(edited_scene)) {
|
|
|
|
|
|
|
|
|
|
|
|
current_option=-1;
|
|
|
|
//accept->get_cancel()->hide();
|
2016-05-04 09:25:37 +08:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
2014-02-10 09:10:30 +08:00
|
|
|
accept->set_text("This operation can't be done on the tree root.");
|
2015-04-09 01:02:13 +08:00
|
|
|
accept->popup_centered_minsize();
|
2014-02-10 09:10:30 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-09-03 10:13:40 +08:00
|
|
|
if (!_validate_no_foreign())
|
|
|
|
break;
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
List<Node*> selection = editor_selection->get_selected_node_list();
|
|
|
|
|
|
|
|
List<Node*> reselect;
|
|
|
|
|
2016-05-04 09:25:37 +08:00
|
|
|
editor_data->get_undo_redo().create_action(TTR("Duplicate Node(s)"));
|
2014-02-10 09:10:30 +08:00
|
|
|
editor_data->get_undo_redo().add_do_method(editor_selection,"clear");
|
|
|
|
|
|
|
|
Node *dupsingle=NULL;
|
|
|
|
|
|
|
|
|
|
|
|
for (List<Node*>::Element *E=selection.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
Node *node = E->get();
|
|
|
|
Node *parent = node->get_parent();
|
|
|
|
|
|
|
|
List<Node*> owned;
|
|
|
|
node->get_owned_by(node->get_owner(),&owned);
|
|
|
|
|
|
|
|
Map<Node*,Node*> duplimap;
|
|
|
|
Node * dup = _duplicate(node,duplimap);
|
|
|
|
|
|
|
|
ERR_CONTINUE(!dup);
|
|
|
|
|
|
|
|
if (selection.size()==1)
|
|
|
|
dupsingle=dup;
|
|
|
|
|
|
|
|
String name = node->get_name();
|
|
|
|
|
|
|
|
String nums;
|
|
|
|
for(int i=name.length()-1;i>=0;i--) {
|
|
|
|
CharType n=name[i];
|
|
|
|
if (n>='0' && n<='9') {
|
|
|
|
nums=String::chr(name[i])+nums;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int num=nums.to_int();
|
2015-01-11 13:08:32 +08:00
|
|
|
if (num<1)
|
|
|
|
num=1;
|
2014-02-10 09:10:30 +08:00
|
|
|
else
|
|
|
|
num++;
|
|
|
|
|
2015-01-11 13:08:32 +08:00
|
|
|
String nnsep = _get_name_num_separator();
|
|
|
|
name = name.substr(0,name.length()-nums.length()).strip_edges();
|
|
|
|
if ( name.substr(name.length()-nnsep.length(),nnsep.length()) == nnsep) {
|
|
|
|
name = name.substr(0,name.length()-nnsep.length());
|
|
|
|
}
|
|
|
|
String attempt = (name + nnsep + itos(num)).strip_edges();
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
while(parent->has_node(attempt)) {
|
|
|
|
num++;
|
2015-01-11 13:08:32 +08:00
|
|
|
attempt = (name + nnsep + itos(num)).strip_edges();
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dup->set_name(attempt);
|
|
|
|
|
|
|
|
editor_data->get_undo_redo().add_do_method(parent,"add_child",dup);
|
|
|
|
for (List<Node*>::Element *F=owned.front();F;F=F->next()) {
|
|
|
|
|
|
|
|
if (!duplimap.has(F->get())) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
Node *d=duplimap[F->get()];
|
|
|
|
editor_data->get_undo_redo().add_do_method(d,"set_owner",node->get_owner());
|
|
|
|
}
|
|
|
|
editor_data->get_undo_redo().add_do_method(editor_selection,"add_node",dup);
|
2016-01-18 07:03:57 +08:00
|
|
|
editor_data->get_undo_redo().add_undo_method(parent,"remove_child",dup);
|
2014-02-10 09:10:30 +08:00
|
|
|
editor_data->get_undo_redo().add_do_reference(dup);
|
|
|
|
|
2015-08-02 23:29:37 +08:00
|
|
|
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
|
|
|
|
|
2015-08-03 07:28:10 +08:00
|
|
|
editor_data->get_undo_redo().add_do_method(sed,"live_debug_duplicate_node",edited_scene->get_path_to(node),attempt);
|
2015-08-02 23:29:37 +08:00
|
|
|
editor_data->get_undo_redo().add_undo_method(sed,"live_debug_remove_node",NodePath(String(edited_scene->get_path_to(parent))+"/"+attempt));
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
//parent->add_child(dup);
|
|
|
|
//reselect.push_back(dup);
|
|
|
|
}
|
|
|
|
|
|
|
|
editor_data->get_undo_redo().commit_action();
|
|
|
|
|
|
|
|
if (dupsingle)
|
|
|
|
editor->push_item(dupsingle);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case TOOL_REPARENT: {
|
|
|
|
|
|
|
|
|
|
|
|
if (!scene_tree->get_selected())
|
|
|
|
break;
|
|
|
|
|
2014-09-03 10:13:40 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
if (editor_selection->is_selected(edited_scene)) {
|
|
|
|
|
|
|
|
|
|
|
|
current_option=-1;
|
|
|
|
//confirmation->get_cancel()->hide();
|
2016-05-04 09:25:37 +08:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
2014-02-10 09:10:30 +08:00
|
|
|
accept->set_text("This operation can't be done on the tree root.");
|
2015-04-09 01:02:13 +08:00
|
|
|
accept->popup_centered_minsize();
|
2014-02-10 09:10:30 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-09-03 10:13:40 +08:00
|
|
|
if (!_validate_no_foreign())
|
|
|
|
break;
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
List<Node*> nodes = editor_selection->get_selected_node_list();
|
|
|
|
Set<Node*> nodeset;
|
|
|
|
for(List<Node*>::Element *E=nodes.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
nodeset.insert(E->get());
|
|
|
|
}
|
|
|
|
reparent_dialog->popup_centered_ratio();
|
|
|
|
reparent_dialog->set_current( nodeset );
|
|
|
|
|
2015-08-25 11:08:45 +08:00
|
|
|
} break;
|
|
|
|
case TOOL_MULTI_EDIT: {
|
|
|
|
|
|
|
|
Node*root=EditorNode::get_singleton()->get_edited_scene();
|
|
|
|
if (!root)
|
|
|
|
break;
|
|
|
|
Ref<MultiNodeEdit> mne = memnew( MultiNodeEdit );
|
|
|
|
for (const Map<Node*,Object*>::Element *E=EditorNode::get_singleton()->get_editor_selection()->get_selection().front();E;E=E->next()) {
|
|
|
|
mne->add_node(root->get_path_to(E->key()));
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorNode::get_singleton()->push_item(mne.ptr());
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
} break;
|
|
|
|
case TOOL_ERASE: {
|
|
|
|
|
|
|
|
List<Node*> remove_list = editor_selection->get_selected_node_list();
|
|
|
|
|
|
|
|
if (remove_list.empty())
|
|
|
|
return;
|
|
|
|
|
2014-09-03 10:13:40 +08:00
|
|
|
if (!_validate_no_foreign())
|
|
|
|
break;
|
|
|
|
|
2014-05-09 18:50:48 +08:00
|
|
|
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 {
|
2016-05-04 09:25:37 +08:00
|
|
|
delete_dialog->set_text(TTR("Delete Node(s)?"));
|
2015-04-09 01:02:13 +08:00
|
|
|
delete_dialog->popup_centered_minsize();
|
2014-05-09 18:50:48 +08:00
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2015-11-28 04:42:48 +08:00
|
|
|
} break;
|
|
|
|
case TOOL_NEW_SCENE_FROM: {
|
|
|
|
|
|
|
|
Node *scene = editor_data->get_edited_scene_root();
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2015-11-28 04:42:48 +08:00
|
|
|
if (!scene) {
|
2016-05-04 09:25:37 +08:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
2015-11-28 04:42:48 +08:00
|
|
|
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) {
|
2016-05-04 09:25:37 +08:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
|
|
|
accept->set_text(TTR("This operation requires a single selected node."));
|
2015-11-28 04:42:48 +08:00
|
|
|
accept->popup_centered_minsize();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node *tocopy = selection.front()->get();
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2015-11-28 04:42:48 +08:00
|
|
|
if (tocopy!=editor_data->get_edited_scene_root() && tocopy->get_filename()!="") {
|
2016-05-04 09:25:37 +08:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
2015-11-28 04:42:48 +08:00
|
|
|
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();
|
2016-05-04 09:25:37 +08:00
|
|
|
new_scene_from_dialog->set_title(TTR("Save New Scene As.."));
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTreeDock::_notification(int p_what) {
|
|
|
|
|
|
|
|
switch(p_what) {
|
|
|
|
|
2015-06-14 13:13:47 +08:00
|
|
|
case NOTIFICATION_READY: {
|
|
|
|
|
|
|
|
if (!first_enter)
|
|
|
|
break;
|
|
|
|
first_enter=false;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2015-06-14 13:13:47 +08:00
|
|
|
CanvasItemEditorPlugin *canvas_item_plugin = editor_data->get_editor("2D")->cast_to<CanvasItemEditorPlugin>();
|
|
|
|
if (canvas_item_plugin) {
|
|
|
|
canvas_item_plugin->get_canvas_item_editor()->connect("item_lock_status_changed", scene_tree, "_update_tree");
|
|
|
|
canvas_item_plugin->get_canvas_item_editor()->connect("item_group_status_changed", scene_tree, "_update_tree");
|
|
|
|
scene_tree->connect("node_changed", canvas_item_plugin->get_canvas_item_editor()->get_viewport_control(), "update");
|
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
static const char* button_names[TOOL_BUTTON_MAX]={
|
|
|
|
"New",
|
|
|
|
"Add",
|
|
|
|
"Replace",
|
|
|
|
"Connect",
|
|
|
|
"Groups",
|
|
|
|
"Script",
|
|
|
|
"MoveUp",
|
|
|
|
"MoveDown",
|
|
|
|
"Duplicate",
|
|
|
|
"Reparent",
|
2015-11-28 04:42:48 +08:00
|
|
|
"CreateNewSceneFrom",
|
2015-08-25 11:08:45 +08:00
|
|
|
"MultiNodeEdit",
|
2015-06-06 20:44:38 +08:00
|
|
|
"Remove",
|
2014-02-10 09:10:30 +08:00
|
|
|
};
|
|
|
|
|
2015-06-14 13:13:47 +08:00
|
|
|
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
for(int i=0;i<TOOL_BUTTON_MAX;i++)
|
|
|
|
tool_buttons[i]->set_icon(get_icon(button_names[i],"EditorIcons"));
|
|
|
|
|
2015-08-25 11:08:45 +08:00
|
|
|
EditorNode::get_singleton()->get_editor_selection()->connect("selection_changed",this,"_selection_changed");
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SceneTreeDock::_load_request(const String& p_path) {
|
|
|
|
|
|
|
|
editor->open_request(p_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTreeDock::_script_open_request(const Ref<Script>& p_script) {
|
|
|
|
|
|
|
|
editor->edit_resource(p_script);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTreeDock::_node_selected() {
|
|
|
|
|
|
|
|
|
|
|
|
Node *node=scene_tree->get_selected();
|
|
|
|
|
|
|
|
if (!node) {
|
|
|
|
|
|
|
|
editor->push_item(NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
editor->push_item(node);
|
|
|
|
}
|
|
|
|
|
2014-09-21 23:56:19 +08:00
|
|
|
void SceneTreeDock::_node_renamed() {
|
|
|
|
|
|
|
|
_node_selected();
|
|
|
|
}
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
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);
|
2015-10-10 20:09:09 +08:00
|
|
|
node = sd->instance(true);
|
2014-02-10 09:10:30 +08:00
|
|
|
ERR_FAIL_COND_V(!node,NULL);
|
2015-10-10 20:09:09 +08:00
|
|
|
//node->generate_instance_state();
|
2014-02-10 09:10:30 +08:00
|
|
|
} else {
|
|
|
|
Object *obj = ObjectTypeDB::instance(p_node->get_type());
|
|
|
|
ERR_FAIL_COND_V(!obj,NULL);
|
|
|
|
node = obj->cast_to<Node>();
|
|
|
|
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;
|
|
|
|
node->set( name, p_node->get(name) );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-09-21 12:43:42 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
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++) {
|
|
|
|
|
|
|
|
Object *obj=p_nodes[i];
|
|
|
|
if (!obj)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Node *n=obj->cast_to<Node>();
|
|
|
|
if (!n)
|
|
|
|
continue;
|
|
|
|
n->set_owner(p_owner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SceneTreeDock::_fill_path_renames(Vector<StringName> base_path,Vector<StringName> new_base_path,Node * p_node, List<Pair<NodePath,NodePath> > *p_renames) {
|
|
|
|
|
|
|
|
base_path.push_back(p_node->get_name());
|
|
|
|
if (new_base_path.size())
|
|
|
|
new_base_path.push_back(p_node->get_name());
|
|
|
|
|
|
|
|
NodePath from( base_path,true );
|
|
|
|
NodePath to;
|
|
|
|
if (new_base_path.size())
|
|
|
|
to=NodePath( new_base_path,true );
|
|
|
|
|
|
|
|
Pair<NodePath,NodePath> npp;
|
|
|
|
npp.first=from;
|
|
|
|
npp.second=to;
|
|
|
|
|
|
|
|
p_renames->push_back(npp);
|
|
|
|
|
|
|
|
for(int i=0;i<p_node->get_child_count();i++) {
|
|
|
|
|
|
|
|
_fill_path_renames(base_path,new_base_path,p_node->get_child(i),p_renames);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTreeDock::fill_path_renames(Node* p_node, Node *p_new_parent, List<Pair<NodePath,NodePath> > *p_renames) {
|
|
|
|
|
|
|
|
if (!bool(EDITOR_DEF("animation/autorename_animation_tracks",true)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
Vector<StringName> base_path;
|
|
|
|
Node *n = p_node->get_parent();
|
|
|
|
while(n) {
|
|
|
|
base_path.push_back(n->get_name());
|
|
|
|
n=n->get_parent();
|
|
|
|
}
|
|
|
|
base_path.invert();
|
|
|
|
|
|
|
|
Vector<StringName> new_base_path;
|
|
|
|
if (p_new_parent) {
|
|
|
|
n = p_new_parent;
|
|
|
|
while(n) {
|
|
|
|
new_base_path.push_back(n->get_name());
|
|
|
|
n=n->get_parent();
|
|
|
|
}
|
|
|
|
|
|
|
|
new_base_path.invert();
|
|
|
|
}
|
|
|
|
|
|
|
|
_fill_path_renames(base_path,new_base_path,p_node,p_renames);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTreeDock::perform_node_renames(Node* p_base,List<Pair<NodePath,NodePath> > *p_renames, Map<Ref<Animation>, Set<int> > *r_rem_anims) {
|
|
|
|
|
|
|
|
Map<Ref<Animation>, Set<int> > rem_anims;
|
|
|
|
|
|
|
|
if (!r_rem_anims)
|
|
|
|
r_rem_anims=&rem_anims;
|
|
|
|
|
|
|
|
if (!bool(EDITOR_DEF("animation/autorename_animation_tracks",true)))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!p_base) {
|
|
|
|
|
|
|
|
p_base=edited_scene;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!p_base)
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (p_base->cast_to<AnimationPlayer>()) {
|
|
|
|
|
|
|
|
AnimationPlayer *ap=p_base->cast_to<AnimationPlayer>();
|
|
|
|
List<StringName> anims;
|
|
|
|
ap->get_animation_list(&anims);
|
|
|
|
Node *root = ap->get_node(ap->get_root());
|
|
|
|
|
|
|
|
|
|
|
|
if (root) {
|
|
|
|
|
|
|
|
|
|
|
|
NodePath root_path=root->get_path();
|
|
|
|
NodePath new_root_path=root_path;
|
|
|
|
|
|
|
|
|
|
|
|
for(List<Pair<NodePath,NodePath> >::Element* E=p_renames->front();E;E=E->next()) {
|
|
|
|
|
|
|
|
if (E->get().first==root_path) {
|
|
|
|
new_root_path=E->get().second;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_root_path!=NodePath()) {
|
|
|
|
//will not be erased
|
|
|
|
|
|
|
|
for(List<StringName>::Element *E=anims.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
Ref<Animation> anim=ap->get_animation(E->get());
|
|
|
|
if (!r_rem_anims->has(anim)) {
|
|
|
|
r_rem_anims->insert(anim,Set<int>());
|
|
|
|
Set<int> &ran = r_rem_anims->find(anim)->get();
|
|
|
|
for(int i=0;i<anim->get_track_count();i++)
|
|
|
|
ran.insert(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
Set<int> &ran = r_rem_anims->find(anim)->get();
|
|
|
|
|
|
|
|
if (anim.is_null())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for(int i=0;i<anim->get_track_count();i++) {
|
|
|
|
|
|
|
|
NodePath track_np=anim->track_get_path(i);
|
|
|
|
Node *n = root->get_node(track_np);
|
|
|
|
if (!n) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
NodePath old_np = n->get_path();
|
|
|
|
|
|
|
|
if (!ran.has(i))
|
|
|
|
continue; //channel was removed
|
|
|
|
|
|
|
|
for(List<Pair<NodePath,NodePath> >::Element* E=p_renames->front();E;E=E->next()) {
|
|
|
|
|
|
|
|
if (E->get().first==old_np) {
|
|
|
|
|
|
|
|
|
|
|
|
if (E->get().second==NodePath()) {
|
|
|
|
//will be erased
|
|
|
|
|
|
|
|
int idx=0;
|
|
|
|
Set<int>::Element *EI=ran.front();
|
|
|
|
ERR_FAIL_COND(!EI); //bug
|
|
|
|
while(EI->get()!=i) {
|
|
|
|
idx++;
|
|
|
|
EI=EI->next();
|
|
|
|
ERR_FAIL_COND(!EI); //another bug
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
editor_data->get_undo_redo().add_do_method(anim.ptr(),"remove_track",idx);
|
|
|
|
editor_data->get_undo_redo().add_undo_method(anim.ptr(),"add_track",anim->track_get_type(i),idx);
|
|
|
|
editor_data->get_undo_redo().add_undo_method(anim.ptr(),"track_set_path",idx,track_np);
|
|
|
|
editor_data->get_undo_redo().add_undo_method(anim.ptr(),"track_set_interpolation_type",idx,anim->track_get_interpolation_type(i));
|
|
|
|
for(int j=0;j<anim->track_get_key_count(i);j++) {
|
|
|
|
|
|
|
|
editor_data->get_undo_redo().add_undo_method(anim.ptr(),"track_insert_key",idx,anim->track_get_key_time(i,j),anim->track_get_key_value(i,j),anim->track_get_key_transition(i,j));
|
|
|
|
}
|
|
|
|
|
|
|
|
ran.erase(i); //byebye channel
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//will be renamed
|
|
|
|
NodePath rel_path = new_root_path.rel_path_to(E->get().second);
|
|
|
|
|
|
|
|
NodePath new_path = NodePath( rel_path.get_names(), track_np.get_subnames(), false, track_np.get_property() );
|
|
|
|
if (new_path==track_np)
|
|
|
|
continue; //bleh
|
|
|
|
editor_data->get_undo_redo().add_do_method(anim.ptr(),"track_set_path",i,new_path);
|
|
|
|
editor_data->get_undo_redo().add_undo_method(anim.ptr(),"track_set_path",i,track_np);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<p_base->get_child_count();i++)
|
|
|
|
perform_node_renames(p_base->get_child(i),p_renames,r_rem_anims);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SceneTreeDock::_node_prerenamed(Node* p_node, const String& p_new_name) {
|
|
|
|
|
|
|
|
|
|
|
|
List<Pair<NodePath,NodePath> > path_renames;
|
|
|
|
|
|
|
|
Vector<StringName> base_path;
|
|
|
|
Node *n = p_node->get_parent();
|
|
|
|
while(n) {
|
|
|
|
base_path.push_back(n->get_name());
|
|
|
|
n=n->get_parent();
|
|
|
|
}
|
|
|
|
base_path.invert();
|
|
|
|
|
|
|
|
|
|
|
|
Vector<StringName> new_base_path=base_path;
|
|
|
|
base_path.push_back(p_node->get_name());
|
|
|
|
|
|
|
|
new_base_path.push_back(p_new_name);
|
|
|
|
|
|
|
|
Pair<NodePath,NodePath> npp;
|
|
|
|
npp.first = NodePath(base_path,true);
|
|
|
|
npp.second = NodePath(new_base_path,true);
|
|
|
|
path_renames.push_back(npp);
|
|
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<p_node->get_child_count();i++)
|
|
|
|
_fill_path_renames(base_path,new_base_path,p_node->get_child(i),&path_renames);
|
|
|
|
|
|
|
|
perform_node_renames(NULL,&path_renames);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-09-03 10:13:40 +08:00
|
|
|
bool SceneTreeDock::_validate_no_foreign() {
|
|
|
|
|
|
|
|
List<Node*> selection = editor_selection->get_selected_node_list();
|
|
|
|
|
|
|
|
for (List<Node*>::Element *E=selection.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
if (E->get()!=edited_scene && E->get()->get_owner()!=edited_scene) {
|
|
|
|
|
2016-05-04 09:25:37 +08:00
|
|
|
accept->get_ok()->set_text(TTR("Makes Sense!"));
|
|
|
|
accept->set_text(TTR("Can't operate on nodes from a foreign scene!"));
|
2015-04-09 01:02:13 +08:00
|
|
|
accept->popup_centered_minsize();
|
2014-09-03 10:13:40 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
2015-10-10 20:09:09 +08:00
|
|
|
|
2016-01-18 07:03:57 +08:00
|
|
|
if (edited_scene->get_scene_inherited_state().is_valid() && edited_scene->get_scene_inherited_state()->find_node_by_path(edited_scene->get_path_to(E->get()))>=0) {
|
2015-10-10 20:09:09 +08:00
|
|
|
|
2016-05-04 09:25:37 +08:00
|
|
|
accept->get_ok()->set_text(TTR("Makes Sense!"));
|
|
|
|
accept->set_text(TTR("Can't operate on nodes the current scene inherits from!"));
|
2015-10-10 20:09:09 +08:00
|
|
|
accept->popup_centered_minsize();
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-09-03 10:13:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-02 22:57:47 +08:00
|
|
|
void SceneTreeDock::_node_reparent(NodePath p_path,bool p_keep_global_xform) {
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
Node *new_parent = scene_root->get_node(p_path);
|
|
|
|
ERR_FAIL_COND(!new_parent);
|
|
|
|
|
2016-05-11 22:46:08 +08:00
|
|
|
//ok all valid
|
|
|
|
|
|
|
|
List<Node*> selection = editor_selection->get_selected_node_list();
|
|
|
|
|
|
|
|
if (selection.empty())
|
|
|
|
return; //nothing to reparent
|
|
|
|
|
|
|
|
Vector<Node*> nodes;
|
|
|
|
|
|
|
|
for(List<Node*>::Element *E=selection.front();E;E=E->next()) {
|
|
|
|
nodes.push_back(E->get());
|
|
|
|
}
|
|
|
|
|
|
|
|
_do_reparent(new_parent,-1,nodes,p_keep_global_xform);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SceneTreeDock::_do_reparent(Node* p_new_parent,int p_position_in_parent,Vector<Node*> p_nodes,bool p_keep_global_xform) {
|
|
|
|
|
|
|
|
|
|
|
|
Node *new_parent = p_new_parent;
|
|
|
|
ERR_FAIL_COND(!new_parent);
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
Node *validate=new_parent;
|
|
|
|
while(validate) {
|
|
|
|
|
2016-05-11 22:46:08 +08:00
|
|
|
if (p_nodes.find(validate)!=-1) {
|
2014-02-10 09:10:30 +08:00
|
|
|
ERR_EXPLAIN("Selection changed at some point.. can't reparent");
|
|
|
|
ERR_FAIL();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
validate=validate->get_parent();
|
|
|
|
}
|
|
|
|
|
|
|
|
//ok all valid
|
|
|
|
|
|
|
|
List<Node*> selection = editor_selection->get_selected_node_list();
|
|
|
|
|
2016-05-11 22:46:08 +08:00
|
|
|
if (p_nodes.size()==0)
|
2014-02-10 09:10:30 +08:00
|
|
|
return; //nothing to reparent
|
|
|
|
|
|
|
|
//sort by tree order, so re-adding is easy
|
2016-05-11 22:46:08 +08:00
|
|
|
p_nodes.sort_custom<Node::Comparator>();
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2016-05-04 09:25:37 +08:00
|
|
|
editor_data->get_undo_redo().create_action(TTR("Reparent Node"));
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
List<Pair<NodePath,NodePath> > path_renames;
|
|
|
|
|
2016-05-11 22:46:08 +08:00
|
|
|
for(int ni=0;ni<p_nodes.size();ni++) {
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
//no undo for now, sorry
|
2016-05-11 22:46:08 +08:00
|
|
|
Node *node = p_nodes[ni];
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
fill_path_renames(node,new_parent,&path_renames);
|
|
|
|
|
|
|
|
List<Node*> owned;
|
|
|
|
node->get_owned_by(node->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(node->get_parent(),"remove_child",node);
|
|
|
|
editor_data->get_undo_redo().add_do_method(new_parent,"add_child",node);
|
2015-08-02 23:29:37 +08:00
|
|
|
|
2016-05-11 22:46:08 +08:00
|
|
|
if (p_position_in_parent>=0)
|
|
|
|
editor_data->get_undo_redo().add_do_method(new_parent,"move_child",node,p_position_in_parent+ni);
|
|
|
|
|
2015-08-02 23:29:37 +08:00
|
|
|
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
|
|
|
|
String new_name = new_parent->validate_child_name(node->get_name());
|
2015-08-03 07:28:10 +08:00
|
|
|
editor_data->get_undo_redo().add_do_method(sed,"live_debug_reparent_node",edited_scene->get_path_to(node),edited_scene->get_path_to(new_parent),new_name,-1);
|
|
|
|
editor_data->get_undo_redo().add_undo_method(sed,"live_debug_reparent_node",NodePath(String(edited_scene->get_path_to(new_parent))+"/"+new_name),edited_scene->get_path_to(node->get_parent()),node->get_name(),node->get_index());
|
2015-08-02 23:29:37 +08:00
|
|
|
|
2016-01-02 22:57:47 +08:00
|
|
|
if (p_keep_global_xform) {
|
|
|
|
if (node->cast_to<Node2D>())
|
|
|
|
editor_data->get_undo_redo().add_do_method(node,"set_global_transform",node->cast_to<Node2D>()->get_global_transform());
|
|
|
|
if (node->cast_to<Spatial>())
|
|
|
|
editor_data->get_undo_redo().add_do_method(node,"set_global_transform",node->cast_to<Spatial>()->get_global_transform());
|
|
|
|
if (node->cast_to<Control>()) {
|
|
|
|
bool can_do_it=false;
|
|
|
|
Control *c=node->cast_to<Control>();
|
|
|
|
if (c->get_parent()->cast_to<Container>())
|
|
|
|
can_do_it=false;
|
|
|
|
for(int i=0;i<4;i++) {
|
|
|
|
if (c->get_anchor(Margin(i))!=ANCHOR_BEGIN)
|
|
|
|
can_do_it=false;
|
|
|
|
}
|
|
|
|
editor_data->get_undo_redo().add_do_method(node,"set_global_pos",node->cast_to<Control>()->get_global_pos());
|
|
|
|
}
|
|
|
|
}
|
2015-08-02 23:29:37 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
editor_data->get_undo_redo().add_do_method(this,"_set_owners",edited_scene,owners);
|
|
|
|
|
2016-01-18 07:03:57 +08:00
|
|
|
if (AnimationPlayerEditor::singleton->get_key_editor()->get_root()==node)
|
|
|
|
editor_data->get_undo_redo().add_do_method(AnimationPlayerEditor::singleton->get_key_editor(),"set_root",node);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
editor_data->get_undo_redo().add_undo_method(new_parent,"remove_child",node);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//add and move in a second step.. (so old order is preserved)
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-05-11 22:46:08 +08:00
|
|
|
for(int ni=0;ni<p_nodes.size();ni++) {
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2016-05-11 22:46:08 +08:00
|
|
|
Node *node = p_nodes[ni];
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
List<Node*> owned;
|
|
|
|
node->get_owned_by(node->get_owner(),&owned);
|
|
|
|
Array owners;
|
|
|
|
for(List<Node*>::Element *E=owned.front();E;E=E->next()) {
|
|
|
|
|
|
|
|
owners.push_back(E->get());
|
|
|
|
}
|
|
|
|
|
|
|
|
int child_pos = node->get_position_in_parent();
|
|
|
|
|
|
|
|
editor_data->get_undo_redo().add_undo_method(node->get_parent(),"add_child",node);
|
|
|
|
editor_data->get_undo_redo().add_undo_method(node->get_parent(),"move_child",node,child_pos);
|
|
|
|
editor_data->get_undo_redo().add_undo_method(this,"_set_owners",edited_scene,owners);
|
2016-01-18 07:03:57 +08:00
|
|
|
if (AnimationPlayerEditor::singleton->get_key_editor()->get_root()==node)
|
|
|
|
editor_data->get_undo_redo().add_undo_method(AnimationPlayerEditor::singleton->get_key_editor(),"set_root",node);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2016-01-02 22:57:47 +08:00
|
|
|
if (p_keep_global_xform) {
|
|
|
|
if (node->cast_to<Node2D>())
|
|
|
|
editor_data->get_undo_redo().add_undo_method(node,"set_transform",node->cast_to<Node2D>()->get_transform());
|
|
|
|
if (node->cast_to<Spatial>())
|
|
|
|
editor_data->get_undo_redo().add_undo_method(node,"set_transform",node->cast_to<Spatial>()->get_transform());
|
|
|
|
if (node->cast_to<Control>()) {
|
|
|
|
bool can_do_it=false;
|
|
|
|
Control *c=node->cast_to<Control>();
|
|
|
|
if (c->get_parent()->cast_to<Container>())
|
|
|
|
can_do_it=false;
|
|
|
|
for(int i=0;i<4;i++) {
|
|
|
|
if (c->get_anchor(Margin(i))!=ANCHOR_BEGIN)
|
|
|
|
can_do_it=false;
|
|
|
|
}
|
|
|
|
editor_data->get_undo_redo().add_undo_method(node,"set_pos",node->cast_to<Control>()->get_pos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
perform_node_renames(NULL,&path_renames);
|
|
|
|
|
|
|
|
editor_data->get_undo_redo().commit_action();
|
|
|
|
//node->set_owner(owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTreeDock::_script_created(Ref<Script> p_script) {
|
|
|
|
|
|
|
|
Node *selected = scene_tree->get_selected();
|
|
|
|
if (!selected)
|
|
|
|
return;
|
|
|
|
selected->set_script(p_script.get_ref_ptr());
|
|
|
|
editor->push_item(p_script.operator->());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SceneTreeDock::_delete_confirm() {
|
|
|
|
|
|
|
|
List<Node*> remove_list = editor_selection->get_selected_node_list();
|
|
|
|
|
|
|
|
if (remove_list.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
2016-03-30 07:02:53 +08:00
|
|
|
editor->get_editor_plugins_over()->make_visible(false);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2016-05-04 09:25:37 +08:00
|
|
|
editor_data->get_undo_redo().create_action(TTR("Remove Node(s)"));
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
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();
|
2014-11-06 08:20:42 +08:00
|
|
|
if (!n->is_inside_tree() || !n->get_parent())
|
2014-02-10 09:10:30 +08:00
|
|
|
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();
|
2014-11-06 08:20:42 +08:00
|
|
|
if (!n->is_inside_tree() || !n->get_parent())
|
2014-02-10 09:10:30 +08:00
|
|
|
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());
|
2016-01-18 07:03:57 +08:00
|
|
|
if (AnimationPlayerEditor::singleton->get_key_editor()->get_root()==n)
|
|
|
|
editor_data->get_undo_redo().add_undo_method(AnimationPlayerEditor::singleton->get_key_editor(),"set_root",n);
|
2014-02-10 09:10:30 +08:00
|
|
|
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);
|
2015-08-02 23:29:37 +08:00
|
|
|
|
|
|
|
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
|
|
|
|
editor_data->get_undo_redo().add_do_method(sed,"live_debug_remove_and_keep_node",edited_scene->get_path_to(n),n->get_instance_ID());
|
|
|
|
editor_data->get_undo_redo().add_undo_method(sed,"live_debug_restore_node",n->get_instance_ID(),edited_scene->get_path_to(n->get_parent()),n->get_index());
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
editor_data->get_undo_redo().commit_action();
|
|
|
|
_update_tool_buttons();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTreeDock::_update_tool_buttons() {
|
|
|
|
|
|
|
|
Node *sel = scene_tree->get_selected();
|
2015-10-22 03:52:43 +08:00
|
|
|
bool disable = !sel || (sel!=edited_scene && sel->get_owner()!=edited_scene);
|
|
|
|
disable = disable || (edited_scene->get_scene_inherited_state().is_valid() && edited_scene->get_scene_inherited_state()->find_node_by_path(edited_scene->get_path_to(sel))>=0);
|
2014-02-10 09:10:30 +08:00
|
|
|
bool disable_root = disable || sel->get_parent()==scene_root;
|
2015-10-10 20:09:09 +08:00
|
|
|
bool disable_edit = !sel;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2015-10-10 20:09:09 +08:00
|
|
|
tool_buttons[TOOL_INSTANCE]->set_disabled(disable_edit);
|
2014-02-10 09:10:30 +08:00
|
|
|
tool_buttons[TOOL_REPLACE]->set_disabled(disable);
|
2015-10-10 20:09:09 +08:00
|
|
|
tool_buttons[TOOL_CONNECT]->set_disabled(disable_edit);
|
|
|
|
tool_buttons[TOOL_GROUP]->set_disabled(disable_edit);
|
|
|
|
tool_buttons[TOOL_SCRIPT]->set_disabled(disable_edit);
|
2014-02-10 09:10:30 +08:00
|
|
|
tool_buttons[TOOL_MOVE_UP]->set_disabled(disable_root);
|
|
|
|
tool_buttons[TOOL_MOVE_DOWN]->set_disabled(disable_root);
|
|
|
|
tool_buttons[TOOL_DUPLICATE]->set_disabled(disable_root);
|
|
|
|
tool_buttons[TOOL_REPARENT]->set_disabled(disable_root);
|
|
|
|
tool_buttons[TOOL_ERASE]->set_disabled(disable);
|
2015-11-28 04:42:48 +08:00
|
|
|
tool_buttons[TOOL_NEW_SCENE_FROM]->set_disabled(disable_root);
|
2015-08-25 11:08:45 +08:00
|
|
|
tool_buttons[TOOL_MULTI_EDIT]->set_disabled(EditorNode::get_singleton()->get_editor_selection()->get_selection().size()<2);
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-25 11:08:45 +08:00
|
|
|
|
|
|
|
void SceneTreeDock::_selection_changed() {
|
|
|
|
|
|
|
|
tool_buttons[TOOL_MULTI_EDIT]->set_disabled(EditorNode::get_singleton()->get_editor_selection()->get_selection().size()<2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
void SceneTreeDock::_create() {
|
|
|
|
|
|
|
|
|
|
|
|
if (current_option==TOOL_NEW) {
|
|
|
|
|
|
|
|
Node *parent=NULL;
|
|
|
|
|
|
|
|
|
|
|
|
if (edited_scene) {
|
2015-04-01 02:26:38 +08:00
|
|
|
// If root exists in edited scene
|
2014-02-10 09:10:30 +08:00
|
|
|
parent = scene_tree->get_selected();
|
2015-04-01 02:26:38 +08:00
|
|
|
if( !parent )
|
|
|
|
parent = edited_scene;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2015-04-01 02:26:38 +08:00
|
|
|
} else {
|
|
|
|
// If no root exist in edited scene
|
2014-02-10 09:10:30 +08:00
|
|
|
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);
|
|
|
|
|
2016-05-04 09:25:37 +08:00
|
|
|
editor_data->get_undo_redo().create_action(TTR("Create Node"));
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
if (edited_scene) {
|
2015-08-02 23:29:37 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
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);
|
2015-08-02 23:29:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
} 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);
|
2016-04-13 00:21:37 +08:00
|
|
|
newnode->set_editable_instances(n->get_editable_instances());
|
2014-02-10 09:10:30 +08:00
|
|
|
}
|
|
|
|
|
2016-01-12 16:53:59 +08:00
|
|
|
//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") );
|
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
editor_data->get_undo_redo().clear_history();
|
|
|
|
newnode->set_name(newname);
|
2015-09-07 21:13:29 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
editor->push_item(newnode);
|
|
|
|
|
2015-09-07 21:13:29 +08:00
|
|
|
memdelete(n);
|
2016-01-18 07:03:57 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
_update_tool_buttons();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SceneTreeDock::set_edited_scene(Node* p_scene) {
|
|
|
|
|
|
|
|
edited_scene=p_scene;
|
|
|
|
}
|
|
|
|
|
2014-07-02 15:34:46 +08:00
|
|
|
void SceneTreeDock::set_selected(Node *p_node, bool p_emit_selected ) {
|
2014-02-10 09:10:30 +08:00
|
|
|
|
2014-07-02 15:34:46 +08:00
|
|
|
scene_tree->set_selected(p_node,p_emit_selected);
|
2014-02-10 09:10:30 +08:00
|
|
|
_update_tool_buttons();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTreeDock::import_subscene() {
|
|
|
|
|
|
|
|
import_subscene_dialog->popup_centered_ratio();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTreeDock::_import_subscene() {
|
|
|
|
|
|
|
|
Node* parent = scene_tree->get_selected();
|
2015-11-24 03:06:37 +08:00
|
|
|
if (!parent) {
|
|
|
|
parent = editor_data->get_edited_scene_root();
|
|
|
|
ERR_FAIL_COND(!parent);
|
|
|
|
}
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
import_subscene_dialog->move(parent,edited_scene);
|
|
|
|
editor_data->get_undo_redo().clear_history(); //no undo for now..
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2016-05-04 09:25:37 +08:00
|
|
|
editor_data->get_undo_redo().create_action(TTR("Import Subscene"));
|
2014-02-10 09:10:30 +08:00
|
|
|
editor_data->get_undo_redo().add_do_method(parent,"add_child",ss);
|
|
|
|
//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(ss);
|
|
|
|
editor_data->get_undo_redo().add_undo_method(parent,"remove_child",ss);
|
|
|
|
editor_data->get_undo_redo().commit_action();
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2015-11-28 04:42:48 +08:00
|
|
|
void SceneTreeDock::_new_scene_from(String p_file) {
|
|
|
|
|
|
|
|
List<Node*> selection = editor_selection->get_selected_node_list();
|
|
|
|
|
|
|
|
if (selection.size()!=1) {
|
2016-05-04 09:25:37 +08:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
|
|
|
accept->set_text(TTR("This operation requires a single selected node."));
|
2015-11-28 04:42:48 +08:00
|
|
|
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) {
|
2016-05-04 09:25:37 +08:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
|
|
|
accept->set_text(TTR("Couldn't save new scene. Likely dependencies (instances) couldn't be satisfied."));
|
2015-11-28 04:42:48 +08:00
|
|
|
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) {
|
2016-05-04 09:25:37 +08:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
|
|
|
accept->set_text(TTR("Error saving scene."));
|
2015-11-28 04:42:48 +08:00
|
|
|
accept->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2016-05-04 09:25:37 +08:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
|
|
|
accept->set_text(TTR("Error duplicating scene to save it."));
|
2015-11-28 04:42:48 +08:00
|
|
|
accept->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-11 22:46:08 +08:00
|
|
|
static bool _is_node_visible(Node* p_node) {
|
|
|
|
|
|
|
|
if (!p_node->get_owner())
|
|
|
|
return false;
|
|
|
|
if (p_node->get_owner()!=EditorNode::get_singleton()->get_edited_scene() && !EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(p_node->get_owner()))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool _has_visible_children(Node* p_node) {
|
|
|
|
|
|
|
|
bool collapsed = p_node->has_meta("_editor_collapsed") ? (bool)p_node->get_meta("_editor_collapsed") : false;
|
|
|
|
if (collapsed)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for(int i=0;i<p_node->get_child_count();i++) {
|
|
|
|
|
|
|
|
Node* child = p_node->get_child(i);
|
|
|
|
if (!_is_node_visible(p_node))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Node* _find_last_visible(Node*p_node) {
|
|
|
|
|
|
|
|
Node*last=NULL;
|
|
|
|
for(int i=0;i<p_node->get_child_count();i++) {
|
|
|
|
if (_is_node_visible(p_node->get_child(i))) {
|
|
|
|
last=p_node->get_child(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last) {
|
|
|
|
Node* lastc=_find_last_visible(last);
|
|
|
|
if (lastc)
|
|
|
|
last=lastc;
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
last=p_node;
|
|
|
|
}
|
|
|
|
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-12 07:57:52 +08:00
|
|
|
void SceneTreeDock::_normalize_drop(Node*& to_node, int &to_pos,int p_type) {
|
2016-05-11 22:46:08 +08:00
|
|
|
|
2016-05-12 07:57:52 +08:00
|
|
|
to_pos=-1;
|
2016-05-11 22:46:08 +08:00
|
|
|
|
|
|
|
if (p_type==1 && to_node==EditorNode::get_singleton()->get_edited_scene()) {
|
|
|
|
//if at lower sibling of root node
|
|
|
|
to_pos=0; //just insert at begining of root node
|
|
|
|
} else if (p_type==-1) {
|
|
|
|
//drop at above selected node
|
2016-05-12 07:57:52 +08:00
|
|
|
if (to_node==EditorNode::get_singleton()->get_edited_scene()) {
|
|
|
|
to_node=NULL;
|
|
|
|
ERR_FAIL_COND(to_node==EditorNode::get_singleton()->get_edited_scene());
|
|
|
|
}
|
2016-05-11 22:46:08 +08:00
|
|
|
Node* upper_sibling=NULL;
|
|
|
|
|
|
|
|
for(int i=0;i<to_node->get_index();i++) {
|
|
|
|
Node *c =to_node->get_parent()->get_child(i);
|
|
|
|
if (_is_node_visible(c)) {
|
|
|
|
upper_sibling=c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (upper_sibling) {
|
|
|
|
//quite complicated, look for next visible in tree
|
|
|
|
upper_sibling=_find_last_visible(upper_sibling);
|
|
|
|
|
|
|
|
if (upper_sibling->get_parent()==to_node->get_parent()) {
|
|
|
|
//just insert over this node because nothing is above at an upper level
|
|
|
|
to_pos=to_node->get_index();
|
|
|
|
to_node=to_node->get_parent();
|
|
|
|
} else {
|
|
|
|
to_pos=-1; //insert last in whathever is up
|
|
|
|
to_node=upper_sibling->get_parent(); //insert at a parent of whathever is up
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//just insert over this node because nothing is above at the same level
|
|
|
|
to_pos=to_node->get_index();
|
|
|
|
to_node=to_node->get_parent();
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (p_type==1) {
|
|
|
|
//drop at below selected node
|
2016-05-12 07:57:52 +08:00
|
|
|
if (to_node==EditorNode::get_singleton()->get_edited_scene()) {
|
|
|
|
to_node=NULL;
|
|
|
|
ERR_FAIL_COND(to_node==EditorNode::get_singleton()->get_edited_scene());
|
|
|
|
}
|
2016-05-11 22:46:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
Node* lower_sibling=NULL;
|
|
|
|
|
|
|
|
for(int i=to_node->get_index()+1;i<to_node->get_parent()->get_child_count();i++) {
|
|
|
|
Node *c =to_node->get_parent()->get_child(i);
|
|
|
|
if (_is_node_visible(c)) {
|
|
|
|
lower_sibling=c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lower_sibling) {
|
|
|
|
to_pos=lower_sibling->get_index();
|
|
|
|
}
|
|
|
|
|
|
|
|
to_node=to_node->get_parent();
|
|
|
|
#if 0
|
|
|
|
//quite complicated, look for next visible in tree
|
|
|
|
upper_sibling=_find_last_visible(upper_sibling);
|
|
|
|
|
|
|
|
if (upper_sibling->get_parent()==to_node->get_parent()) {
|
|
|
|
//just insert over this node because nothing is above at an upper level
|
|
|
|
to_pos=to_node->get_index();
|
|
|
|
to_node=to_node->get_parent();
|
|
|
|
} else {
|
|
|
|
to_pos=-1; //insert last in whathever is up
|
|
|
|
to_node=upper_sibling->get_parent(); //insert at a parent of whathever is up
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//just insert over this node because nothing is above at the same level
|
|
|
|
to_pos=to_node->get_index();
|
|
|
|
to_node=to_node->get_parent();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-12 07:57:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTreeDock::_files_dropped(Vector<String> p_files,NodePath p_to,int p_type) {
|
|
|
|
|
|
|
|
Node *node = get_node(p_to);
|
|
|
|
ERR_FAIL_COND(!node);
|
|
|
|
|
|
|
|
int to_pos=-1;
|
|
|
|
_normalize_drop(node,to_pos,p_type);
|
|
|
|
instance_scenes(p_files,node,to_pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTreeDock::_nodes_dragged(Array p_nodes,NodePath p_to,int p_type) {
|
|
|
|
|
|
|
|
Vector<Node*> nodes;
|
|
|
|
Node *to_node;
|
|
|
|
|
|
|
|
for(int i=0;i<p_nodes.size();i++) {
|
|
|
|
Node *n=get_node((p_nodes[i]));
|
|
|
|
nodes.push_back(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nodes.size()==0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
to_node=get_node(p_to);
|
|
|
|
if (!to_node)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int to_pos=-1;
|
|
|
|
|
|
|
|
_normalize_drop(to_node,to_pos,p_type);
|
2016-05-11 22:46:08 +08:00
|
|
|
_do_reparent(to_node,to_pos,nodes,true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-16 10:41:48 +08:00
|
|
|
void SceneTreeDock::_tree_rmb(const Vector2& p_menu_pos) {
|
|
|
|
|
|
|
|
List<Node*> selection = editor_selection->get_selected_node_list();
|
|
|
|
|
|
|
|
if (selection.size()==0)
|
|
|
|
return;
|
|
|
|
menu->clear();
|
|
|
|
|
|
|
|
|
|
|
|
if (selection.size()==1) {
|
|
|
|
menu->add_item("Add Child Node",TOOL_NEW,KEY_MASK_CMD|KEY_A);
|
|
|
|
menu->add_item("Instance Child",TOOL_INSTANCE);
|
|
|
|
menu->add_separator();
|
|
|
|
menu->add_item("Change Type",TOOL_REPLACE);
|
|
|
|
menu->add_separator();
|
|
|
|
menu->add_item("Edit Groups",TOOL_GROUP);
|
|
|
|
menu->add_item("Edit Connections",TOOL_CONNECT);
|
|
|
|
menu->add_separator();
|
|
|
|
menu->add_item("Add Script",TOOL_SCRIPT);
|
|
|
|
menu->add_separator();
|
|
|
|
}
|
|
|
|
|
|
|
|
menu->add_item("Move Up",TOOL_MOVE_UP,KEY_MASK_CMD|KEY_UP);
|
|
|
|
menu->add_item("Move Down",TOOL_MOVE_DOWN,KEY_MASK_CMD|KEY_DOWN);
|
|
|
|
menu->add_item("Duplicate",TOOL_DUPLICATE,KEY_MASK_CMD|KEY_D);
|
|
|
|
menu->add_item("Reparent",TOOL_REPARENT);
|
|
|
|
|
|
|
|
if (selection.size()==1) {
|
|
|
|
menu->add_separator();
|
|
|
|
menu->add_item("Save Branch as Scene",TOOL_NEW_SCENE_FROM);
|
|
|
|
}
|
|
|
|
menu->add_separator();
|
|
|
|
|
|
|
|
menu->add_item("Delete Node(s)",TOOL_ERASE,KEY_DELETE);
|
|
|
|
|
|
|
|
menu->set_size(Size2(1,1));
|
|
|
|
menu->set_pos(p_menu_pos);
|
|
|
|
menu->popup();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
void SceneTreeDock::_bind_methods() {
|
|
|
|
|
2016-05-16 10:41:48 +08:00
|
|
|
ObjectTypeDB::bind_method(_MD("_tool_selected"),&SceneTreeDock::_tool_selected,DEFVAL(false));
|
2014-02-10 09:10:30 +08:00
|
|
|
ObjectTypeDB::bind_method(_MD("_create"),&SceneTreeDock::_create);
|
|
|
|
//ObjectTypeDB::bind_method(_MD("_script_created"),&SceneTreeDock::_script_created);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_node_reparent"),&SceneTreeDock::_node_reparent);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_set_owners"),&SceneTreeDock::_set_owners);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_node_selected"),&SceneTreeDock::_node_selected);
|
2014-09-21 23:56:19 +08:00
|
|
|
ObjectTypeDB::bind_method(_MD("_node_renamed"),&SceneTreeDock::_node_renamed);
|
2014-02-10 09:10:30 +08:00
|
|
|
ObjectTypeDB::bind_method(_MD("_script_created"),&SceneTreeDock::_script_created);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_load_request"),&SceneTreeDock::_load_request);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_script_open_request"),&SceneTreeDock::_script_open_request);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_unhandled_key_input"),&SceneTreeDock::_unhandled_key_input);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_delete_confirm"),&SceneTreeDock::_delete_confirm);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_node_prerenamed"),&SceneTreeDock::_node_prerenamed);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_import_subscene"),&SceneTreeDock::_import_subscene);
|
2015-08-25 11:08:45 +08:00
|
|
|
ObjectTypeDB::bind_method(_MD("_selection_changed"),&SceneTreeDock::_selection_changed);
|
2015-11-28 04:42:48 +08:00
|
|
|
ObjectTypeDB::bind_method(_MD("_new_scene_from"),&SceneTreeDock::_new_scene_from);
|
2016-05-11 22:46:08 +08:00
|
|
|
ObjectTypeDB::bind_method(_MD("_nodes_dragged"),&SceneTreeDock::_nodes_dragged);
|
2016-05-12 07:57:52 +08:00
|
|
|
ObjectTypeDB::bind_method(_MD("_files_dropped"),&SceneTreeDock::_files_dropped);
|
2016-05-16 10:41:48 +08:00
|
|
|
ObjectTypeDB::bind_method(_MD("_tree_rmb"),&SceneTreeDock::_tree_rmb);
|
2016-05-11 22:46:08 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
ObjectTypeDB::bind_method(_MD("instance"),&SceneTreeDock::instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SceneTreeDock::SceneTreeDock(EditorNode *p_editor,Node *p_scene_root,EditorSelection *p_editor_selection,EditorData &p_editor_data) {
|
|
|
|
|
|
|
|
editor=p_editor;
|
|
|
|
edited_scene=NULL;
|
|
|
|
editor_data=&p_editor_data;
|
|
|
|
editor_selection=p_editor_selection;
|
|
|
|
scene_root=p_scene_root;
|
|
|
|
|
|
|
|
VBoxContainer *vbc = this;
|
|
|
|
|
|
|
|
HBoxContainer *hbc_top = memnew( HBoxContainer );
|
|
|
|
vbc->add_child(hbc_top);
|
|
|
|
|
|
|
|
ToolButton *tb;
|
|
|
|
|
|
|
|
tb = memnew( ToolButton );
|
2014-05-09 18:50:48 +08:00
|
|
|
tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_NEW, false));
|
2014-02-10 09:10:30 +08:00
|
|
|
tb->set_tooltip("Add/Create a New Node\n("+keycode_get_string(KEY_MASK_CMD|KEY_A)+")");
|
|
|
|
hbc_top->add_child(tb);
|
|
|
|
tool_buttons[TOOL_NEW]=tb;
|
|
|
|
|
|
|
|
tb = memnew( ToolButton );
|
2014-05-09 18:50:48 +08:00
|
|
|
tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_INSTANCE, false));
|
2016-05-04 09:25:37 +08:00
|
|
|
tb->set_tooltip(TTR("Instance a scene file as a Node."));
|
2014-02-10 09:10:30 +08:00
|
|
|
hbc_top->add_child(tb);
|
|
|
|
tool_buttons[TOOL_INSTANCE]=tb;
|
|
|
|
|
|
|
|
tb = memnew( ToolButton );
|
2014-05-09 18:50:48 +08:00
|
|
|
tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_REPLACE, false));
|
2016-05-04 09:25:37 +08:00
|
|
|
tb->set_tooltip(TTR("Replace a Node by Another Node Type"));
|
2014-02-10 09:10:30 +08:00
|
|
|
hbc_top->add_child(tb);
|
|
|
|
tool_buttons[TOOL_REPLACE]=tb;
|
|
|
|
|
|
|
|
hbc_top->add_spacer();
|
|
|
|
|
|
|
|
tb = memnew( ToolButton );
|
2014-05-09 18:50:48 +08:00
|
|
|
tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_CONNECT, false));
|
2016-05-04 09:25:37 +08:00
|
|
|
tb->set_tooltip(TTR("Edit the Node Connections"));
|
2014-02-10 09:10:30 +08:00
|
|
|
hbc_top->add_child(tb);
|
|
|
|
tool_buttons[TOOL_CONNECT]=tb;
|
|
|
|
|
|
|
|
tb = memnew( ToolButton );
|
2014-05-09 18:50:48 +08:00
|
|
|
tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_GROUP, false));
|
2016-05-04 09:25:37 +08:00
|
|
|
tb->set_tooltip(TTR("Edit the Node Groups"));
|
2014-02-10 09:10:30 +08:00
|
|
|
hbc_top->add_child(tb);
|
|
|
|
tool_buttons[TOOL_GROUP]=tb;
|
|
|
|
|
|
|
|
tb = memnew( ToolButton );
|
2014-05-09 18:50:48 +08:00
|
|
|
tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_SCRIPT, false));
|
2016-05-04 09:25:37 +08:00
|
|
|
tb->set_tooltip(TTR("Edit/Create the Node Script"));
|
2014-02-10 09:10:30 +08:00
|
|
|
hbc_top->add_child(tb);
|
|
|
|
tool_buttons[TOOL_SCRIPT]=tb;
|
|
|
|
|
|
|
|
|
|
|
|
scene_tree = memnew( SceneTreeEditor(false,true,true ));
|
|
|
|
vbc->add_child(scene_tree);
|
|
|
|
scene_tree->set_v_size_flags(SIZE_EXPAND|SIZE_FILL);
|
2016-05-16 10:41:48 +08:00
|
|
|
scene_tree->connect("rmb_pressed",this,"_tree_rmb");
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
scene_tree->connect("node_selected", this,"_node_selected",varray(),CONNECT_DEFERRED);
|
|
|
|
scene_tree->connect("node_renamed", this,"_node_renamed",varray(),CONNECT_DEFERRED);
|
|
|
|
scene_tree->connect("node_prerename", this,"_node_prerenamed");
|
|
|
|
scene_tree->connect("open",this,"_load_request");
|
|
|
|
scene_tree->connect("open_script",this,"_script_open_request");
|
2016-05-11 22:46:08 +08:00
|
|
|
scene_tree->connect("nodes_rearranged",this,"_nodes_dragged");
|
2016-05-12 07:57:52 +08:00
|
|
|
scene_tree->connect("files_dropped",this,"_files_dropped");
|
2016-05-11 22:46:08 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
scene_tree->set_undo_redo(&editor_data->get_undo_redo());
|
|
|
|
scene_tree->set_editor_selection(editor_selection);
|
|
|
|
|
2015-12-19 17:41:45 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
HBoxContainer *hbc_bottom = memnew( HBoxContainer );
|
|
|
|
vbc->add_child(hbc_bottom);
|
2015-12-19 17:41:45 +08:00
|
|
|
hbc_bottom->add_constant_override("separation", 0);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
tb = memnew( ToolButton );
|
2014-05-09 18:50:48 +08:00
|
|
|
tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_MOVE_UP, false));
|
2014-02-10 09:10:30 +08:00
|
|
|
tb->set_tooltip("Move Node Up\n("+keycode_get_string(KEY_MASK_CMD|KEY_UP)+")");
|
|
|
|
hbc_bottom->add_child(tb);
|
|
|
|
tool_buttons[TOOL_MOVE_UP]=tb;
|
|
|
|
|
|
|
|
tb = memnew( ToolButton );
|
2014-05-09 18:50:48 +08:00
|
|
|
tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_MOVE_DOWN, false));
|
2014-02-10 09:10:30 +08:00
|
|
|
tb->set_tooltip("Move Node Down\n("+keycode_get_string(KEY_MASK_CMD|KEY_DOWN)+")");
|
|
|
|
hbc_bottom->add_child(tb);
|
|
|
|
tool_buttons[TOOL_MOVE_DOWN]=tb;
|
|
|
|
|
|
|
|
tb = memnew( ToolButton );
|
2014-05-09 18:50:48 +08:00
|
|
|
tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_DUPLICATE, false));
|
2014-02-10 09:10:30 +08:00
|
|
|
tb->set_tooltip("Duplicate Selected Node(s)\n("+keycode_get_string(KEY_MASK_CMD|KEY_D)+")");
|
|
|
|
hbc_bottom->add_child(tb);
|
|
|
|
tool_buttons[TOOL_DUPLICATE]=tb;
|
|
|
|
|
|
|
|
tb = memnew( ToolButton );
|
2014-05-09 18:50:48 +08:00
|
|
|
tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_REPARENT, false));
|
2016-05-04 09:25:37 +08:00
|
|
|
tb->set_tooltip(TTR("Reparent Selected Node(s)"));
|
2014-02-10 09:10:30 +08:00
|
|
|
hbc_bottom->add_child(tb);
|
|
|
|
tool_buttons[TOOL_REPARENT]=tb;
|
|
|
|
|
|
|
|
hbc_bottom->add_spacer();
|
|
|
|
|
2015-11-28 04:42:48 +08:00
|
|
|
tb = memnew( ToolButton );
|
|
|
|
tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_NEW_SCENE_FROM, false));
|
2016-05-04 09:25:37 +08:00
|
|
|
tb->set_tooltip(TTR("Create New Scene From Node(s)"));
|
2015-11-28 04:42:48 +08:00
|
|
|
hbc_bottom->add_child(tb);
|
|
|
|
tool_buttons[TOOL_NEW_SCENE_FROM]=tb;
|
|
|
|
|
2015-08-25 11:08:45 +08:00
|
|
|
tb = memnew( ToolButton );
|
|
|
|
tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_MULTI_EDIT, false));
|
2016-05-04 09:25:37 +08:00
|
|
|
tb->set_tooltip(TTR("Multi-Edit Selected Nodes"));
|
2015-08-25 11:08:45 +08:00
|
|
|
hbc_bottom->add_child(tb);
|
|
|
|
tool_buttons[TOOL_MULTI_EDIT]=tb;
|
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
tb = memnew( ToolButton );
|
2014-05-09 18:50:48 +08:00
|
|
|
tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_ERASE, false));
|
2016-05-04 09:25:37 +08:00
|
|
|
tb->set_tooltip(TTR("Erase Selected Node(s)"));
|
2014-02-10 09:10:30 +08:00
|
|
|
hbc_bottom->add_child(tb);
|
|
|
|
tool_buttons[TOOL_ERASE]=tb;
|
|
|
|
|
|
|
|
create_dialog = memnew( CreateDialog );
|
|
|
|
create_dialog->set_base_type("Node");
|
|
|
|
add_child(create_dialog);
|
|
|
|
create_dialog->connect("create",this,"_create");
|
|
|
|
|
|
|
|
groups_editor = memnew( GroupsEditor );
|
|
|
|
add_child(groups_editor);
|
|
|
|
groups_editor->set_undo_redo(&editor_data->get_undo_redo());
|
2015-11-28 04:42:48 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
connect_dialog = memnew( ConnectionsDialog(p_editor) );
|
|
|
|
add_child(connect_dialog);
|
|
|
|
connect_dialog->set_undoredo(&editor_data->get_undo_redo());
|
2015-11-28 04:42:48 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
script_create_dialog = memnew( ScriptCreateDialog );
|
|
|
|
add_child(script_create_dialog);
|
|
|
|
script_create_dialog->connect("script_created",this,"_script_created");
|
2015-11-28 04:42:48 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
reparent_dialog = memnew( ReparentDialog );
|
|
|
|
add_child(reparent_dialog);
|
|
|
|
reparent_dialog->connect("reparent",this,"_node_reparent");
|
|
|
|
|
|
|
|
accept = memnew( AcceptDialog );
|
|
|
|
add_child(accept);
|
|
|
|
|
2015-06-06 20:44:38 +08:00
|
|
|
file = memnew( EditorFileDialog );
|
2014-02-10 09:10:30 +08:00
|
|
|
add_child(file);
|
|
|
|
file->connect("file_selected",this,"instance");
|
2014-04-10 11:18:27 +08:00
|
|
|
set_process_unhandled_key_input(true);
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
delete_dialog = memnew( ConfirmationDialog );
|
|
|
|
add_child(delete_dialog);
|
|
|
|
delete_dialog->connect("confirmed",this,"_delete_confirm");
|
2015-11-28 04:42:48 +08:00
|
|
|
|
2014-02-10 09:10:30 +08:00
|
|
|
import_subscene_dialog = memnew( EditorSubScene );
|
|
|
|
add_child(import_subscene_dialog);
|
|
|
|
import_subscene_dialog->connect("subscene_selected",this,"_import_subscene");
|
|
|
|
|
2015-11-28 04:42:48 +08:00
|
|
|
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");
|
|
|
|
|
2016-05-11 22:46:08 +08:00
|
|
|
|
2016-05-16 10:41:48 +08:00
|
|
|
menu = memnew( PopupMenu );
|
|
|
|
add_child(menu);
|
|
|
|
menu->connect("item_pressed",this,"_tool_selected");
|
2015-06-14 13:13:47 +08:00
|
|
|
first_enter=true;
|
2014-02-10 09:10:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
}
|