scene_tree_editor.cpp 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. /*************************************************************************/
  2. /* scene_tree_editor.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "scene_tree_editor.h"
  31. #include "editor/plugins/canvas_item_editor_plugin.h"
  32. #include "editor_node.h"
  33. #include "message_queue.h"
  34. #include "print_string.h"
  35. #include "scene/gui/label.h"
  36. #include "scene/main/viewport.h"
  37. #include "scene/resources/packed_scene.h"
  38. Node *SceneTreeEditor::get_scene_node() {
  39. ERR_FAIL_COND_V(!is_inside_tree(), NULL);
  40. return get_tree()->get_edited_scene_root();
  41. }
  42. void SceneTreeEditor::_subscene_option(int p_idx) {
  43. Object *obj = ObjectDB::get_instance(instance_node);
  44. if (!obj)
  45. return;
  46. Node *node = obj->cast_to<Node>();
  47. if (!node)
  48. return;
  49. switch (p_idx) {
  50. case SCENE_MENU_EDITABLE_CHILDREN: {
  51. bool editable = EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(node);
  52. editable = !editable;
  53. //node->set_instance_children_editable(editable);
  54. EditorNode::get_singleton()->get_edited_scene()->set_editable_instance(node, editable);
  55. instance_menu->set_item_checked(0, editable);
  56. if (editable) {
  57. node->set_scene_instance_load_placeholder(false);
  58. instance_menu->set_item_checked(1, false);
  59. }
  60. _update_tree();
  61. } break;
  62. case SCENE_MENU_USE_PLACEHOLDER: {
  63. bool placeholder = node->get_scene_instance_load_placeholder();
  64. placeholder = !placeholder;
  65. //node->set_instance_children_editable(editable);
  66. if (placeholder) {
  67. EditorNode::get_singleton()->get_edited_scene()->set_editable_instance(node, false);
  68. }
  69. node->set_scene_instance_load_placeholder(placeholder);
  70. instance_menu->set_item_checked(0, false);
  71. instance_menu->set_item_checked(1, placeholder);
  72. _update_tree();
  73. } break;
  74. case SCENE_MENU_OPEN: {
  75. emit_signal("open", node->get_filename());
  76. } break;
  77. case SCENE_MENU_CLEAR_INHERITANCE: {
  78. clear_inherit_confirm->popup_centered_minsize();
  79. } break;
  80. case SCENE_MENU_CLEAR_INSTANCING: {
  81. Node *root = EditorNode::get_singleton()->get_edited_scene();
  82. if (!root)
  83. break;
  84. ERR_FAIL_COND(node->get_filename() == String());
  85. undo_redo->create_action("Discard Instancing");
  86. undo_redo->add_do_method(node, "set_filename", "");
  87. undo_redo->add_undo_method(node, "set_filename", node->get_filename());
  88. _node_replace_owner(node, node, root);
  89. undo_redo->add_do_method(this, "update_tree");
  90. undo_redo->add_undo_method(this, "update_tree");
  91. undo_redo->commit_action();
  92. } break;
  93. case SCENE_MENU_OPEN_INHERITED: {
  94. if (node && node->get_scene_inherited_state().is_valid()) {
  95. emit_signal("open", node->get_scene_inherited_state()->get_path());
  96. }
  97. } break;
  98. case SCENE_MENU_CLEAR_INHERITANCE_CONFIRM: {
  99. if (node && node->get_scene_inherited_state().is_valid()) {
  100. node->set_scene_inherited_state(Ref<SceneState>());
  101. update_tree();
  102. EditorNode::get_singleton()->get_property_editor()->update_tree();
  103. }
  104. } break;
  105. }
  106. }
  107. void SceneTreeEditor::_node_replace_owner(Node *p_base, Node *p_node, Node *p_root) {
  108. if (p_base != p_node) {
  109. if (p_node->get_owner() == p_base) {
  110. undo_redo->add_do_method(p_node, "set_owner", p_root);
  111. undo_redo->add_undo_method(p_node, "set_owner", p_base);
  112. }
  113. }
  114. for (int i = 0; i < p_node->get_child_count(); i++) {
  115. _node_replace_owner(p_base, p_node->get_child(i), p_root);
  116. }
  117. }
  118. void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_id) {
  119. TreeItem *item = p_item->cast_to<TreeItem>();
  120. ERR_FAIL_COND(!item);
  121. NodePath np = item->get_metadata(0);
  122. Node *n = get_node(np);
  123. ERR_FAIL_COND(!n);
  124. if (p_id == BUTTON_SUBSCENE) {
  125. //open scene request
  126. Rect2 item_rect = tree->get_item_rect(item, 0);
  127. item_rect.pos.y -= tree->get_scroll().y;
  128. item_rect.pos += tree->get_global_pos();
  129. if (n == get_scene_node()) {
  130. inheritance_menu->set_pos(item_rect.pos + Vector2(0, item_rect.size.y));
  131. inheritance_menu->set_size(Vector2(item_rect.size.x, 0));
  132. inheritance_menu->popup();
  133. instance_node = n->get_instance_ID();
  134. } else {
  135. instance_menu->set_pos(item_rect.pos + Vector2(0, item_rect.size.y));
  136. instance_menu->set_size(Vector2(item_rect.size.x, 0));
  137. if (EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(n))
  138. instance_menu->set_item_checked(0, true);
  139. else
  140. instance_menu->set_item_checked(0, false);
  141. if (n->get_owner() == get_scene_node()) {
  142. instance_menu->set_item_checked(1, n->get_scene_instance_load_placeholder());
  143. instance_menu->set_item_disabled(1, false);
  144. } else {
  145. instance_menu->set_item_checked(1, false);
  146. instance_menu->set_item_disabled(1, true);
  147. }
  148. instance_menu->popup();
  149. instance_node = n->get_instance_ID();
  150. }
  151. //emit_signal("open",n->get_filename());
  152. } else if (p_id == BUTTON_SCRIPT) {
  153. RefPtr script = n->get_script();
  154. if (!script.is_null())
  155. emit_signal("open_script", script);
  156. } else if (p_id == BUTTON_VISIBILITY) {
  157. undo_redo->create_action(TTR("Toggle Visible"));
  158. _toggle_visible(n);
  159. List<Node *> selection = editor_selection->get_selected_node_list();
  160. if (selection.size() > 1) {
  161. for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
  162. Node *nv = E->get();
  163. ERR_FAIL_COND(!nv);
  164. if (nv == n) {
  165. continue;
  166. }
  167. _toggle_visible(nv);
  168. }
  169. }
  170. undo_redo->commit_action();
  171. } else if (p_id == BUTTON_LOCK) {
  172. if (n->is_type("CanvasItem")) {
  173. n->set_meta("_edit_lock_", Variant());
  174. _update_tree();
  175. emit_signal("node_changed");
  176. }
  177. } else if (p_id == BUTTON_GROUP) {
  178. if (n->is_type("CanvasItem")) {
  179. n->set_meta("_edit_group_", Variant());
  180. _update_tree();
  181. emit_signal("node_changed");
  182. }
  183. } else if (p_id == BUTTON_WARNING) {
  184. String config_err = n->get_configuration_warning();
  185. if (config_err == String())
  186. return;
  187. config_err = config_err.word_wrap(80);
  188. warning->set_text(config_err);
  189. warning->popup_centered_minsize();
  190. } else if (p_id == BUTTON_SIGNALS) {
  191. editor_selection->clear();
  192. editor_selection->add_node(n);
  193. set_selected(n);
  194. NodeDock::singleton->get_parent()->call("set_current_tab", NodeDock::singleton->get_index());
  195. NodeDock::singleton->show_connections();
  196. } else if (p_id == BUTTON_GROUPS) {
  197. editor_selection->clear();
  198. editor_selection->add_node(n);
  199. set_selected(n);
  200. NodeDock::singleton->get_parent()->call("set_current_tab", NodeDock::singleton->get_index());
  201. NodeDock::singleton->show_groups();
  202. }
  203. }
  204. void SceneTreeEditor::_toggle_visible(Node *p_node) {
  205. if (p_node->has_method("is_hidden") && p_node->has_method("set_hidden")) {
  206. bool v = bool(p_node->call("is_hidden"));
  207. undo_redo->add_do_method(p_node, "set_hidden", !v);
  208. undo_redo->add_undo_method(p_node, "set_hidden", v);
  209. }
  210. }
  211. bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
  212. if (!p_node)
  213. return false;
  214. // only owned nodes are editable, since nodes can create their own (manually owned) child nodes,
  215. // which the editor needs not to know about.
  216. bool part_of_subscene = false;
  217. if (!display_foreign && p_node->get_owner() != get_scene_node() && p_node != get_scene_node()) {
  218. if ((show_enabled_subscene || can_open_instance) && p_node->get_owner() && (get_scene_node()->is_editable_instance(p_node->get_owner()))) {
  219. part_of_subscene = true;
  220. //allow
  221. } else {
  222. return false;
  223. }
  224. } else {
  225. part_of_subscene = p_node != get_scene_node() && get_scene_node()->get_scene_inherited_state().is_valid() && get_scene_node()->get_scene_inherited_state()->find_node_by_path(get_scene_node()->get_path_to(p_node)) >= 0;
  226. }
  227. TreeItem *item = tree->create_item(p_parent);
  228. item->set_text(0, p_node->get_name());
  229. if (can_rename && !part_of_subscene /*(p_node->get_owner() == get_scene_node() || p_node==get_scene_node())*/)
  230. item->set_editable(0, true);
  231. item->set_selectable(0, true);
  232. if (can_rename) {
  233. #ifdef ENABLE_DEPRECATED
  234. if (p_node->has_meta("_editor_collapsed")) {
  235. //remove previous way of storing folding, which did not get along with scene inheritance and instancing
  236. if ((bool)p_node->get_meta("_editor_collapsed"))
  237. p_node->set_display_folded(true);
  238. p_node->set_meta("_editor_collapsed", Variant());
  239. }
  240. #endif
  241. bool collapsed = p_node->is_displayed_folded();
  242. if (collapsed)
  243. item->set_collapsed(true);
  244. }
  245. Ref<Texture> icon;
  246. if (p_node->has_meta("_editor_icon"))
  247. icon = p_node->get_meta("_editor_icon");
  248. else
  249. icon = get_icon((has_icon(p_node->get_type(), "EditorIcons") ? p_node->get_type() : String("Object")), "EditorIcons");
  250. item->set_icon(0, icon);
  251. item->set_metadata(0, p_node->get_path());
  252. if (part_of_subscene) {
  253. //item->set_selectable(0,marked_selectable);
  254. item->set_custom_color(0, Color(0.8, 0.4, 0.20));
  255. } else if (marked.has(p_node)) {
  256. item->set_selectable(0, marked_selectable);
  257. item->set_custom_color(0, Color(0.8, 0.1, 0.10));
  258. } else if (!marked_selectable && !marked_children_selectable) {
  259. Node *node = p_node;
  260. while (node) {
  261. if (marked.has(node)) {
  262. item->set_selectable(0, false);
  263. item->set_custom_color(0, Color(0.8, 0.1, 0.10));
  264. break;
  265. }
  266. node = node->get_parent();
  267. }
  268. }
  269. if (can_rename) { //should be can edit..
  270. String warning = p_node->get_configuration_warning();
  271. if (warning != String()) {
  272. item->add_button(0, get_icon("NodeWarning", "EditorIcons"), BUTTON_WARNING, false, TTR("Node configuration warning:") + "\n" + p_node->get_configuration_warning());
  273. }
  274. bool has_connections = p_node->has_persistent_signal_connections();
  275. bool has_groups = p_node->has_persistent_groups();
  276. if (has_connections && has_groups) {
  277. item->add_button(0, get_icon("ConnectionAndGroups", "EditorIcons"), BUTTON_SIGNALS, false, TTR("Node has connection(s) and group(s)\nClick to show signals dock."));
  278. } else if (has_connections) {
  279. item->add_button(0, get_icon("Connect", "EditorIcons"), BUTTON_SIGNALS, false, TTR("Node has connections.\nClick to show signals dock."));
  280. } else if (has_groups) {
  281. item->add_button(0, get_icon("Groups", "EditorIcons"), BUTTON_GROUPS, false, TTR("Node is in group(s).\nClick to show groups dock."));
  282. }
  283. }
  284. if (p_node == get_scene_node() && p_node->get_scene_inherited_state().is_valid()) {
  285. item->add_button(0, get_icon("InstanceOptions", "EditorIcons"), BUTTON_SUBSCENE, false, TTR("Subscene options"));
  286. item->set_tooltip(0, TTR("Inherits:") + " " + p_node->get_scene_inherited_state()->get_path() + "\n" + TTR("Type:") + " " + p_node->get_type());
  287. } else if (p_node != get_scene_node() && p_node->get_filename() != "" && can_open_instance) {
  288. item->add_button(0, get_icon("InstanceOptions", "EditorIcons"), BUTTON_SUBSCENE, false, TTR("Subscene options"));
  289. item->set_tooltip(0, TTR("Instance:") + " " + p_node->get_filename() + "\n" + TTR("Type:") + " " + p_node->get_type());
  290. } else {
  291. item->set_tooltip(0, String(p_node->get_name()) + "\n" + TTR("Type:") + " " + p_node->get_type());
  292. }
  293. if (can_open_instance) {
  294. if (!p_node->is_connected("script_changed", this, "_node_script_changed"))
  295. p_node->connect("script_changed", this, "_node_script_changed", varray(p_node));
  296. if (!p_node->get_script().is_null()) {
  297. item->add_button(0, get_icon("Script", "EditorIcons"), BUTTON_SCRIPT, false, TTR("Open script"));
  298. }
  299. if (p_node->is_type("CanvasItem")) {
  300. bool is_locked = p_node->has_meta("_edit_lock_"); //_edit_group_
  301. if (is_locked)
  302. item->add_button(0, get_icon("Lock", "EditorIcons"), BUTTON_LOCK, false, TTR("Node is locked.\nClick to unlock"));
  303. bool is_grouped = p_node->has_meta("_edit_group_");
  304. if (is_grouped)
  305. item->add_button(0, get_icon("Group", "EditorIcons"), BUTTON_GROUP, false, TTR("Children are not selectable.\nClick to make selectable"));
  306. bool h = p_node->call("is_hidden");
  307. if (h)
  308. item->add_button(0, get_icon("Hidden", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
  309. else
  310. item->add_button(0, get_icon("Visible", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
  311. if (!p_node->is_connected("visibility_changed", this, "_node_visibility_changed"))
  312. p_node->connect("visibility_changed", this, "_node_visibility_changed", varray(p_node));
  313. _update_visibility_color(p_node, item);
  314. } else if (p_node->is_type("Spatial")) {
  315. bool h = p_node->call("is_hidden");
  316. if (h)
  317. item->add_button(0, get_icon("Hidden", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
  318. else
  319. item->add_button(0, get_icon("Visible", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
  320. if (!p_node->is_connected("visibility_changed", this, "_node_visibility_changed"))
  321. p_node->connect("visibility_changed", this, "_node_visibility_changed", varray(p_node));
  322. _update_visibility_color(p_node, item);
  323. }
  324. }
  325. if (editor_selection) {
  326. if (editor_selection->is_selected(p_node)) {
  327. item->select(0);
  328. }
  329. }
  330. if (selected == p_node) {
  331. if (!editor_selection)
  332. item->select(0);
  333. item->set_as_cursor(0);
  334. }
  335. bool keep = (filter.is_subsequence_ofi(String(p_node->get_name())));
  336. for (int i = 0; i < p_node->get_child_count(); i++) {
  337. bool child_keep = _add_nodes(p_node->get_child(i), item);
  338. keep = keep || child_keep;
  339. }
  340. if (!keep) {
  341. memdelete(item);
  342. return false;
  343. } else {
  344. return true;
  345. }
  346. }
  347. void SceneTreeEditor::_node_visibility_changed(Node *p_node) {
  348. if (p_node != get_scene_node() && !p_node->get_owner()) {
  349. return;
  350. }
  351. TreeItem *item = p_node ? _find(tree->get_root(), p_node->get_path()) : NULL;
  352. if (!item) {
  353. return;
  354. }
  355. int idx = item->get_button_by_id(0, BUTTON_VISIBILITY);
  356. ERR_FAIL_COND(idx == -1);
  357. bool visible = false;
  358. if (p_node->is_type("CanvasItem")) {
  359. visible = !p_node->call("is_hidden");
  360. CanvasItemEditor::get_singleton()->get_viewport_control()->update();
  361. } else if (p_node->is_type("Spatial")) {
  362. visible = !p_node->call("is_hidden");
  363. }
  364. if (!visible)
  365. item->set_button(0, idx, get_icon("Hidden", "EditorIcons"));
  366. else
  367. item->set_button(0, idx, get_icon("Visible", "EditorIcons"));
  368. _update_visibility_color(p_node, item);
  369. }
  370. void SceneTreeEditor::_update_visibility_color(Node *p_node, TreeItem *p_item) {
  371. if (p_node->is_type("CanvasItem") || p_node->is_type("Spatial")) {
  372. Color color(1, 1, 1, 1);
  373. bool visible_on_screen = p_node->call("is_visible");
  374. if (!visible_on_screen) {
  375. color = Color(0.6, 0.6, 0.6, 1);
  376. }
  377. int idx = p_item->get_button_by_id(0, BUTTON_VISIBILITY);
  378. p_item->set_button_color(0, idx, color);
  379. }
  380. }
  381. void SceneTreeEditor::_node_script_changed(Node *p_node) {
  382. _update_tree();
  383. /*
  384. changes the order :|
  385. TreeItem* item=p_node?_find(tree->get_root(),p_node->get_path()):NULL;
  386. if (p_node->get_script().is_null()) {
  387. int idx=item->get_button_by_id(0,2);
  388. if (idx>=0)
  389. item->erase_button(0,idx);
  390. } else {
  391. int idx=item->get_button_by_id(0,2);
  392. if (idx<0)
  393. item->add_button(0,get_icon("Script","EditorIcons"),2);
  394. }*/
  395. }
  396. void SceneTreeEditor::_node_removed(Node *p_node) {
  397. if (EditorNode::get_singleton()->is_exiting())
  398. return; //speed up exit
  399. if (p_node->is_connected("script_changed", this, "_node_script_changed"))
  400. p_node->disconnect("script_changed", this, "_node_script_changed");
  401. if (p_node->is_type("Spatial") || p_node->is_type("CanvasItem")) {
  402. if (p_node->is_connected("visibility_changed", this, "_node_visibility_changed"))
  403. p_node->disconnect("visibility_changed", this, "_node_visibility_changed");
  404. }
  405. if (p_node == selected) {
  406. selected = NULL;
  407. emit_signal("node_selected");
  408. }
  409. }
  410. void SceneTreeEditor::_update_tree() {
  411. if (!is_inside_tree()) {
  412. tree_dirty = false;
  413. return;
  414. }
  415. updating_tree = true;
  416. tree->clear();
  417. if (get_scene_node()) {
  418. _add_nodes(get_scene_node(), NULL);
  419. last_hash = hash_djb2_one_64(0);
  420. _compute_hash(get_scene_node(), last_hash);
  421. }
  422. updating_tree = false;
  423. tree_dirty = false;
  424. }
  425. void SceneTreeEditor::_compute_hash(Node *p_node, uint64_t &hash) {
  426. hash = hash_djb2_one_64(p_node->get_instance_ID(), hash);
  427. if (p_node->get_parent())
  428. hash = hash_djb2_one_64(p_node->get_parent()->get_instance_ID(), hash); //so a reparent still produces a different hash
  429. for (int i = 0; i < p_node->get_child_count(); i++) {
  430. _compute_hash(p_node->get_child(i), hash);
  431. }
  432. }
  433. void SceneTreeEditor::_test_update_tree() {
  434. pending_test_update = false;
  435. if (!is_inside_tree())
  436. return;
  437. if (tree_dirty)
  438. return; // don't even bother
  439. uint64_t hash = hash_djb2_one_64(0);
  440. if (get_scene_node())
  441. _compute_hash(get_scene_node(), hash);
  442. //test hash
  443. if (hash == last_hash)
  444. return; // did not change
  445. MessageQueue::get_singleton()->push_call(this, "_update_tree");
  446. tree_dirty = true;
  447. }
  448. void SceneTreeEditor::_tree_changed() {
  449. if (EditorNode::get_singleton()->is_exiting())
  450. return; //speed up exit
  451. if (pending_test_update)
  452. return;
  453. if (tree_dirty)
  454. return;
  455. MessageQueue::get_singleton()->push_call(this, "_test_update_tree");
  456. pending_test_update = true;
  457. }
  458. void SceneTreeEditor::_selected_changed() {
  459. TreeItem *s = tree->get_selected();
  460. ERR_FAIL_COND(!s);
  461. NodePath np = s->get_metadata(0);
  462. Node *n = get_node(np);
  463. if (n == selected)
  464. return;
  465. selected = get_node(np);
  466. blocked++;
  467. emit_signal("node_selected");
  468. blocked--;
  469. }
  470. void SceneTreeEditor::_cell_multi_selected(Object *p_object, int p_cell, bool p_selected) {
  471. TreeItem *item = p_object->cast_to<TreeItem>();
  472. ERR_FAIL_COND(!item);
  473. NodePath np = item->get_metadata(0);
  474. Node *n = get_node(np);
  475. if (!n)
  476. return;
  477. if (!editor_selection)
  478. return;
  479. if (p_selected) {
  480. editor_selection->add_node(n);
  481. } else {
  482. editor_selection->remove_node(n);
  483. }
  484. }
  485. void SceneTreeEditor::_notification(int p_what) {
  486. if (p_what == NOTIFICATION_ENTER_TREE) {
  487. get_tree()->connect("tree_changed", this, "_tree_changed");
  488. get_tree()->connect("node_removed", this, "_node_removed");
  489. get_tree()->connect("node_configuration_warning_changed", this, "_warning_changed");
  490. instance_menu->set_item_icon(5, get_icon("Load", "EditorIcons"));
  491. tree->connect("item_collapsed", this, "_cell_collapsed");
  492. inheritance_menu->set_item_icon(2, get_icon("Load", "EditorIcons"));
  493. clear_inherit_confirm->connect("confirmed", this, "_subscene_option", varray(SCENE_MENU_CLEAR_INHERITANCE_CONFIRM));
  494. EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed");
  495. // get_scene()->connect("tree_changed",this,"_tree_changed",Vector<Variant>(),CONNECT_DEFERRED);
  496. // get_scene()->connect("node_removed",this,"_node_removed",Vector<Variant>(),CONNECT_DEFERRED);
  497. _update_tree();
  498. }
  499. if (p_what == NOTIFICATION_EXIT_TREE) {
  500. get_tree()->disconnect("tree_changed", this, "_tree_changed");
  501. get_tree()->disconnect("node_removed", this, "_node_removed");
  502. tree->disconnect("item_collapsed", this, "_cell_collapsed");
  503. clear_inherit_confirm->disconnect("confirmed", this, "_subscene_option");
  504. get_tree()->disconnect("node_configuration_warning_changed", this, "_warning_changed");
  505. EditorSettings::get_singleton()->disconnect("settings_changed", this, "_editor_settings_changed");
  506. }
  507. }
  508. TreeItem *SceneTreeEditor::_find(TreeItem *p_node, const NodePath &p_path) {
  509. if (!p_node)
  510. return NULL;
  511. NodePath np = p_node->get_metadata(0);
  512. if (np == p_path)
  513. return p_node;
  514. TreeItem *children = p_node->get_children();
  515. while (children) {
  516. TreeItem *n = _find(children, p_path);
  517. if (n)
  518. return n;
  519. children = children->get_next();
  520. }
  521. return NULL;
  522. }
  523. void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) {
  524. ERR_FAIL_COND(blocked > 0);
  525. if (pending_test_update)
  526. _test_update_tree();
  527. if (tree_dirty)
  528. _update_tree();
  529. if (selected == p_node)
  530. return;
  531. TreeItem *item = p_node ? _find(tree->get_root(), p_node->get_path()) : NULL;
  532. if (item) {
  533. // make visible when it's collapsed
  534. TreeItem *node = item->get_parent();
  535. while (node && node != tree->get_root()) {
  536. node->set_collapsed(false);
  537. node = node->get_parent();
  538. }
  539. item->select(0);
  540. item->set_as_cursor(0);
  541. selected = p_node;
  542. tree->ensure_cursor_is_visible();
  543. } else {
  544. if (!p_node)
  545. selected = NULL;
  546. _update_tree();
  547. selected = p_node;
  548. }
  549. if (p_emit_selected) {
  550. emit_signal("node_selected");
  551. }
  552. }
  553. void SceneTreeEditor::_rename_node(ObjectID p_node, const String &p_name) {
  554. Object *o = ObjectDB::get_instance(p_node);
  555. ERR_FAIL_COND(!o);
  556. Node *n = o->cast_to<Node>();
  557. ERR_FAIL_COND(!n);
  558. TreeItem *item = _find(tree->get_root(), n->get_path());
  559. ERR_FAIL_COND(!item);
  560. n->set_name(p_name);
  561. item->set_metadata(0, n->get_path());
  562. item->set_text(0, p_name);
  563. emit_signal("node_renamed");
  564. if (!tree_dirty) {
  565. MessageQueue::get_singleton()->push_call(this, "_update_tree");
  566. tree_dirty = true;
  567. }
  568. }
  569. void SceneTreeEditor::_renamed() {
  570. TreeItem *which = tree->get_edited();
  571. ERR_FAIL_COND(!which);
  572. NodePath np = which->get_metadata(0);
  573. Node *n = get_node(np);
  574. ERR_FAIL_COND(!n);
  575. String new_name = which->get_text(0);
  576. if (new_name.find(".") != -1 || new_name.find("/") != -1) {
  577. error->set_text(TTR("Invalid node name, the following characters are not allowed:") + "\n \".\", \"/\"");
  578. error->popup_centered_minsize();
  579. new_name = n->get_name();
  580. }
  581. if (new_name == n->get_name())
  582. return;
  583. if (!undo_redo) {
  584. n->set_name(new_name);
  585. which->set_metadata(0, n->get_path());
  586. emit_signal("node_renamed");
  587. } else {
  588. undo_redo->create_action(TTR("Rename Node"));
  589. emit_signal("node_prerename", n, new_name);
  590. undo_redo->add_do_method(this, "_rename_node", n->get_instance_ID(), new_name);
  591. undo_redo->add_undo_method(this, "_rename_node", n->get_instance_ID(), n->get_name());
  592. undo_redo->commit_action();
  593. }
  594. }
  595. Node *SceneTreeEditor::get_selected() {
  596. return selected;
  597. }
  598. void SceneTreeEditor::set_marked(const Set<Node *> &p_marked, bool p_selectable, bool p_children_selectable) {
  599. if (tree_dirty)
  600. _update_tree();
  601. marked = p_marked;
  602. marked_selectable = p_selectable;
  603. marked_children_selectable = p_children_selectable;
  604. _update_tree();
  605. }
  606. void SceneTreeEditor::set_marked(Node *p_marked, bool p_selectable, bool p_children_selectable) {
  607. Set<Node *> s;
  608. if (p_marked)
  609. s.insert(p_marked);
  610. set_marked(s, p_selectable, p_children_selectable);
  611. }
  612. void SceneTreeEditor::set_filter(const String &p_filter) {
  613. filter = p_filter;
  614. _update_tree();
  615. }
  616. String SceneTreeEditor::get_filter() const {
  617. return filter;
  618. }
  619. void SceneTreeEditor::set_display_foreign_nodes(bool p_display) {
  620. display_foreign = p_display;
  621. _update_tree();
  622. }
  623. bool SceneTreeEditor::get_display_foreign_nodes() const {
  624. return display_foreign;
  625. }
  626. void SceneTreeEditor::set_editor_selection(EditorSelection *p_selection) {
  627. editor_selection = p_selection;
  628. tree->set_select_mode(Tree::SELECT_MULTI);
  629. tree->set_cursor_can_exit_tree(false);
  630. editor_selection->connect("selection_changed", this, "_selection_changed");
  631. }
  632. void SceneTreeEditor::_update_selection(TreeItem *item) {
  633. ERR_FAIL_COND(!item);
  634. NodePath np = item->get_metadata(0);
  635. if (!has_node(np))
  636. return;
  637. Node *n = get_node(np);
  638. if (!n)
  639. return;
  640. if (editor_selection->is_selected(n))
  641. item->select(0);
  642. else
  643. item->deselect(0);
  644. TreeItem *c = item->get_children();
  645. while (c) {
  646. _update_selection(c);
  647. c = c->get_next();
  648. }
  649. }
  650. void SceneTreeEditor::_selection_changed() {
  651. if (!editor_selection)
  652. return;
  653. TreeItem *root = tree->get_root();
  654. if (!root)
  655. return;
  656. _update_selection(root);
  657. }
  658. void SceneTreeEditor::_cell_collapsed(Object *p_obj) {
  659. if (updating_tree)
  660. return;
  661. if (!can_rename)
  662. return;
  663. TreeItem *ti = p_obj->cast_to<TreeItem>();
  664. if (!ti)
  665. return;
  666. bool collapsed = ti->is_collapsed();
  667. NodePath np = ti->get_metadata(0);
  668. Node *n = get_node(np);
  669. ERR_FAIL_COND(!n);
  670. n->set_display_folded(collapsed);
  671. }
  672. Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  673. if (!can_rename)
  674. return Variant(); //not editable tree
  675. Vector<Node *> selected;
  676. Vector<Ref<Texture> > icons;
  677. TreeItem *next = tree->get_next_selected(NULL);
  678. while (next) {
  679. NodePath np = next->get_metadata(0);
  680. Node *n = get_node(np);
  681. if (n) {
  682. selected.push_back(n);
  683. icons.push_back(next->get_icon(0));
  684. }
  685. next = tree->get_next_selected(next);
  686. }
  687. if (selected.empty())
  688. return Variant();
  689. VBoxContainer *vb = memnew(VBoxContainer);
  690. Array objs;
  691. int list_max = 10;
  692. float opacity_step = 1.0f / list_max;
  693. float opacity_item = 1.0f;
  694. for (int i = 0; i < selected.size(); i++) {
  695. if (i < list_max) {
  696. HBoxContainer *hb = memnew(HBoxContainer);
  697. TextureFrame *tf = memnew(TextureFrame);
  698. tf->set_texture(icons[i]);
  699. hb->add_child(tf);
  700. Label *label = memnew(Label(selected[i]->get_name()));
  701. hb->add_child(label);
  702. vb->add_child(hb);
  703. hb->set_opacity(opacity_item);
  704. opacity_item -= opacity_step;
  705. }
  706. NodePath p = selected[i]->get_path();
  707. objs.push_back(p);
  708. }
  709. set_drag_preview(vb);
  710. Dictionary drag_data;
  711. drag_data["type"] = "nodes";
  712. drag_data["nodes"] = objs;
  713. tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN | Tree::DROP_MODE_ON_ITEM);
  714. return drag_data;
  715. }
  716. bool SceneTreeEditor::_is_script_type(const StringName &p_type) const {
  717. return (script_types->find(p_type));
  718. }
  719. bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  720. if (!can_rename)
  721. return false; //not editable tree
  722. if (filter != String())
  723. return false; //can't rearrange tree with filter turned on
  724. Dictionary d = p_data;
  725. if (!d.has("type"))
  726. return false;
  727. TreeItem *item = tree->get_item_at_pos(p_point);
  728. if (!item)
  729. return false;
  730. int section = tree->get_drop_section_at_pos(p_point);
  731. if (section < -1 || (section == -1 && !item->get_parent()))
  732. return false;
  733. if (String(d["type"]) == "files") {
  734. Vector<String> files = d["files"];
  735. if (files.size() == 0)
  736. return false; //weird
  737. if (_is_script_type(EditorFileSystem::get_singleton()->get_file_type(files[0]))) {
  738. tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
  739. return true;
  740. }
  741. for (int i = 0; i < files.size(); i++) {
  742. String file = files[i];
  743. String ftype = EditorFileSystem::get_singleton()->get_file_type(file);
  744. if (ftype != "PackedScene")
  745. return false;
  746. }
  747. tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN | Tree::DROP_MODE_ON_ITEM); //so it works..
  748. return true;
  749. }
  750. if (String(d["type"]) == "nodes") {
  751. return true;
  752. }
  753. return false;
  754. }
  755. void SceneTreeEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  756. if (!can_drop_data_fw(p_point, p_data, p_from))
  757. return;
  758. TreeItem *item = tree->get_item_at_pos(p_point);
  759. if (!item)
  760. return;
  761. int section = tree->get_drop_section_at_pos(p_point);
  762. if (section < -1)
  763. return;
  764. NodePath np = item->get_metadata(0);
  765. Node *n = get_node(np);
  766. if (!n)
  767. return;
  768. Dictionary d = p_data;
  769. if (String(d["type"]) == "nodes") {
  770. Array nodes = d["nodes"];
  771. emit_signal("nodes_rearranged", nodes, np, section);
  772. }
  773. if (String(d["type"]) == "files") {
  774. Vector<String> files = d["files"];
  775. String ftype = EditorFileSystem::get_singleton()->get_file_type(files[0]);
  776. if (_is_script_type(ftype)) {
  777. emit_signal("script_dropped", files[0], np);
  778. } else {
  779. emit_signal("files_dropped", files, np, section);
  780. }
  781. }
  782. }
  783. void SceneTreeEditor::_rmb_select(const Vector2 &p_pos) {
  784. emit_signal("rmb_pressed", tree->get_global_transform().xform(p_pos));
  785. }
  786. void SceneTreeEditor::_warning_changed(Node *p_for_node) {
  787. //should use a timer
  788. update_timer->start();
  789. // print_line("WARNING CHANGED "+String(p_for_node->get_name()));
  790. }
  791. void SceneTreeEditor::_editor_settings_changed() {
  792. bool enable_rl = EditorSettings::get_singleton()->get("scenetree_editor/draw_relationship_lines");
  793. Color rl_color = EditorSettings::get_singleton()->get("scenetree_editor/relationship_line_color");
  794. if (enable_rl) {
  795. tree->add_constant_override("draw_relationship_lines", 1);
  796. tree->add_color_override("relationship_line_color", rl_color);
  797. } else
  798. tree->add_constant_override("draw_relationship_lines", 0);
  799. }
  800. void SceneTreeEditor::_bind_methods() {
  801. ObjectTypeDB::bind_method("_tree_changed", &SceneTreeEditor::_tree_changed);
  802. ObjectTypeDB::bind_method("_update_tree", &SceneTreeEditor::_update_tree);
  803. ObjectTypeDB::bind_method("_node_removed", &SceneTreeEditor::_node_removed);
  804. ObjectTypeDB::bind_method("_selected_changed", &SceneTreeEditor::_selected_changed);
  805. ObjectTypeDB::bind_method("_renamed", &SceneTreeEditor::_renamed);
  806. ObjectTypeDB::bind_method("_rename_node", &SceneTreeEditor::_rename_node);
  807. ObjectTypeDB::bind_method("_test_update_tree", &SceneTreeEditor::_test_update_tree);
  808. ObjectTypeDB::bind_method("_cell_multi_selected", &SceneTreeEditor::_cell_multi_selected);
  809. ObjectTypeDB::bind_method("_selection_changed", &SceneTreeEditor::_selection_changed);
  810. ObjectTypeDB::bind_method("_cell_button_pressed", &SceneTreeEditor::_cell_button_pressed);
  811. ObjectTypeDB::bind_method("_cell_collapsed", &SceneTreeEditor::_cell_collapsed);
  812. ObjectTypeDB::bind_method("_subscene_option", &SceneTreeEditor::_subscene_option);
  813. ObjectTypeDB::bind_method("_rmb_select", &SceneTreeEditor::_rmb_select);
  814. ObjectTypeDB::bind_method("_warning_changed", &SceneTreeEditor::_warning_changed);
  815. ObjectTypeDB::bind_method("_node_script_changed", &SceneTreeEditor::_node_script_changed);
  816. ObjectTypeDB::bind_method("_node_visibility_changed", &SceneTreeEditor::_node_visibility_changed);
  817. ObjectTypeDB::bind_method("_editor_settings_changed", &SceneTreeEditor::_editor_settings_changed);
  818. ObjectTypeDB::bind_method(_MD("get_drag_data_fw"), &SceneTreeEditor::get_drag_data_fw);
  819. ObjectTypeDB::bind_method(_MD("can_drop_data_fw"), &SceneTreeEditor::can_drop_data_fw);
  820. ObjectTypeDB::bind_method(_MD("drop_data_fw"), &SceneTreeEditor::drop_data_fw);
  821. ObjectTypeDB::bind_method(_MD("update_tree"), &SceneTreeEditor::update_tree);
  822. ADD_SIGNAL(MethodInfo("node_selected"));
  823. ADD_SIGNAL(MethodInfo("node_renamed"));
  824. ADD_SIGNAL(MethodInfo("node_prerename"));
  825. ADD_SIGNAL(MethodInfo("node_changed"));
  826. ADD_SIGNAL(MethodInfo("nodes_rearranged", PropertyInfo(Variant::ARRAY, "paths"), PropertyInfo(Variant::NODE_PATH, "to_path"), PropertyInfo(Variant::INT, "type")));
  827. ADD_SIGNAL(MethodInfo("files_dropped", PropertyInfo(Variant::STRING_ARRAY, "files"), PropertyInfo(Variant::NODE_PATH, "to_path"), PropertyInfo(Variant::INT, "type")));
  828. ADD_SIGNAL(MethodInfo("script_dropped", PropertyInfo(Variant::STRING, "file"), PropertyInfo(Variant::NODE_PATH, "to_path")));
  829. ADD_SIGNAL(MethodInfo("rmb_pressed", PropertyInfo(Variant::VECTOR2, "pos")));
  830. ADD_SIGNAL(MethodInfo("open"));
  831. ADD_SIGNAL(MethodInfo("open_script"));
  832. }
  833. SceneTreeEditor::SceneTreeEditor(bool p_label, bool p_can_rename, bool p_can_open_instance) {
  834. undo_redo = NULL;
  835. tree_dirty = true;
  836. selected = NULL;
  837. marked_selectable = false;
  838. marked_children_selectable = false;
  839. can_rename = p_can_rename;
  840. can_open_instance = p_can_open_instance;
  841. display_foreign = false;
  842. editor_selection = NULL;
  843. if (p_label) {
  844. Label *label = memnew(Label);
  845. label->set_pos(Point2(10, 0));
  846. label->set_text(TTR("Scene Tree (Nodes):"));
  847. add_child(label);
  848. }
  849. tree = memnew(Tree);
  850. tree->set_anchor(MARGIN_RIGHT, ANCHOR_END);
  851. tree->set_anchor(MARGIN_BOTTOM, ANCHOR_END);
  852. tree->set_begin(Point2(0, p_label ? 18 : 0));
  853. tree->set_end(Point2(0, 0));
  854. tree->add_constant_override("button_margin", 0);
  855. add_child(tree);
  856. tree->set_drag_forwarding(this);
  857. if (p_can_rename) {
  858. tree->set_allow_rmb_select(true);
  859. tree->connect("item_rmb_selected", this, "_rmb_select");
  860. tree->connect("empty_tree_rmb_selected", this, "_rmb_select");
  861. }
  862. tree->connect("cell_selected", this, "_selected_changed");
  863. tree->connect("item_edited", this, "_renamed", varray(), CONNECT_DEFERRED);
  864. tree->connect("multi_selected", this, "_cell_multi_selected");
  865. tree->connect("button_pressed", this, "_cell_button_pressed");
  866. // tree->connect("item_edited", this,"_renamed",Vector<Variant>(),true);
  867. error = memnew(AcceptDialog);
  868. add_child(error);
  869. warning = memnew(AcceptDialog);
  870. add_child(warning);
  871. warning->set_title("Node Configuration Warning!");
  872. show_enabled_subscene = false;
  873. last_hash = 0;
  874. pending_test_update = false;
  875. updating_tree = false;
  876. blocked = 0;
  877. instance_menu = memnew(PopupMenu);
  878. instance_menu->add_check_item(TTR("Editable Children"), SCENE_MENU_EDITABLE_CHILDREN);
  879. instance_menu->add_check_item(TTR("Load As Placeholder"), SCENE_MENU_USE_PLACEHOLDER);
  880. instance_menu->add_separator();
  881. instance_menu->add_item(TTR("Discard Instancing"), SCENE_MENU_CLEAR_INSTANCING);
  882. instance_menu->add_separator();
  883. instance_menu->add_item(TTR("Open in Editor"), SCENE_MENU_OPEN);
  884. instance_menu->connect("item_pressed", this, "_subscene_option");
  885. add_child(instance_menu);
  886. inheritance_menu = memnew(PopupMenu);
  887. inheritance_menu->add_item(TTR("Clear Inheritance"), SCENE_MENU_CLEAR_INHERITANCE);
  888. inheritance_menu->add_separator();
  889. inheritance_menu->add_item(TTR("Open in Editor"), SCENE_MENU_OPEN_INHERITED);
  890. inheritance_menu->connect("item_pressed", this, "_subscene_option");
  891. add_child(inheritance_menu);
  892. clear_inherit_confirm = memnew(ConfirmationDialog);
  893. clear_inherit_confirm->set_text(TTR("Clear Inheritance? (No Undo!)"));
  894. clear_inherit_confirm->get_ok()->set_text(TTR("Clear!"));
  895. add_child(clear_inherit_confirm);
  896. update_timer = memnew(Timer);
  897. update_timer->connect("timeout", this, "_update_tree");
  898. update_timer->set_one_shot(true);
  899. update_timer->set_wait_time(0.5);
  900. add_child(update_timer);
  901. script_types = memnew(List<StringName>);
  902. ObjectTypeDB::get_inheriters_from("Script", script_types);
  903. }
  904. SceneTreeEditor::~SceneTreeEditor() {
  905. memdelete(script_types);
  906. }
  907. /******** DIALOG *********/
  908. void SceneTreeDialog::_notification(int p_what) {
  909. if (p_what == NOTIFICATION_ENTER_TREE) {
  910. connect("confirmed", this, "_select");
  911. }
  912. if (p_what == NOTIFICATION_EXIT_TREE) {
  913. disconnect("confirmed", this, "_select");
  914. }
  915. if (p_what == NOTIFICATION_DRAW) {
  916. RID ci = get_canvas_item();
  917. get_stylebox("panel", "PopupMenu")->draw(ci, Rect2(Point2(), get_size()));
  918. }
  919. if (p_what == NOTIFICATION_VISIBILITY_CHANGED && is_visible()) {
  920. tree->update_tree();
  921. }
  922. }
  923. void SceneTreeDialog::_cancel() {
  924. hide();
  925. }
  926. void SceneTreeDialog::_select() {
  927. if (tree->get_selected()) {
  928. emit_signal("selected", tree->get_selected()->get_path());
  929. hide();
  930. }
  931. }
  932. void SceneTreeDialog::_bind_methods() {
  933. ObjectTypeDB::bind_method("_select", &SceneTreeDialog::_select);
  934. ObjectTypeDB::bind_method("_cancel", &SceneTreeDialog::_cancel);
  935. ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::NODE_PATH, "path")));
  936. }
  937. SceneTreeDialog::SceneTreeDialog() {
  938. set_title(TTR("Select a Node"));
  939. tree = memnew(SceneTreeEditor(false, false));
  940. add_child(tree);
  941. set_child_rect(tree);
  942. tree->get_scene_tree()->connect("item_activated", this, "_select");
  943. }
  944. SceneTreeDialog::~SceneTreeDialog() {
  945. }