2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* scene_tree_dock.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:45:00 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00: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"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "animation_editor.h"
|
|
|
|
#include "core/io/resource_saver.h"
|
|
|
|
#include "editor/plugins/animation_player_editor_plugin.h"
|
|
|
|
#include "editor/plugins/canvas_item_editor_plugin.h"
|
|
|
|
#include "editor/plugins/script_editor_plugin.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "editor_node.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "editor_settings.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "globals.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "multi_node_edit.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "os/keyboard.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "scene/main/viewport.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/resources/packed_scene.h"
|
2015-08-02 15:29:37 +00:00
|
|
|
#include "script_editor_debugger.h"
|
2016-05-11 14:46:08 +00:00
|
|
|
|
2015-10-10 12:09:09 +00:00
|
|
|
void SceneTreeDock::_unhandled_key_input(InputEvent p_event) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-27 23:14:59 +00:00
|
|
|
if (get_viewport()->get_modal_stack_top())
|
|
|
|
return; //ignore because of modal window
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!p_event.key.pressed || p_event.key.echo)
|
|
|
|
return;
|
|
|
|
|
2016-06-19 19:33:42 +00:00
|
|
|
if (ED_IS_SHORTCUT("scene_tree/add_child_node", p_event)) {
|
|
|
|
_tool_selected(TOOL_NEW);
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (ED_IS_SHORTCUT("scene_tree/instance_scene", p_event)) {
|
2016-06-19 19:33:42 +00:00
|
|
|
_tool_selected(TOOL_INSTANCE);
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (ED_IS_SHORTCUT("scene_tree/change_node_type", p_event)) {
|
2016-06-19 19:33:42 +00:00
|
|
|
_tool_selected(TOOL_REPLACE);
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (ED_IS_SHORTCUT("scene_tree/duplicate", p_event)) {
|
2016-06-19 19:33:42 +00:00
|
|
|
_tool_selected(TOOL_DUPLICATE);
|
2017-03-29 21:36:58 +00:00
|
|
|
} else if (ED_IS_SHORTCUT("scene_tree/attach_script", p_event)) {
|
|
|
|
_tool_selected(TOOL_ATTACH_SCRIPT);
|
2017-03-29 20:23:49 +00:00
|
|
|
} else if(ED_IS_SHORTCUT("scene_tree/clear_script", p_event)) {
|
|
|
|
_tool_selected(TOOL_CLEAR_SCRIPT);
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (ED_IS_SHORTCUT("scene_tree/move_up", p_event)) {
|
2016-06-19 19:33:42 +00:00
|
|
|
_tool_selected(TOOL_MOVE_UP);
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (ED_IS_SHORTCUT("scene_tree/move_down", p_event)) {
|
2016-06-19 19:33:42 +00:00
|
|
|
_tool_selected(TOOL_MOVE_DOWN);
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (ED_IS_SHORTCUT("scene_tree/reparent", p_event)) {
|
2016-06-19 19:33:42 +00:00
|
|
|
_tool_selected(TOOL_REPARENT);
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (ED_IS_SHORTCUT("scene_tree/merge_from_scene", p_event)) {
|
2016-06-19 19:33:42 +00:00
|
|
|
_tool_selected(TOOL_MERGE_FROM_SCENE);
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (ED_IS_SHORTCUT("scene_tree/save_branch_as_scene", p_event)) {
|
2016-06-19 19:33:42 +00:00
|
|
|
_tool_selected(TOOL_NEW_SCENE_FROM);
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (ED_IS_SHORTCUT("scene_tree/delete_no_confirm", p_event)) {
|
2016-06-12 15:47:29 +00:00
|
|
|
_tool_selected(TOOL_ERASE, true);
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (ED_IS_SHORTCUT("scene_tree/copy_node_path", p_event)) {
|
2017-01-15 10:56:30 +00:00
|
|
|
_tool_selected(TOOL_COPY_NODE_PATH);
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (ED_IS_SHORTCUT("scene_tree/delete", p_event)) {
|
2016-06-12 15:47:29 +00:00
|
|
|
_tool_selected(TOOL_ERASE);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::instance(const String &p_file) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Node *parent = scene_tree->get_selected();
|
|
|
|
if (!parent || !edited_scene) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
current_option = -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
//accept->get_cancel()->hide();
|
2016-05-18 22:08:12 +00:00
|
|
|
accept->get_ok()->set_text(TTR("OK :("));
|
2016-05-04 01:25:37 +00:00
|
|
|
accept->set_text(TTR("No parent to instance a child at."));
|
2015-04-08 17:02:13 +00:00
|
|
|
accept->popup_centered_minsize();
|
2016-05-11 23:57:52 +00:00
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2016-05-11 23:57:52 +00:00
|
|
|
ERR_FAIL_COND(!parent);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-11 23:57:52 +00:00
|
|
|
Vector<String> scenes;
|
|
|
|
scenes.push_back(p_file);
|
2017-03-18 23:36:26 +00:00
|
|
|
_perform_instance_scenes(scenes, parent, -1);
|
2016-05-11 23:57:52 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::instance_scenes(const Vector<String> &p_files, Node *p_parent) {
|
2016-07-20 17:09:03 +00:00
|
|
|
|
|
|
|
Node *parent = p_parent;
|
|
|
|
|
|
|
|
if (!parent) {
|
|
|
|
parent = scene_tree->get_selected();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parent || !edited_scene) {
|
|
|
|
|
|
|
|
accept->get_ok()->set_text(TTR("OK"));
|
|
|
|
accept->set_text(TTR("No parent to instance the scenes at."));
|
|
|
|
accept->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
|
|
|
_perform_instance_scenes(p_files, parent, -1);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::_perform_instance_scenes(const Vector<String> &p_files, Node *parent, int p_pos) {
|
2015-01-19 20:47:50 +00:00
|
|
|
|
2016-05-11 23:57:52 +00:00
|
|
|
ERR_FAIL_COND(!parent);
|
2015-01-20 14:05:22 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Vector<Node *> instances;
|
2016-05-11 23:57:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool error = false;
|
2016-05-11 23:57:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_files.size(); i++) {
|
2016-05-11 23:57:52 +00:00
|
|
|
|
|
|
|
Ref<PackedScene> sdata = ResourceLoader::load(p_files[i]);
|
|
|
|
if (!sdata.is_valid()) {
|
2017-03-18 23:36:26 +00:00
|
|
|
current_option = -1;
|
2016-05-11 23:57:52 +00:00
|
|
|
//accept->get_cancel()->hide();
|
|
|
|
accept->get_ok()->set_text(TTR("Ugh"));
|
2017-03-18 23:36:26 +00:00
|
|
|
accept->set_text(vformat(TTR("Error loading scene from %s"), p_files[i]));
|
2015-04-08 17:02:13 +00:00
|
|
|
accept->popup_centered_minsize();
|
2017-03-18 23:36:26 +00:00
|
|
|
error = true;
|
2016-05-11 23:57:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *instanced_scene = sdata->instance(true);
|
2016-05-11 23:57:52 +00:00
|
|
|
if (!instanced_scene) {
|
2017-03-18 23:36:26 +00:00
|
|
|
current_option = -1;
|
2016-05-11 23:57:52 +00:00
|
|
|
//accept->get_cancel()->hide();
|
|
|
|
accept->get_ok()->set_text(TTR("Ugh"));
|
2017-03-18 23:36:26 +00:00
|
|
|
accept->set_text(vformat(TTR("Error instancing scene from %s"), p_files[i]));
|
2016-05-11 23:57:52 +00:00
|
|
|
accept->popup_centered_minsize();
|
2017-03-18 23:36:26 +00:00
|
|
|
error = true;
|
2016-05-11 23:57:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (edited_scene->get_filename() != "") {
|
2016-05-11 23:57:52 +00:00
|
|
|
|
|
|
|
if (_cyclical_dependency_exists(edited_scene->get_filename(), instanced_scene)) {
|
|
|
|
|
|
|
|
accept->get_ok()->set_text(TTR("Ok"));
|
2017-03-18 23:36:26 +00:00
|
|
|
accept->set_text(vformat(TTR("Cannot instance the scene '%s' because the current scene exists within one of its nodes."), p_files[i]));
|
2016-05-11 23:57:52 +00:00
|
|
|
accept->popup_centered_minsize();
|
2017-03-18 23:36:26 +00:00
|
|
|
error = true;
|
2016-05-11 23:57:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-01-20 14:05:22 +00:00
|
|
|
}
|
2016-05-11 23:57:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
instanced_scene->set_filename(Globals::get_singleton()->localize_path(p_files[i]));
|
2016-05-11 23:57:52 +00:00
|
|
|
|
|
|
|
instances.push_back(instanced_scene);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 23:57:52 +00:00
|
|
|
if (error) {
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < instances.size(); i++) {
|
2016-05-11 23:57:52 +00:00
|
|
|
memdelete(instances[i]);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-10 12:09:09 +00:00
|
|
|
//instanced_scene->generate_instance_state();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-11 23:57:52 +00:00
|
|
|
editor_data->get_undo_redo().create_action(TTR("Instance Scene(s)"));
|
2015-08-02 15:29:37 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < instances.size(); i++) {
|
2015-08-02 15:29:37 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *instanced_scene = instances[i];
|
2015-08-02 15:29:37 +00:00
|
|
|
|
2017-03-18 23:36:26 +00: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);
|
2016-05-11 23:57:52 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
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);
|
2016-05-11 23:57:52 +00:00
|
|
|
editor_data->get_undo_redo().add_do_reference(instanced_scene);
|
2017-03-18 23:36:26 +00:00
|
|
|
editor_data->get_undo_redo().add_undo_method(parent, "remove_child", instanced_scene);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-11 23:57:52 +00:00
|
|
|
String new_name = parent->validate_child_name(instanced_scene->get_name());
|
|
|
|
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
|
2017-03-18 23:36:26 +00:00
|
|
|
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));
|
2016-05-11 23:57:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
editor_data->get_undo_redo().commit_action();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::_replace_with_branch_scene(const String &p_file, Node *base) {
|
2016-10-11 14:54:46 +00:00
|
|
|
Ref<PackedScene> sdata = ResourceLoader::load(p_file);
|
|
|
|
if (!sdata.is_valid()) {
|
|
|
|
accept->get_ok()->set_text(TTR("Ugh"));
|
2017-03-18 23:36:26 +00:00
|
|
|
accept->set_text(vformat(TTR("Error loading scene from %s"), p_file));
|
2016-10-11 14:54:46 +00:00
|
|
|
accept->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *instanced_scene = sdata->instance(true);
|
2016-10-11 14:54:46 +00:00
|
|
|
if (!instanced_scene) {
|
|
|
|
accept->get_ok()->set_text(TTR("Ugh"));
|
2017-03-18 23:36:26 +00:00
|
|
|
accept->set_text(vformat(TTR("Error instancing scene from %s"), p_file));
|
2016-10-11 14:54:46 +00:00
|
|
|
accept->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node *parent = base->get_parent();
|
|
|
|
int pos = base->get_index();
|
|
|
|
memdelete(base);
|
|
|
|
parent->add_child(instanced_scene);
|
|
|
|
parent->move_child(instanced_scene, pos);
|
|
|
|
instanced_scene->set_owner(edited_scene);
|
|
|
|
editor_selection->clear();
|
|
|
|
editor_selection->add_node(instanced_scene);
|
|
|
|
scene_tree->set_selected(instanced_scene);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool SceneTreeDock::_cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node) {
|
2015-01-19 20:47:50 +00:00
|
|
|
int childCount = p_desired_node->get_child_count();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_desired_node->get_filename() == p_target_scene_path) {
|
2015-01-19 20:47:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < childCount; i++) {
|
|
|
|
Node *child = p_desired_node->get_child(i);
|
2015-01-19 20:47:50 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (_cyclical_dependency_exists(p_target_scene_path, child)) {
|
2015-01-19 20:47:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-11 05:08:32 +00:00
|
|
|
static String _get_name_num_separator() {
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (EditorSettings::get_singleton()->get("scenetree_editor/duplicate_node_name_num_separator").operator int()) {
|
2015-01-11 05:08:32 +00:00
|
|
|
case 0: return "";
|
|
|
|
case 1: return " ";
|
|
|
|
case 2: return "_";
|
|
|
|
case 3: return "-";
|
|
|
|
}
|
|
|
|
return " ";
|
|
|
|
}
|
|
|
|
|
2014-05-09 10:50:48 +00:00
|
|
|
void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
current_option = p_tool;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_tool) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case TOOL_NEW: {
|
|
|
|
|
2015-10-10 12:09:09 +00:00
|
|
|
//if (!_validate_no_foreign())
|
|
|
|
// break;
|
2016-07-10 11:19:15 +00:00
|
|
|
create_dialog->popup(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case TOOL_INSTANCE: {
|
|
|
|
|
|
|
|
Node *scene = edited_scene;
|
|
|
|
|
|
|
|
if (!scene) {
|
|
|
|
|
2016-05-16 15:23:40 +00:00
|
|
|
EditorNode::get_singleton()->new_inherited_scene();
|
|
|
|
|
|
|
|
/* should be legal now
|
2014-02-10 01:10:30 +00:00
|
|
|
current_option=-1;
|
|
|
|
//confirmation->get_cancel()->hide();
|
2016-05-20 23:18:35 +00:00
|
|
|
accept->get_ok()->set_text("I see..");
|
2014-02-10 01:10:30 +00:00
|
|
|
accept->set_text("This operation can't be done without a tree root.");
|
2015-04-08 17:02:13 +00:00
|
|
|
accept->popup_centered_minsize();
|
2016-05-16 15:23:40 +00:00
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-10-10 12:09:09 +00:00
|
|
|
//if (!_validate_no_foreign())
|
|
|
|
// break;
|
2014-09-03 02:13:40 +00:00
|
|
|
|
2015-06-06 12:44:38 +00:00
|
|
|
file->set_mode(EditorFileDialog::MODE_OPEN_FILE);
|
2014-02-10 01:10:30 +00:00
|
|
|
List<String> extensions;
|
2017-03-18 23:36:26 +00:00
|
|
|
ResourceLoader::get_recognized_extensions_for_type("PackedScene", &extensions);
|
2014-02-10 01:10:30 +00:00
|
|
|
file->clear_filters();
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < extensions.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
file->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//file->set_current_path(current_path);
|
|
|
|
file->popup_centered_ratio();
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case TOOL_REPLACE: {
|
|
|
|
|
2016-07-10 11:19:15 +00:00
|
|
|
create_dialog->popup(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case TOOL_CONNECT: {
|
|
|
|
|
|
|
|
Node *current = scene_tree->get_selected();
|
|
|
|
if (!current)
|
|
|
|
break;
|
|
|
|
|
2015-10-10 12:09:09 +00:00
|
|
|
//if (!_validate_no_foreign())
|
|
|
|
// break;
|
2016-06-04 00:03:09 +00:00
|
|
|
//connect_dialog->popup_centered_ratio();
|
|
|
|
//connect_dialog->set_node(current);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case TOOL_GROUP: {
|
|
|
|
|
|
|
|
Node *current = scene_tree->get_selected();
|
|
|
|
if (!current)
|
|
|
|
break;
|
2015-10-10 12:09:09 +00:00
|
|
|
//if (!_validate_no_foreign())
|
|
|
|
// break;
|
2016-06-04 16:17:56 +00:00
|
|
|
//groups_editor->set_current(current);
|
|
|
|
//groups_editor->popup_centered_ratio();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2017-03-29 21:36:58 +00:00
|
|
|
case TOOL_ATTACH_SCRIPT: {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Node *selected = scene_tree->get_selected();
|
|
|
|
if (!selected)
|
|
|
|
break;
|
|
|
|
|
2015-10-10 12:09:09 +00:00
|
|
|
//if (!_validate_no_foreign())
|
|
|
|
// break;
|
2014-09-03 02:13:40 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Ref<Script> existing = selected->get_script();
|
|
|
|
if (existing.is_valid())
|
|
|
|
editor->push_item(existing.ptr());
|
|
|
|
else {
|
|
|
|
String path = selected->get_filename();
|
2017-03-18 23:36:26 +00:00
|
|
|
script_create_dialog->config(selected->get_type(), path);
|
|
|
|
script_create_dialog->popup_centered(Size2(300, 290));
|
2014-02-10 01:10:30 +00:00
|
|
|
//script_create_dialog->popup_centered_minsize();
|
|
|
|
}
|
|
|
|
|
2017-03-29 20:23:49 +00:00
|
|
|
} break;
|
|
|
|
case TOOL_CLEAR_SCRIPT: {
|
|
|
|
Node *selected = scene_tree->get_selected();
|
|
|
|
if(!selected)
|
|
|
|
break;
|
|
|
|
|
|
|
|
Ref<Script> existing = selected->get_script();
|
|
|
|
if(existing.is_valid()) {
|
|
|
|
const RefPtr empty;
|
|
|
|
selected->set_script(empty);
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case TOOL_MOVE_UP:
|
|
|
|
case TOOL_MOVE_DOWN: {
|
|
|
|
|
|
|
|
if (!scene_tree->get_selected())
|
|
|
|
break;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (scene_tree->get_selected() == edited_scene) {
|
2014-09-03 02:13:40 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
current_option = -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
//accept->get_cancel()->hide();
|
2016-05-04 01:25:37 +00:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
2016-05-20 23:18:35 +00:00
|
|
|
accept->set_text(TTR("This operation can't be done on the tree root."));
|
2015-04-08 17:02:13 +00:00
|
|
|
accept->popup_centered_minsize();
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-09-03 02:13:40 +00:00
|
|
|
if (!_validate_no_foreign())
|
|
|
|
break;
|
|
|
|
|
2014-12-18 02:38:24 +00:00
|
|
|
bool MOVING_DOWN = (p_tool == TOOL_MOVE_DOWN);
|
|
|
|
bool MOVING_UP = !MOVING_DOWN;
|
|
|
|
|
2014-12-18 04:46:03 +00:00
|
|
|
Node *common_parent = scene_tree->get_selected()->get_parent();
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Node *> selection = editor_selection->get_selected_node_list();
|
|
|
|
selection.sort_custom<Node::Comparator>(); // sort by index
|
2014-12-18 02:38:24 +00:00
|
|
|
if (MOVING_DOWN)
|
|
|
|
selection.invert();
|
|
|
|
|
2014-12-18 04:46:03 +00:00
|
|
|
int lowest_id = common_parent->get_child_count() - 1;
|
|
|
|
int highest_id = 0;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-12-18 02:38:24 +00:00
|
|
|
int index = E->get()->get_index();
|
|
|
|
|
2014-12-18 04:46:03 +00: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 02:38:24 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 04:46:03 +00: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 02:38:24 +00:00
|
|
|
|
2016-05-04 01:25:37 +00: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 04:52:27 +00:00
|
|
|
|
2014-12-18 02:38:24 +00:00
|
|
|
for (int i = 0; i < selection.size(); i++) {
|
|
|
|
Node *top_node = selection[i];
|
|
|
|
Node *bottom_node = selection[selection.size() - 1 - i];
|
2016-01-17 23:03:57 +00:00
|
|
|
|
2014-12-18 02:38:24 +00:00
|
|
|
ERR_FAIL_COND(!top_node->get_parent());
|
|
|
|
ERR_FAIL_COND(!bottom_node->get_parent());
|
|
|
|
|
|
|
|
int bottom_node_pos = bottom_node->get_index();
|
2016-07-06 17:04:21 +00:00
|
|
|
int top_node_pos_next = top_node->get_index() + (MOVING_DOWN ? 1 : -1);
|
2014-12-18 02:38:24 +00:00
|
|
|
|
|
|
|
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 04:52:27 +00:00
|
|
|
editor_data->get_undo_redo().commit_action();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case TOOL_DUPLICATE: {
|
|
|
|
|
|
|
|
if (!edited_scene)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (editor_selection->is_selected(edited_scene)) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
current_option = -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
//accept->get_cancel()->hide();
|
2016-05-04 01:25:37 +00:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
2016-05-20 23:18:35 +00:00
|
|
|
accept->set_text(TTR("This operation can't be done on the tree root."));
|
2015-04-08 17:02:13 +00:00
|
|
|
accept->popup_centered_minsize();
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-09-03 02:13:40 +00:00
|
|
|
if (!_validate_no_foreign())
|
|
|
|
break;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Node *> selection = editor_selection->get_selected_node_list();
|
|
|
|
if (selection.size() == 0)
|
2016-11-04 15:52:53 +00:00
|
|
|
break;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Node *> reselect;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
editor_data->get_undo_redo().create_action(TTR("Duplicate Node(s)"));
|
2017-03-18 23:36:26 +00:00
|
|
|
editor_data->get_undo_redo().add_do_method(editor_selection, "clear");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *dupsingle = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Node *node = E->get();
|
|
|
|
Node *parent = node->get_parent();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Node *> owned;
|
|
|
|
node->get_owned_by(node->get_owner(), &owned);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Map<Node *, Node *> duplimap;
|
|
|
|
Node *dup = _duplicate(node, duplimap);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
ERR_CONTINUE(!dup);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (selection.size() == 1)
|
|
|
|
dupsingle = dup;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String name = node->get_name();
|
|
|
|
|
|
|
|
String nums;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = name.length() - 1; i >= 0; i--) {
|
|
|
|
CharType n = name[i];
|
|
|
|
if (n >= '0' && n <= '9') {
|
|
|
|
nums = String::chr(name[i]) + nums;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int num = nums.to_int();
|
|
|
|
if (num < 1)
|
|
|
|
num = 1;
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
|
|
|
num++;
|
|
|
|
|
2015-01-11 05:08:32 +00:00
|
|
|
String nnsep = _get_name_num_separator();
|
2017-03-18 23:36:26 +00:00
|
|
|
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());
|
2015-01-11 05:08:32 +00:00
|
|
|
}
|
|
|
|
String attempt = (name + nnsep + itos(num)).strip_edges();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (parent->has_node(attempt)) {
|
2014-02-10 01:10:30 +00:00
|
|
|
num++;
|
2015-01-11 05:08:32 +00:00
|
|
|
attempt = (name + nnsep + itos(num)).strip_edges();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dup->set_name(attempt);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
editor_data->get_undo_redo().add_do_method(parent, "_add_child_below_node", node, dup);
|
|
|
|
for (List<Node *>::Element *F = owned.front(); F; F = F->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!duplimap.has(F->get())) {
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *d = duplimap[F->get()];
|
|
|
|
editor_data->get_undo_redo().add_do_method(d, "set_owner", node->get_owner());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
editor_data->get_undo_redo().add_do_method(editor_selection, "add_node", dup);
|
|
|
|
editor_data->get_undo_redo().add_undo_method(parent, "remove_child", dup);
|
2014-02-10 01:10:30 +00:00
|
|
|
editor_data->get_undo_redo().add_do_reference(dup);
|
|
|
|
|
2015-08-02 15:29:37 +00:00
|
|
|
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
editor_data->get_undo_redo().add_do_method(sed, "live_debug_duplicate_node", edited_scene->get_path_to(node), attempt);
|
|
|
|
editor_data->get_undo_redo().add_undo_method(sed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(parent)) + "/" + attempt));
|
2015-08-02 15:29:37 +00:00
|
|
|
|
2014-02-10 01:10:30 +00: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;
|
|
|
|
|
|
|
|
if (editor_selection->is_selected(edited_scene)) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
current_option = -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
//confirmation->get_cancel()->hide();
|
2016-05-04 01:25:37 +00:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
2016-05-20 23:18:35 +00:00
|
|
|
accept->set_text(TTR("This operation can't be done on the tree root."));
|
2015-04-08 17:02:13 +00:00
|
|
|
accept->popup_centered_minsize();
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-09-03 02:13:40 +00:00
|
|
|
if (!_validate_no_foreign())
|
|
|
|
break;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Node *> nodes = editor_selection->get_selected_node_list();
|
|
|
|
Set<Node *> nodeset;
|
|
|
|
for (List<Node *>::Element *E = nodes.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
nodeset.insert(E->get());
|
|
|
|
}
|
|
|
|
reparent_dialog->popup_centered_ratio();
|
2017-03-18 23:36:26 +00:00
|
|
|
reparent_dialog->set_current(nodeset);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-08-25 03:08:45 +00:00
|
|
|
} break;
|
|
|
|
case TOOL_MULTI_EDIT: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *root = EditorNode::get_singleton()->get_edited_scene();
|
2015-08-25 03:08:45 +00:00
|
|
|
if (!root)
|
|
|
|
break;
|
2017-03-18 23:36:26 +00:00
|
|
|
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()) {
|
2015-08-25 03:08:45 +00:00
|
|
|
mne->add_node(root->get_path_to(E->key()));
|
|
|
|
}
|
|
|
|
|
|
|
|
EditorNode::get_singleton()->push_item(mne.ptr());
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2016-06-12 02:00:06 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
case TOOL_ERASE: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Node *> remove_list = editor_selection->get_selected_node_list();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (remove_list.empty())
|
|
|
|
return;
|
|
|
|
|
2014-09-03 02:13:40 +00:00
|
|
|
if (!_validate_no_foreign())
|
|
|
|
break;
|
|
|
|
|
2014-05-09 10:50:48 +00: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 01:25:37 +00:00
|
|
|
delete_dialog->set_text(TTR("Delete Node(s)?"));
|
2015-04-08 17:02:13 +00:00
|
|
|
delete_dialog->popup_centered_minsize();
|
2014-05-09 10:50:48 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-11-27 20:42:48 +00:00
|
|
|
} break;
|
2016-05-27 17:18:40 +00:00
|
|
|
case TOOL_MERGE_FROM_SCENE: {
|
|
|
|
|
|
|
|
EditorNode::get_singleton()->merge_from_scene();
|
|
|
|
} break;
|
2015-11-27 20:42:48 +00:00
|
|
|
case TOOL_NEW_SCENE_FROM: {
|
|
|
|
|
|
|
|
Node *scene = editor_data->get_edited_scene_root();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-11-27 20:42:48 +00:00
|
|
|
if (!scene) {
|
2016-05-04 01:25:37 +00:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
2016-05-20 23:18:35 +00:00
|
|
|
accept->set_text(TTR("This operation can't be done without a scene."));
|
2015-11-27 20:42:48 +00:00
|
|
|
accept->popup_centered_minsize();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Node *> selection = editor_selection->get_selected_node_list();
|
2015-11-27 20:42:48 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (selection.size() != 1) {
|
2016-05-04 01:25:37 +00:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
|
|
|
accept->set_text(TTR("This operation requires a single selected node."));
|
2015-11-27 20:42:48 +00:00
|
|
|
accept->popup_centered_minsize();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node *tocopy = selection.front()->get();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (tocopy == scene) {
|
2017-01-29 19:27:14 +00:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
|
|
|
accept->set_text(TTR("Can not perform with the root node."));
|
|
|
|
accept->popup_centered_minsize();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (tocopy != editor_data->get_edited_scene_root() && tocopy->get_filename() != "") {
|
2016-05-04 01:25:37 +00:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
2016-05-20 23:18:35 +00:00
|
|
|
accept->set_text(TTR("This operation can't be done on instanced scenes."));
|
2015-11-27 20:42:48 +00:00
|
|
|
accept->popup_centered_minsize();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_scene_from_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
|
|
|
|
|
|
|
|
List<String> extensions;
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<PackedScene> sd = memnew(PackedScene);
|
|
|
|
ResourceSaver::get_recognized_extensions(sd, &extensions);
|
2015-11-27 20:42:48 +00:00
|
|
|
new_scene_from_dialog->clear_filters();
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < extensions.size(); i++) {
|
|
|
|
new_scene_from_dialog->add_filter("*." + extensions[i] + " ; " + extensions[i].to_upper());
|
2015-11-27 20:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String existing;
|
|
|
|
if (extensions.size()) {
|
2016-05-23 13:27:58 +00:00
|
|
|
String root_name(tocopy->get_name());
|
2017-03-18 23:36:26 +00:00
|
|
|
existing = root_name + "." + extensions.front()->get().to_lower();
|
2015-11-27 20:42:48 +00:00
|
|
|
}
|
|
|
|
new_scene_from_dialog->set_current_path(existing);
|
|
|
|
|
|
|
|
new_scene_from_dialog->popup_centered_ratio();
|
2016-05-04 01:25:37 +00:00
|
|
|
new_scene_from_dialog->set_title(TTR("Save New Scene As.."));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
2017-03-18 23:36:26 +00:00
|
|
|
case TOOL_COPY_NODE_PATH: {
|
|
|
|
List<Node *> selection = editor_selection->get_selected_node_list();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (List<Node *>::Element *e = selection.front()) {
|
|
|
|
if (Node *node = e->get()) {
|
2017-01-15 10:56:30 +00:00
|
|
|
Node *root = EditorNode::get_singleton()->get_edited_scene();
|
|
|
|
NodePath path = root->get_path().rel_path_to(node->get_path());
|
|
|
|
OS::get_singleton()->set_clipboard(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTreeDock::_notification(int p_what) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_what) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-06-14 05:13:47 +00:00
|
|
|
case NOTIFICATION_READY: {
|
|
|
|
|
|
|
|
if (!first_enter)
|
|
|
|
break;
|
2017-03-18 23:36:26 +00:00
|
|
|
first_enter = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
CanvasItemEditorPlugin *canvas_item_plugin = editor_data->get_editor("2D")->cast_to<CanvasItemEditorPlugin>();
|
2015-06-14 05:13:47 +00:00
|
|
|
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");
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
button_add->set_icon(get_icon("Add", "EditorIcons"));
|
|
|
|
button_instance->set_icon(get_icon("Instance", "EditorIcons"));
|
2017-03-29 07:06:53 +00:00
|
|
|
button_create_script->set_icon(get_icon("ScriptCreate","EditorIcons"));
|
2017-03-29 20:23:49 +00:00
|
|
|
button_clear_script->set_icon(get_icon("Remove", "EditorIcons"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
filter_icon->set_texture(get_icon("Zoom", "EditorIcons"));
|
2016-05-16 15:23:40 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
EditorNode::get_singleton()->get_editor_selection()->connect("selection_changed", this, "_selection_changed");
|
2015-08-25 03:08:45 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::_load_request(const String &p_path) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
editor->open_request(p_path);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::_script_open_request(const Ref<Script> &p_script) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
editor->edit_resource(p_script);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTreeDock::_node_selected() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *node = scene_tree->get_selected();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (!node) {
|
|
|
|
|
|
|
|
editor->push_item(NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
editor->push_item(node);
|
|
|
|
}
|
|
|
|
|
2014-09-21 15:56:19 +00:00
|
|
|
void SceneTreeDock::_node_renamed() {
|
|
|
|
|
|
|
|
_node_selected();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *SceneTreeDock::_duplicate(Node *p_node, Map<Node *, Node *> &duplimap) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *node = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_node->get_filename() != "") { //an instance
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<PackedScene> sd = ResourceLoader::load(p_node->get_filename());
|
|
|
|
ERR_FAIL_COND_V(!sd.is_valid(), NULL);
|
2015-10-10 12:09:09 +00:00
|
|
|
node = sd->instance(true);
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(!node, NULL);
|
2017-01-29 10:49:58 +00:00
|
|
|
node->set_scene_instance_load_placeholder(p_node->get_scene_instance_load_placeholder());
|
2015-10-10 12:09:09 +00:00
|
|
|
//node->generate_instance_state();
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
Object *obj = ObjectTypeDB::instance(p_node->get_type());
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(!obj, NULL);
|
2014-02-10 01:10:30 +00:00
|
|
|
node = obj->cast_to<Node>();
|
|
|
|
if (!node)
|
|
|
|
memdelete(obj);
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_COND_V(!node, NULL);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
List<PropertyInfo> plist;
|
|
|
|
|
|
|
|
p_node->get_property_list(&plist);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
|
|
|
String name = E->get().name;
|
2017-03-18 23:36:26 +00:00
|
|
|
node->set(name, p_node->get(name));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2014-09-21 04:43:42 +00:00
|
|
|
List<Node::GroupInfo> group_info;
|
|
|
|
p_node->get_groups(&group_info);
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Node::GroupInfo>::Element *E = group_info.front(); E; E = E->next()) {
|
2014-09-21 04:43:42 +00:00
|
|
|
|
|
|
|
if (E->get().persistent)
|
2017-03-18 23:36:26 +00:00
|
|
|
node->add_to_group(E->get().name, true);
|
2014-09-21 04:43:42 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
node->set_name(p_node->get_name());
|
2017-03-18 23:36:26 +00:00
|
|
|
duplimap[p_node] = node;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_node->get_child_count(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Node *child = p_node->get_child(i);
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_node->get_owner() != child->get_owner())
|
2014-02-10 01:10:30 +00:00
|
|
|
continue; //don't bother with not in-scene nodes.
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *dup = _duplicate(child, duplimap);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!dup) {
|
|
|
|
memdelete(node);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
node->add_child(dup);
|
|
|
|
}
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::_set_owners(Node *p_owner, const Array &p_nodes) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_nodes.size(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Object *obj = p_nodes[i];
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!obj)
|
|
|
|
continue;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *n = obj->cast_to<Node>();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!n)
|
|
|
|
continue;
|
|
|
|
n->set_owner(p_owner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::_fill_path_renames(Vector<StringName> base_path, Vector<StringName> new_base_path, Node *p_node, List<Pair<NodePath, NodePath> > *p_renames) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
base_path.push_back(p_node->get_name());
|
|
|
|
if (new_base_path.size())
|
|
|
|
new_base_path.push_back(p_node->get_name());
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
NodePath from(base_path, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
NodePath to;
|
|
|
|
if (new_base_path.size())
|
2017-03-18 23:36:26 +00:00
|
|
|
to = NodePath(new_base_path, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Pair<NodePath, NodePath> npp;
|
|
|
|
npp.first = from;
|
|
|
|
npp.second = to;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
p_renames->push_back(npp);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_node->get_child_count(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_fill_path_renames(base_path, new_base_path, p_node->get_child(i), p_renames);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::fill_path_renames(Node *p_node, Node *p_new_parent, List<Pair<NodePath, NodePath> > *p_renames) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!bool(EDITOR_DEF("animation/autorename_animation_tracks", true)))
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
Vector<StringName> base_path;
|
|
|
|
Node *n = p_node->get_parent();
|
2017-03-18 23:36:26 +00:00
|
|
|
while (n) {
|
2014-02-10 01:10:30 +00:00
|
|
|
base_path.push_back(n->get_name());
|
2017-03-18 23:36:26 +00:00
|
|
|
n = n->get_parent();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
base_path.invert();
|
|
|
|
|
|
|
|
Vector<StringName> new_base_path;
|
|
|
|
if (p_new_parent) {
|
|
|
|
n = p_new_parent;
|
2017-03-18 23:36:26 +00:00
|
|
|
while (n) {
|
2014-02-10 01:10:30 +00:00
|
|
|
new_base_path.push_back(n->get_name());
|
2017-03-18 23:36:26 +00:00
|
|
|
n = n->get_parent();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
new_base_path.invert();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_fill_path_renames(base_path, new_base_path, p_node, p_renames);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::perform_node_renames(Node *p_base, List<Pair<NodePath, NodePath> > *p_renames, Map<Ref<Animation>, Set<int> > *r_rem_anims) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Map<Ref<Animation>, Set<int> > rem_anims;
|
|
|
|
|
|
|
|
if (!r_rem_anims)
|
2017-03-18 23:36:26 +00:00
|
|
|
r_rem_anims = &rem_anims;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!bool(EDITOR_DEF("animation/autorename_animation_tracks", true)))
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!p_base) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_base = edited_scene;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!p_base)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (p_base->cast_to<AnimationPlayer>()) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
AnimationPlayer *ap = p_base->cast_to<AnimationPlayer>();
|
2014-02-10 01:10:30 +00:00
|
|
|
List<StringName> anims;
|
|
|
|
ap->get_animation_list(&anims);
|
|
|
|
Node *root = ap->get_node(ap->get_root());
|
|
|
|
|
|
|
|
if (root) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
NodePath root_path = root->get_path();
|
|
|
|
NodePath new_root_path = root_path;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Pair<NodePath, NodePath> >::Element *E = p_renames->front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (E->get().first == root_path) {
|
|
|
|
new_root_path = E->get().second;
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (new_root_path != NodePath()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//will not be erased
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<StringName>::Element *E = anims.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<Animation> anim = ap->get_animation(E->get());
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!r_rem_anims->has(anim)) {
|
2017-03-18 23:36:26 +00:00
|
|
|
r_rem_anims->insert(anim, Set<int>());
|
2014-02-10 01:10:30 +00:00
|
|
|
Set<int> &ran = r_rem_anims->find(anim)->get();
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < anim->get_track_count(); i++)
|
2014-02-10 01:10:30 +00:00
|
|
|
ran.insert(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
Set<int> &ran = r_rem_anims->find(anim)->get();
|
|
|
|
|
|
|
|
if (anim.is_null())
|
|
|
|
continue;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < anim->get_track_count(); i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
NodePath track_np = anim->track_get_path(i);
|
2014-02-10 01:10:30 +00:00
|
|
|
Node *n = root->get_node(track_np);
|
|
|
|
if (!n) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
NodePath old_np = n->get_path();
|
|
|
|
|
|
|
|
if (!ran.has(i))
|
|
|
|
continue; //channel was removed
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Pair<NodePath, NodePath> >::Element *E = p_renames->front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (E->get().first == old_np) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (E->get().second == NodePath()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//will be erased
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx = 0;
|
|
|
|
Set<int>::Element *EI = ran.front();
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND(!EI); //bug
|
2017-03-18 23:36:26 +00:00
|
|
|
while (EI->get() != i) {
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2017-03-18 23:36:26 +00:00
|
|
|
EI = EI->next();
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND(!EI); //another bug
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
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++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
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));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ran.erase(i); //byebye channel
|
|
|
|
|
|
|
|
} else {
|
|
|
|
//will be renamed
|
|
|
|
NodePath rel_path = new_root_path.rel_path_to(E->get().second);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
NodePath new_path = NodePath(rel_path.get_names(), track_np.get_subnames(), false, track_np.get_property());
|
|
|
|
if (new_path == track_np)
|
2014-02-10 01:10:30 +00:00
|
|
|
continue; //bleh
|
2017-03-18 23:36:26 +00:00
|
|
|
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);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_base->get_child_count(); i++)
|
|
|
|
perform_node_renames(p_base->get_child(i), p_renames, r_rem_anims);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::_node_prerenamed(Node *p_node, const String &p_new_name) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Pair<NodePath, NodePath> > path_renames;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Vector<StringName> base_path;
|
|
|
|
Node *n = p_node->get_parent();
|
2017-03-18 23:36:26 +00:00
|
|
|
while (n) {
|
2014-02-10 01:10:30 +00:00
|
|
|
base_path.push_back(n->get_name());
|
2017-03-18 23:36:26 +00:00
|
|
|
n = n->get_parent();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
base_path.invert();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Vector<StringName> new_base_path = base_path;
|
2014-02-10 01:10:30 +00:00
|
|
|
base_path.push_back(p_node->get_name());
|
|
|
|
|
|
|
|
new_base_path.push_back(p_new_name);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Pair<NodePath, NodePath> npp;
|
|
|
|
npp.first = NodePath(base_path, true);
|
|
|
|
npp.second = NodePath(new_base_path, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
path_renames.push_back(npp);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
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);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
perform_node_renames(NULL, &path_renames);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2014-09-03 02:13:40 +00:00
|
|
|
bool SceneTreeDock::_validate_no_foreign() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Node *> selection = editor_selection->get_selected_node_list();
|
2014-09-03 02:13:40 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2014-09-03 02:13:40 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (E->get() != edited_scene && E->get()->get_owner() != edited_scene) {
|
2014-09-03 02:13:40 +00:00
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
accept->get_ok()->set_text(TTR("Makes Sense!"));
|
|
|
|
accept->set_text(TTR("Can't operate on nodes from a foreign scene!"));
|
2015-04-08 17:02:13 +00:00
|
|
|
accept->popup_centered_minsize();
|
2014-09-03 02:13:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-10-10 12:09:09 +00:00
|
|
|
|
2017-03-18 23:36:26 +00: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 12:09:09 +00:00
|
|
|
|
2016-05-04 01:25:37 +00: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 12:09:09 +00:00
|
|
|
accept->popup_centered_minsize();
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-03 02:13:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::_node_reparent(NodePath p_path, bool p_keep_global_xform) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Node *new_parent = scene_root->get_node(p_path);
|
|
|
|
ERR_FAIL_COND(!new_parent);
|
|
|
|
|
2016-05-11 14:46:08 +00:00
|
|
|
//ok all valid
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Node *> selection = editor_selection->get_selected_node_list();
|
2016-05-11 14:46:08 +00:00
|
|
|
|
|
|
|
if (selection.empty())
|
|
|
|
return; //nothing to reparent
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Vector<Node *> nodes;
|
2016-05-11 14:46:08 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
|
2016-05-11 14:46:08 +00:00
|
|
|
nodes.push_back(E->get());
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_do_reparent(new_parent, -1, nodes, p_keep_global_xform);
|
2016-05-11 14:46:08 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, Vector<Node *> p_nodes, bool p_keep_global_xform) {
|
2016-05-11 14:46:08 +00:00
|
|
|
|
|
|
|
Node *new_parent = p_new_parent;
|
|
|
|
ERR_FAIL_COND(!new_parent);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *validate = new_parent;
|
|
|
|
while (validate) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_nodes.find(validate) != -1) {
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_EXPLAIN("Selection changed at some point.. can't reparent");
|
|
|
|
ERR_FAIL();
|
|
|
|
return;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
validate = validate->get_parent();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//ok all valid
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Node *> selection = editor_selection->get_selected_node_list();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_nodes.size() == 0)
|
2014-02-10 01:10:30 +00:00
|
|
|
return; //nothing to reparent
|
|
|
|
|
|
|
|
//sort by tree order, so re-adding is easy
|
2016-05-11 14:46:08 +00:00
|
|
|
p_nodes.sort_custom<Node::Comparator>();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
editor_data->get_undo_redo().create_action(TTR("Reparent Node"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Pair<NodePath, NodePath> > path_renames;
|
2016-10-08 18:37:05 +00:00
|
|
|
Vector<StringName> former_names;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int inc = 0;
|
2016-07-01 02:19:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int ni = 0; ni < p_nodes.size(); ni++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//no undo for now, sorry
|
2016-05-11 14:46:08 +00:00
|
|
|
Node *node = p_nodes[ni];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
fill_path_renames(node, new_parent, &path_renames);
|
2016-10-08 18:37:05 +00:00
|
|
|
former_names.push_back(node->get_name());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Node *> owned;
|
|
|
|
node->get_owned_by(node->get_owner(), &owned);
|
2014-02-10 01:10:30 +00:00
|
|
|
Array owners;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Node *>::Element *E = owned.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
owners.push_back(E->get());
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (new_parent == node->get_parent() && node->get_index() < p_position_in_parent + ni) {
|
2016-07-01 02:19:44 +00:00
|
|
|
//if child will generate a gap when moved, adjust
|
|
|
|
inc--;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
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 15:29:37 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_position_in_parent >= 0)
|
|
|
|
editor_data->get_undo_redo().add_do_method(new_parent, "move_child", node, p_position_in_parent + inc);
|
2016-05-11 14:46:08 +00:00
|
|
|
|
2015-08-02 15:29:37 +00:00
|
|
|
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
|
|
|
|
String new_name = new_parent->validate_child_name(node->get_name());
|
2017-03-18 23:36:26 +00: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 15:29:37 +00:00
|
|
|
|
2016-01-02 14:57:47 +00:00
|
|
|
if (p_keep_global_xform) {
|
|
|
|
if (node->cast_to<Node2D>())
|
2017-03-18 23:36:26 +00:00
|
|
|
editor_data->get_undo_redo().add_do_method(node, "set_global_transform", node->cast_to<Node2D>()->get_global_transform());
|
2016-01-02 14:57:47 +00:00
|
|
|
if (node->cast_to<Spatial>())
|
2017-03-18 23:36:26 +00:00
|
|
|
editor_data->get_undo_redo().add_do_method(node, "set_global_transform", node->cast_to<Spatial>()->get_global_transform());
|
2016-07-06 17:04:21 +00:00
|
|
|
if (node->cast_to<Control>())
|
2017-03-18 23:36:26 +00:00
|
|
|
editor_data->get_undo_redo().add_do_method(node, "set_global_pos", node->cast_to<Control>()->get_global_pos());
|
2016-01-02 14:57:47 +00:00
|
|
|
}
|
2015-08-02 15:29:37 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
editor_data->get_undo_redo().add_do_method(this, "_set_owners", edited_scene, owners);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00: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 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
editor_data->get_undo_redo().add_undo_method(new_parent, "remove_child", node);
|
|
|
|
editor_data->get_undo_redo().add_undo_method(node, "set_name", former_names[ni]);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-07-01 02:19:44 +00:00
|
|
|
inc++;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//add and move in a second step.. (so old order is preserved)
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int ni = 0; ni < p_nodes.size(); ni++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-11 14:46:08 +00:00
|
|
|
Node *node = p_nodes[ni];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Node *> owned;
|
|
|
|
node->get_owned_by(node->get_owner(), &owned);
|
2014-02-10 01:10:30 +00:00
|
|
|
Array owners;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Node *>::Element *E = owned.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
owners.push_back(E->get());
|
|
|
|
}
|
|
|
|
|
|
|
|
int child_pos = node->get_position_in_parent();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
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);
|
|
|
|
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 01:10:30 +00:00
|
|
|
|
2016-01-02 14:57:47 +00:00
|
|
|
if (p_keep_global_xform) {
|
|
|
|
if (node->cast_to<Node2D>())
|
2017-03-18 23:36:26 +00:00
|
|
|
editor_data->get_undo_redo().add_undo_method(node, "set_transform", node->cast_to<Node2D>()->get_transform());
|
2016-01-02 14:57:47 +00:00
|
|
|
if (node->cast_to<Spatial>())
|
2017-03-18 23:36:26 +00:00
|
|
|
editor_data->get_undo_redo().add_undo_method(node, "set_transform", node->cast_to<Spatial>()->get_transform());
|
2016-07-06 17:04:21 +00:00
|
|
|
if (node->cast_to<Control>())
|
2017-03-18 23:36:26 +00:00
|
|
|
editor_data->get_undo_redo().add_undo_method(node, "set_pos", node->cast_to<Control>()->get_pos());
|
2016-01-02 14:57:47 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
perform_node_renames(NULL, &path_renames);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
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() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Node *> remove_list = editor_selection->get_selected_node_list();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (remove_list.empty())
|
|
|
|
return;
|
|
|
|
|
2016-03-29 23:02:53 +00:00
|
|
|
editor->get_editor_plugins_over()->make_visible(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
editor_data->get_undo_redo().create_action(TTR("Remove Node(s)"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool entire_scene = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Node *>::Element *E = remove_list.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (E->get() == edited_scene) {
|
|
|
|
entire_scene = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (entire_scene) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
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());
|
2014-02-10 01:10:30 +00:00
|
|
|
editor_data->get_undo_redo().add_undo_reference(edited_scene);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
remove_list.sort_custom<Node::Comparator>(); //sort nodes to keep positions
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Pair<NodePath, NodePath> > path_renames;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//delete from animation
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Node *>::Element *E = remove_list.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
Node *n = E->get();
|
2014-11-06 00:20:42 +00:00
|
|
|
if (!n->is_inside_tree() || !n->get_parent())
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
fill_path_renames(n, NULL, &path_renames);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
perform_node_renames(NULL, &path_renames);
|
2014-02-10 01:10:30 +00:00
|
|
|
//delete for read
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Node *>::Element *E = remove_list.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
Node *n = E->get();
|
2014-11-06 00:20:42 +00:00
|
|
|
if (!n->is_inside_tree() || !n->get_parent())
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Node *> owned;
|
|
|
|
n->get_owned_by(n->get_owner(), &owned);
|
2014-02-10 01:10:30 +00:00
|
|
|
Array owners;
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Node *>::Element *E = owned.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
owners.push_back(E->get());
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
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 (AnimationPlayerEditor::singleton->get_key_editor()->get_root() == n)
|
|
|
|
editor_data->get_undo_redo().add_undo_method(AnimationPlayerEditor::singleton->get_key_editor(), "set_root", n);
|
|
|
|
editor_data->get_undo_redo().add_undo_method(this, "_set_owners", edited_scene, owners);
|
2014-02-10 01:10:30 +00:00
|
|
|
//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 15:29:37 +00:00
|
|
|
|
|
|
|
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
|
2017-03-18 23:36:26 +00:00
|
|
|
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 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
editor_data->get_undo_redo().commit_action();
|
2016-05-17 21:27:15 +00:00
|
|
|
}
|
2015-08-25 03:08:45 +00:00
|
|
|
|
|
|
|
void SceneTreeDock::_selection_changed() {
|
|
|
|
|
2017-03-29 05:16:26 +00:00
|
|
|
int selection_size = EditorNode::get_singleton()->get_editor_selection()->get_selection().size();
|
|
|
|
if (selection_size > 1) {
|
2016-05-16 15:23:40 +00:00
|
|
|
//automatically turn on multi-edit
|
|
|
|
_tool_selected(TOOL_MULTI_EDIT);
|
|
|
|
}
|
2016-05-21 13:29:25 +00:00
|
|
|
|
2017-03-29 20:23:49 +00:00
|
|
|
if (selection_size==1) {
|
|
|
|
if(EditorNode::get_singleton()->get_editor_selection()->get_selection().front()->key()->get_script().is_null()) {
|
|
|
|
button_create_script->show();
|
|
|
|
button_clear_script->hide();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
button_create_script->hide();
|
|
|
|
button_clear_script->show();
|
|
|
|
}
|
2017-03-29 05:16:26 +00:00
|
|
|
} else {
|
|
|
|
button_create_script->hide();
|
2017-03-29 20:23:49 +00:00
|
|
|
button_clear_script->hide();
|
2017-03-29 05:16:26 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 15:23:40 +00:00
|
|
|
//tool_buttons[TOOL_MULTI_EDIT]->set_disabled(EditorNode::get_singleton()->get_editor_selection()->get_selection().size()<2);
|
2015-08-25 03:08:45 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void SceneTreeDock::_create() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (current_option == TOOL_NEW) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *parent = NULL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (edited_scene) {
|
2015-03-31 18:26:38 +00:00
|
|
|
// If root exists in edited scene
|
2014-02-10 01:10:30 +00:00
|
|
|
parent = scene_tree->get_selected();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!parent)
|
2015-03-31 18:26:38 +00:00
|
|
|
parent = edited_scene;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-03-31 18:26:38 +00:00
|
|
|
} else {
|
|
|
|
// If no root exist in edited scene
|
2014-02-10 01:10:30 +00:00
|
|
|
parent = scene_root;
|
|
|
|
ERR_FAIL_COND(!parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
Object *c = create_dialog->instance_selected();
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!c);
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *child = c->cast_to<Node>();
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND(!child);
|
|
|
|
|
2016-05-04 01:25:37 +00:00
|
|
|
editor_data->get_undo_redo().create_action(TTR("Create Node"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (edited_scene) {
|
2015-08-02 15:29:37 +00:00
|
|
|
|
2017-03-18 23:36:26 +00: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);
|
2014-02-10 01:10:30 +00:00
|
|
|
editor_data->get_undo_redo().add_do_reference(child);
|
2017-03-18 23:36:26 +00:00
|
|
|
editor_data->get_undo_redo().add_undo_method(parent, "remove_child", child);
|
2015-08-02 15:29:37 +00:00
|
|
|
|
|
|
|
String new_name = parent->validate_child_name(child->get_type());
|
|
|
|
ScriptEditorDebugger *sed = ScriptEditor::get_singleton()->get_debugger();
|
2017-03-18 23:36:26 +00:00
|
|
|
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));
|
2015-08-02 15:29:37 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
editor_data->get_undo_redo().add_do_method(editor, "set_edited_scene", child);
|
2014-02-10 01:10:30 +00:00
|
|
|
editor_data->get_undo_redo().add_do_reference(child);
|
2017-03-18 23:36:26 +00:00
|
|
|
editor_data->get_undo_redo().add_undo_method(editor, "set_edited_scene", (Object *)NULL);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ms.width < 4)
|
|
|
|
ms.width = 40;
|
|
|
|
if (ms.height < 4)
|
|
|
|
ms.height = 40;
|
2014-02-10 01:10:30 +00:00
|
|
|
ct->set_size(ms);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (current_option == TOOL_REPLACE) {
|
|
|
|
Node *n = scene_tree->get_selected();
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND(!n);
|
|
|
|
|
|
|
|
Object *c = create_dialog->instance_selected();
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!c);
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *newnode = c->cast_to<Node>();
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL_COND(!newnode);
|
|
|
|
|
|
|
|
List<PropertyInfo> pinfo;
|
|
|
|
n->get_property_list(&pinfo);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
|
|
|
|
if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2017-03-18 23:36:26 +00:00
|
|
|
newnode->set(E->get().name, n->get(E->get().name));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
editor->push_item(NULL);
|
|
|
|
|
|
|
|
//reconnect signals
|
|
|
|
List<MethodInfo> sl;
|
|
|
|
|
|
|
|
n->get_signal_list(&sl);
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<MethodInfo>::Element *E = sl.front(); E; E = E->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
List<Object::Connection> cl;
|
2017-03-18 23:36:26 +00:00
|
|
|
n->get_signal_connection_list(E->get().name, &cl);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Object::Connection>::Element *F = cl.front(); F; F = F->next()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Object::Connection &c = F->get();
|
|
|
|
if (!(c.flags & Object::CONNECT_PERSIST))
|
2014-02-10 01:10:30 +00:00
|
|
|
continue;
|
2017-03-18 23:36:26 +00:00
|
|
|
newnode->connect(c.signal, c.target, c.method, varray(), Object::CONNECT_PERSIST);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
String newname = n->get_name();
|
2016-06-21 01:57:07 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Node *> to_erase;
|
|
|
|
for (int i = 0; i < n->get_child_count(); i++) {
|
|
|
|
if (n->get_child(i)->get_owner() == NULL && n->is_owned_by_parent()) {
|
2016-06-21 01:57:07 +00:00
|
|
|
to_erase.push_back(n->get_child(i));
|
|
|
|
}
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
n->replace_by(newnode, true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (n == edited_scene) {
|
|
|
|
edited_scene = newnode;
|
2014-02-10 01:10:30 +00:00
|
|
|
editor->set_edited_scene(newnode);
|
2016-04-12 16:21:37 +00:00
|
|
|
newnode->set_editable_instances(n->get_editable_instances());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 08:53:59 +00:00
|
|
|
//small hack to make collisionshapes and other kind of nodes to work
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < newnode->get_child_count(); i++) {
|
|
|
|
Node *c = newnode->get_child(i);
|
|
|
|
c->call("set_transform", c->call("get_transform"));
|
2016-01-12 08:53:59 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
editor_data->get_undo_redo().clear_history();
|
|
|
|
newnode->set_name(newname);
|
2015-09-07 13:13:29 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
editor->push_item(newnode);
|
|
|
|
|
2015-09-07 13:13:29 +00:00
|
|
|
memdelete(n);
|
2016-01-17 23:03:57 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
while (to_erase.front()) {
|
2016-06-21 01:57:07 +00:00
|
|
|
memdelete(to_erase.front()->get());
|
|
|
|
to_erase.pop_front();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::set_edited_scene(Node *p_scene) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
edited_scene = p_scene;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::set_selected(Node *p_node, bool p_emit_selected) {
|
2016-05-17 21:27:15 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
scene_tree->set_selected(p_node, p_emit_selected);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTreeDock::import_subscene() {
|
|
|
|
|
|
|
|
import_subscene_dialog->popup_centered_ratio();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneTreeDock::_import_subscene() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *parent = scene_tree->get_selected();
|
2015-11-23 19:06:37 +00:00
|
|
|
if (!parent) {
|
|
|
|
parent = editor_data->get_edited_scene_root();
|
|
|
|
ERR_FAIL_COND(!parent);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
import_subscene_dialog->move(parent, edited_scene);
|
2014-02-10 01:10:30 +00:00
|
|
|
editor_data->get_undo_redo().clear_history(); //no undo for now..
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
/*
|
2016-05-20 23:18:35 +00:00
|
|
|
editor_data->get_undo_redo().create_action("Import Subscene");
|
2014-02-10 01:10:30 +00: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-27 20:42:48 +00:00
|
|
|
void SceneTreeDock::_new_scene_from(String p_file) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Node *> selection = editor_selection->get_selected_node_list();
|
2015-11-27 20:42:48 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (selection.size() != 1) {
|
2016-05-04 01:25:37 +00:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
|
|
|
accept->set_text(TTR("This operation requires a single selected node."));
|
2015-11-27 20:42:48 +00:00
|
|
|
accept->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node *base = selection.front()->get();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Map<Node *, Node *> reown;
|
|
|
|
reown[editor_data->get_edited_scene_root()] = base;
|
2015-11-27 20:42:48 +00:00
|
|
|
Node *copy = base->duplicate_and_reown(reown);
|
|
|
|
if (copy) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Ref<PackedScene> sdata = memnew(PackedScene);
|
2015-11-27 20:42:48 +00:00
|
|
|
Error err = sdata->pack(copy);
|
|
|
|
memdelete(copy);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (err != OK) {
|
2016-05-04 01:25:37 +00: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-27 20:42:48 +00:00
|
|
|
accept->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int flg = 0;
|
2015-11-27 20:42:48 +00:00
|
|
|
if (EditorSettings::get_singleton()->get("on_save/compress_binary_resources"))
|
2017-03-18 23:36:26 +00:00
|
|
|
flg |= ResourceSaver::FLAG_COMPRESS;
|
2016-07-22 13:39:46 +00:00
|
|
|
//if (EditorSettings::get_singleton()->get("on_save/save_paths_as_relative"))
|
|
|
|
// flg|=ResourceSaver::FLAG_RELATIVE_PATHS;
|
2015-11-27 20:42:48 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
err = ResourceSaver::save(p_file, sdata, flg);
|
|
|
|
if (err != OK) {
|
2016-05-04 01:25:37 +00:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
|
|
|
accept->set_text(TTR("Error saving scene."));
|
2015-11-27 20:42:48 +00:00
|
|
|
accept->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
2016-10-11 14:54:46 +00:00
|
|
|
_replace_with_branch_scene(p_file, base);
|
2015-11-27 20:42:48 +00:00
|
|
|
} else {
|
2016-05-04 01:25:37 +00:00
|
|
|
accept->get_ok()->set_text(TTR("I see.."));
|
|
|
|
accept->set_text(TTR("Error duplicating scene to save it."));
|
2015-11-27 20:42:48 +00:00
|
|
|
accept->popup_centered_minsize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
static bool _is_node_visible(Node *p_node) {
|
2016-05-11 14:46:08 +00:00
|
|
|
|
|
|
|
if (!p_node->get_owner())
|
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_node->get_owner() != EditorNode::get_singleton()->get_edited_scene() && !EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(p_node->get_owner()))
|
2016-05-11 14:46:08 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
static bool _has_visible_children(Node *p_node) {
|
2016-05-11 14:46:08 +00:00
|
|
|
|
2016-11-02 15:23:03 +00:00
|
|
|
bool collapsed = p_node->is_displayed_folded();
|
2016-05-11 14:46:08 +00:00
|
|
|
if (collapsed)
|
|
|
|
return false;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_node->get_child_count(); i++) {
|
2016-05-11 14:46:08 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *child = p_node->get_child(i);
|
2016-07-07 06:37:38 +00:00
|
|
|
if (!_is_node_visible(child))
|
2016-05-11 14:46:08 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
static Node *_find_last_visible(Node *p_node) {
|
2016-05-11 14:46:08 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *last = NULL;
|
2016-06-18 18:30:44 +00:00
|
|
|
|
2016-11-02 15:23:03 +00:00
|
|
|
bool collapsed = p_node->is_displayed_folded();
|
2016-06-18 18:30:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (!collapsed) {
|
|
|
|
for (int i = 0; i < p_node->get_child_count(); i++) {
|
2016-06-18 18:30:44 +00:00
|
|
|
if (_is_node_visible(p_node->get_child(i))) {
|
2017-03-18 23:36:26 +00:00
|
|
|
last = p_node->get_child(i);
|
2016-06-18 18:30:44 +00:00
|
|
|
}
|
2016-05-11 14:46:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (last) {
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *lastc = _find_last_visible(last);
|
2016-05-11 14:46:08 +00:00
|
|
|
if (lastc)
|
2017-03-18 23:36:26 +00:00
|
|
|
last = lastc;
|
2016-05-11 14:46:08 +00:00
|
|
|
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
last = p_node;
|
2016-05-11 14:46:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return last;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::_normalize_drop(Node *&to_node, int &to_pos, int p_type) {
|
2016-05-11 14:46:08 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
to_pos = -1;
|
2016-05-11 14:46:08 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_type == -1) {
|
2016-05-11 14:46:08 +00:00
|
|
|
//drop at above selected node
|
2017-03-18 23:36:26 +00:00
|
|
|
if (to_node == EditorNode::get_singleton()->get_edited_scene()) {
|
|
|
|
to_node = NULL;
|
2016-07-18 18:00:14 +00:00
|
|
|
ERR_EXPLAIN("Cannot perform drop above the root node!");
|
|
|
|
ERR_FAIL();
|
2016-05-11 23:57:52 +00:00
|
|
|
}
|
2016-05-11 14:46:08 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
to_pos = to_node->get_index();
|
|
|
|
to_node = to_node->get_parent();
|
2016-06-18 18:30:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (p_type == 1) {
|
|
|
|
//drop at below selected node
|
|
|
|
if (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
|
|
|
|
return;
|
|
|
|
}
|
2016-06-18 18:30:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Node *lower_sibling = NULL;
|
2016-06-18 18:30:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (_has_visible_children(to_node)) {
|
|
|
|
to_pos = 0;
|
|
|
|
} else {
|
2016-06-18 18:30:44 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
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;
|
|
|
|
break;
|
2016-06-18 18:30:44 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
if (lower_sibling) {
|
|
|
|
to_pos = lower_sibling->get_index();
|
|
|
|
}
|
|
|
|
|
|
|
|
to_node = to_node->get_parent();
|
|
|
|
}
|
2016-05-11 14:46:08 +00:00
|
|
|
#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-11 23:57:52 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::_files_dropped(Vector<String> p_files, NodePath p_to, int p_type) {
|
2016-05-11 23:57:52 +00:00
|
|
|
|
|
|
|
Node *node = get_node(p_to);
|
|
|
|
ERR_FAIL_COND(!node);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int to_pos = -1;
|
|
|
|
_normalize_drop(node, to_pos, p_type);
|
|
|
|
_perform_instance_scenes(p_files, node, to_pos);
|
2016-05-11 23:57:52 +00:00
|
|
|
}
|
|
|
|
|
2016-10-27 14:32:41 +00:00
|
|
|
void SceneTreeDock::_script_dropped(String p_file, NodePath p_to) {
|
|
|
|
Ref<Script> scr = ResourceLoader::load(p_file);
|
|
|
|
ERR_FAIL_COND(!scr.is_valid());
|
|
|
|
Node *n = get_node(p_to);
|
|
|
|
if (n) {
|
|
|
|
n->set_script(scr.get_ref_ptr());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::_nodes_dragged(Array p_nodes, NodePath p_to, int p_type) {
|
2016-05-11 23:57:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Vector<Node *> nodes;
|
2016-05-11 23:57:52 +00:00
|
|
|
Node *to_node;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < p_nodes.size(); i++) {
|
|
|
|
Node *n = get_node((p_nodes[i]));
|
2017-01-29 13:32:23 +00:00
|
|
|
if (n) {
|
|
|
|
nodes.push_back(n);
|
|
|
|
}
|
2016-05-11 23:57:52 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (nodes.size() == 0)
|
2016-05-11 23:57:52 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
to_node = get_node(p_to);
|
2016-05-11 23:57:52 +00:00
|
|
|
if (!to_node)
|
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int to_pos = -1;
|
2016-05-11 14:46:08 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_normalize_drop(to_node, to_pos, p_type);
|
|
|
|
_do_reparent(to_node, to_pos, nodes, true);
|
2016-05-11 14:46:08 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::_tree_rmb(const Vector2 &p_menu_pos) {
|
2016-05-16 15:23:40 +00:00
|
|
|
if (!EditorNode::get_singleton()->get_edited_scene()) {
|
|
|
|
|
|
|
|
menu->clear();
|
2017-03-18 23:36:26 +00:00
|
|
|
menu->add_icon_shortcut(get_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW);
|
|
|
|
menu->add_icon_shortcut(get_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE);
|
2016-05-16 15:23:40 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
menu->set_size(Size2(1, 1));
|
2016-05-16 15:23:40 +00:00
|
|
|
menu->set_pos(p_menu_pos);
|
|
|
|
menu->popup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
List<Node *> selection = editor_selection->get_selected_node_list();
|
2016-05-16 02:41:48 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (selection.size() == 0)
|
2016-05-16 02:41:48 +00:00
|
|
|
return;
|
2016-05-16 15:23:40 +00:00
|
|
|
|
2016-05-16 02:41:48 +00:00
|
|
|
menu->clear();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (selection.size() == 1) {
|
|
|
|
menu->add_icon_shortcut(get_icon("Add", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/add_child_node"), TOOL_NEW);
|
|
|
|
menu->add_icon_shortcut(get_icon("Instance", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/instance_scene"), TOOL_INSTANCE);
|
2016-05-16 02:41:48 +00:00
|
|
|
menu->add_separator();
|
2017-03-18 23:36:26 +00:00
|
|
|
menu->add_icon_shortcut(get_icon("Reload", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/change_node_type"), TOOL_REPLACE);
|
2016-06-04 16:17:56 +00:00
|
|
|
//menu->add_separator(); moved to their own dock
|
|
|
|
//menu->add_icon_item(get_icon("Groups","EditorIcons"),TTR("Edit Groups"),TOOL_GROUP);
|
2016-06-04 00:03:09 +00:00
|
|
|
//menu->add_icon_item(get_icon("Connect","EditorIcons"),TTR("Edit Connections"),TOOL_CONNECT);
|
2016-05-16 02:41:48 +00:00
|
|
|
menu->add_separator();
|
2017-03-29 21:36:58 +00:00
|
|
|
menu->add_icon_shortcut(get_icon("ScriptCreate", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/attach_script"), TOOL_ATTACH_SCRIPT);
|
2017-03-29 20:23:49 +00:00
|
|
|
menu->add_icon_shortcut(get_icon("Remove", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/clear_script"), TOOL_CLEAR_SCRIPT);
|
2016-05-16 02:41:48 +00:00
|
|
|
menu->add_separator();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
menu->add_icon_shortcut(get_icon("Up", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/move_up"), TOOL_MOVE_UP);
|
|
|
|
menu->add_icon_shortcut(get_icon("Down", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/move_down"), TOOL_MOVE_DOWN);
|
|
|
|
menu->add_icon_shortcut(get_icon("Duplicate", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/duplicate"), TOOL_DUPLICATE);
|
|
|
|
menu->add_icon_shortcut(get_icon("Reparent", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/reparent"), TOOL_REPARENT);
|
2016-05-16 02:41:48 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (selection.size() == 1) {
|
2016-05-16 02:41:48 +00:00
|
|
|
menu->add_separator();
|
2017-03-18 23:36:26 +00:00
|
|
|
menu->add_icon_shortcut(get_icon("Blend", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/merge_from_scene"), TOOL_MERGE_FROM_SCENE);
|
|
|
|
menu->add_icon_shortcut(get_icon("Save", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/save_branch_as_scene"), TOOL_NEW_SCENE_FROM);
|
2017-01-15 10:56:30 +00:00
|
|
|
menu->add_separator();
|
2017-03-18 23:36:26 +00:00
|
|
|
menu->add_icon_shortcut(get_icon("Duplicate", "EditorIcons"), ED_GET_SHORTCUT("scene_tree/copy_node_path"), TOOL_COPY_NODE_PATH);
|
2016-05-16 02:41:48 +00:00
|
|
|
}
|
|
|
|
menu->add_separator();
|
2017-03-18 23:36:26 +00:00
|
|
|
menu->add_icon_shortcut(get_icon("Remove", "EditorIcons"), ED_SHORTCUT("scene_tree/delete", TTR("Delete Node(s)"), KEY_DELETE), TOOL_ERASE);
|
|
|
|
menu->set_size(Size2(1, 1));
|
2016-05-16 02:41:48 +00:00
|
|
|
menu->set_pos(p_menu_pos);
|
|
|
|
menu->popup();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::_filter_changed(const String &p_filter) {
|
2016-05-16 15:23:40 +00:00
|
|
|
|
|
|
|
scene_tree->set_filter(p_filter);
|
|
|
|
}
|
|
|
|
|
|
|
|
String SceneTreeDock::get_filter() {
|
|
|
|
|
|
|
|
return filter->get_text();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void SceneTreeDock::set_filter(const String &p_filter) {
|
2016-05-16 15:23:40 +00:00
|
|
|
|
|
|
|
filter->set_text(p_filter);
|
|
|
|
scene_tree->set_filter(p_filter);
|
|
|
|
}
|
|
|
|
|
2017-03-29 06:46:35 +00:00
|
|
|
void SceneTreeDock::open_script_dialog(Node* p_for_node) {
|
|
|
|
|
|
|
|
scene_tree->set_selected(p_for_node,false);
|
2017-03-29 21:36:58 +00:00
|
|
|
_tool_selected(TOOL_ATTACH_SCRIPT);
|
2017-03-29 06:46:35 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void SceneTreeDock::_bind_methods() {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ObjectTypeDB::bind_method(_MD("_tool_selected"), &SceneTreeDock::_tool_selected, DEFVAL(false));
|
|
|
|
ObjectTypeDB::bind_method(_MD("_create"), &SceneTreeDock::_create);
|
2014-02-10 01:10:30 +00:00
|
|
|
//ObjectTypeDB::bind_method(_MD("_script_created"),&SceneTreeDock::_script_created);
|
2017-03-18 23:36:26 +00:00
|
|
|
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);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_node_renamed"), &SceneTreeDock::_node_renamed);
|
|
|
|
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);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_selection_changed"), &SceneTreeDock::_selection_changed);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_new_scene_from"), &SceneTreeDock::_new_scene_from);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_nodes_dragged"), &SceneTreeDock::_nodes_dragged);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_files_dropped"), &SceneTreeDock::_files_dropped);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_script_dropped"), &SceneTreeDock::_script_dropped);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_tree_rmb"), &SceneTreeDock::_tree_rmb);
|
|
|
|
ObjectTypeDB::bind_method(_MD("_filter_changed"), &SceneTreeDock::_filter_changed);
|
|
|
|
|
|
|
|
ObjectTypeDB::bind_method(_MD("instance"), &SceneTreeDock::instance);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSelection *p_editor_selection, EditorData &p_editor_data) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
editor = p_editor;
|
|
|
|
edited_scene = NULL;
|
|
|
|
editor_data = &p_editor_data;
|
|
|
|
editor_selection = p_editor_selection;
|
|
|
|
scene_root = p_scene_root;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
VBoxContainer *vbc = this;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
HBoxContainer *filter_hbc = memnew(HBoxContainer);
|
2014-02-10 01:10:30 +00:00
|
|
|
ToolButton *tb;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ED_SHORTCUT("scene_tree/add_child_node", TTR("Add Child Node"), KEY_MASK_CMD | KEY_A);
|
|
|
|
ED_SHORTCUT("scene_tree/instance_scene", TTR("Instance Child Scene"));
|
2016-06-19 19:33:42 +00:00
|
|
|
ED_SHORTCUT("scene_tree/change_node_type", TTR("Change Type"));
|
2017-03-29 21:36:58 +00:00
|
|
|
ED_SHORTCUT("scene_tree/attach_script", TTR("Attach Script"));
|
2017-03-29 20:23:49 +00:00
|
|
|
ED_SHORTCUT("scene_tree/clear_script", TTR("Clear Script"));
|
2016-06-19 19:33:42 +00:00
|
|
|
ED_SHORTCUT("scene_tree/move_up", TTR("Move Up"), KEY_MASK_CMD | KEY_UP);
|
|
|
|
ED_SHORTCUT("scene_tree/move_down", TTR("Move Down"), KEY_MASK_CMD | KEY_DOWN);
|
2017-03-18 23:36:26 +00:00
|
|
|
ED_SHORTCUT("scene_tree/duplicate", TTR("Duplicate"), KEY_MASK_CMD | KEY_D);
|
2016-06-19 19:33:42 +00:00
|
|
|
ED_SHORTCUT("scene_tree/reparent", TTR("Reparent"));
|
|
|
|
ED_SHORTCUT("scene_tree/merge_from_scene", TTR("Merge From Scene"));
|
|
|
|
ED_SHORTCUT("scene_tree/save_branch_as_scene", TTR("Save Branch as Scene"));
|
2017-03-18 23:36:26 +00:00
|
|
|
ED_SHORTCUT("scene_tree/copy_node_path", TTR("Copy Node Path"), KEY_MASK_CMD | KEY_C);
|
|
|
|
ED_SHORTCUT("scene_tree/delete_no_confirm", TTR("Delete (No Confirm)"), KEY_MASK_SHIFT | KEY_DELETE);
|
2016-06-12 15:47:29 +00:00
|
|
|
ED_SHORTCUT("scene_tree/delete", TTR("Delete"), KEY_DELETE);
|
2016-06-19 19:33:42 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
tb = memnew(ToolButton);
|
|
|
|
tb->connect("pressed", this, "_tool_selected", make_binds(TOOL_NEW, false));
|
2016-06-19 19:33:42 +00:00
|
|
|
tb->set_tooltip(TTR("Add/Create a New Node"));
|
|
|
|
tb->set_shortcut(ED_GET_SHORTCUT("scene_tree/add_child_node"));
|
2016-05-17 21:27:15 +00:00
|
|
|
filter_hbc->add_child(tb);
|
2017-03-18 23:36:26 +00:00
|
|
|
button_add = tb;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
tb = memnew(ToolButton);
|
|
|
|
tb->connect("pressed", this, "_tool_selected", make_binds(TOOL_INSTANCE, false));
|
2016-05-17 21:27:15 +00:00
|
|
|
tb->set_tooltip(TTR("Instance a scene file as a Node. Creates an inherited scene if no root node exists."));
|
2016-06-19 19:33:42 +00:00
|
|
|
tb->set_shortcut(ED_GET_SHORTCUT("scene_tree/instance_scene"));
|
2016-05-17 21:27:15 +00:00
|
|
|
filter_hbc->add_child(tb);
|
2017-03-18 23:36:26 +00:00
|
|
|
button_instance = tb;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-05-16 15:23:40 +00:00
|
|
|
vbc->add_child(filter_hbc);
|
2017-03-18 23:36:26 +00:00
|
|
|
filter = memnew(LineEdit);
|
2016-05-16 15:23:40 +00:00
|
|
|
filter->set_h_size_flags(SIZE_EXPAND_FILL);
|
|
|
|
filter_hbc->add_child(filter);
|
2017-03-18 23:36:26 +00:00
|
|
|
filter_icon = memnew(TextureFrame);
|
2016-05-16 15:23:40 +00:00
|
|
|
filter_hbc->add_child(filter_icon);
|
2016-05-24 02:24:17 +00:00
|
|
|
filter_icon->set_stretch_mode(TextureFrame::STRETCH_KEEP_CENTERED);
|
2017-03-18 23:36:26 +00:00
|
|
|
filter->connect("text_changed", this, "_filter_changed");
|
2016-05-16 15:23:40 +00:00
|
|
|
|
2017-03-29 05:16:26 +00:00
|
|
|
tb = memnew(ToolButton);
|
2017-03-29 21:36:58 +00:00
|
|
|
tb->connect("pressed",this,"_tool_selected",make_binds(TOOL_ATTACH_SCRIPT, false));
|
|
|
|
tb->set_tooltip(TTR("Attach a new or existing script for the selected node."));
|
|
|
|
tb->set_shortcut(ED_GET_SHORTCUT("scene_tree/attach_script"));
|
2017-03-29 05:16:26 +00:00
|
|
|
filter_hbc->add_child(tb);
|
|
|
|
button_create_script=tb;
|
|
|
|
|
2017-03-29 20:23:49 +00:00
|
|
|
tb = memnew(ToolButton);
|
|
|
|
tb->connect("pressed", this, "_tool_selected", make_binds(TOOL_CLEAR_SCRIPT, false));
|
|
|
|
tb->set_tooltip(TTR("Clear a script for the selected node."));
|
|
|
|
tb->set_shortcut(ED_GET_SHORTCUT("scene_tree/clear_script"));
|
|
|
|
filter_hbc->add_child(tb);
|
|
|
|
button_clear_script = tb;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
scene_tree = memnew(SceneTreeEditor(false, true, true));
|
2014-02-10 01:10:30 +00:00
|
|
|
vbc->add_child(scene_tree);
|
2017-03-18 23:36:26 +00:00
|
|
|
scene_tree->set_v_size_flags(SIZE_EXPAND | SIZE_FILL);
|
|
|
|
scene_tree->connect("rmb_pressed", this, "_tree_rmb");
|
|
|
|
|
|
|
|
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");
|
|
|
|
scene_tree->connect("nodes_rearranged", this, "_nodes_dragged");
|
|
|
|
scene_tree->connect("files_dropped", this, "_files_dropped");
|
|
|
|
scene_tree->connect("script_dropped", this, "_script_dropped");
|
2016-05-11 14:46:08 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
scene_tree->set_undo_redo(&editor_data->get_undo_redo());
|
|
|
|
scene_tree->set_editor_selection(editor_selection);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
create_dialog = memnew(CreateDialog);
|
2014-02-10 01:10:30 +00:00
|
|
|
create_dialog->set_base_type("Node");
|
|
|
|
add_child(create_dialog);
|
2017-03-18 23:36:26 +00:00
|
|
|
create_dialog->connect("create", this, "_create");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-06-04 16:17:56 +00:00
|
|
|
//groups_editor = memnew( GroupsEditor );
|
|
|
|
//add_child(groups_editor);
|
|
|
|
//groups_editor->set_undo_redo(&editor_data->get_undo_redo());
|
2015-11-27 20:42:48 +00:00
|
|
|
|
2016-06-04 00:03:09 +00:00
|
|
|
//connect_dialog = memnew( ConnectionsDialog(p_editor) );
|
|
|
|
//add_child(connect_dialog);
|
|
|
|
//connect_dialog->set_undoredo(&editor_data->get_undo_redo());
|
2015-11-27 20:42:48 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
script_create_dialog = memnew(ScriptCreateDialog);
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(script_create_dialog);
|
2017-03-18 23:36:26 +00:00
|
|
|
script_create_dialog->connect("script_created", this, "_script_created");
|
2015-11-27 20:42:48 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
reparent_dialog = memnew(ReparentDialog);
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(reparent_dialog);
|
2017-03-18 23:36:26 +00:00
|
|
|
reparent_dialog->connect("reparent", this, "_node_reparent");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
accept = memnew(AcceptDialog);
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(accept);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
file = memnew(EditorFileDialog);
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(file);
|
2017-03-18 23:36:26 +00:00
|
|
|
file->connect("file_selected", this, "instance");
|
2014-04-10 03:18:27 +00:00
|
|
|
set_process_unhandled_key_input(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
delete_dialog = memnew(ConfirmationDialog);
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(delete_dialog);
|
2017-03-18 23:36:26 +00:00
|
|
|
delete_dialog->connect("confirmed", this, "_delete_confirm");
|
2015-11-27 20:42:48 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
import_subscene_dialog = memnew(EditorSubScene);
|
2014-02-10 01:10:30 +00:00
|
|
|
add_child(import_subscene_dialog);
|
2017-03-18 23:36:26 +00:00
|
|
|
import_subscene_dialog->connect("subscene_selected", this, "_import_subscene");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
new_scene_from_dialog = memnew(EditorFileDialog);
|
2015-11-27 20:42:48 +00:00
|
|
|
new_scene_from_dialog->set_mode(EditorFileDialog::MODE_SAVE_FILE);
|
|
|
|
add_child(new_scene_from_dialog);
|
2017-03-18 23:36:26 +00:00
|
|
|
new_scene_from_dialog->connect("file_selected", this, "_new_scene_from");
|
2015-11-27 20:42:48 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
menu = memnew(PopupMenu);
|
2016-05-16 02:41:48 +00:00
|
|
|
add_child(menu);
|
2017-03-18 23:36:26 +00:00
|
|
|
menu->connect("item_pressed", this, "_tool_selected");
|
|
|
|
first_enter = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
vbc->add_constant_override("separation", 4);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|