scene_tree_editor.cpp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  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 "core/message_queue.h"
  32. #include "core/print_string.h"
  33. #include "editor/editor_node.h"
  34. #include "editor/node_dock.h"
  35. #include "editor/plugins/animation_player_editor_plugin.h"
  36. #include "editor/plugins/canvas_item_editor_plugin.h"
  37. #include "scene/gui/label.h"
  38. #include "scene/main/window.h"
  39. #include "scene/resources/packed_scene.h"
  40. Node *SceneTreeEditor::get_scene_node() {
  41. ERR_FAIL_COND_V(!is_inside_tree(), nullptr);
  42. return get_tree()->get_edited_scene_root();
  43. }
  44. void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_id) {
  45. if (connect_to_script_mode) {
  46. return; //don't do anything in this mode
  47. }
  48. TreeItem *item = Object::cast_to<TreeItem>(p_item);
  49. ERR_FAIL_COND(!item);
  50. NodePath np = item->get_metadata(0);
  51. Node *n = get_node(np);
  52. ERR_FAIL_COND(!n);
  53. if (p_id == BUTTON_SUBSCENE) {
  54. if (n == get_scene_node()) {
  55. if (n && n->get_scene_inherited_state().is_valid()) {
  56. emit_signal("open", n->get_scene_inherited_state()->get_path());
  57. }
  58. } else {
  59. emit_signal("open", n->get_filename());
  60. }
  61. } else if (p_id == BUTTON_SCRIPT) {
  62. Ref<Script> script_typed = n->get_script();
  63. if (!script_typed.is_null())
  64. emit_signal("open_script", script_typed);
  65. } else if (p_id == BUTTON_VISIBILITY) {
  66. undo_redo->create_action(TTR("Toggle Visible"));
  67. _toggle_visible(n);
  68. List<Node *> selection = editor_selection->get_selected_node_list();
  69. if (selection.size() > 1 && selection.find(n) != nullptr) {
  70. for (List<Node *>::Element *E = selection.front(); E; E = E->next()) {
  71. Node *nv = E->get();
  72. ERR_FAIL_COND(!nv);
  73. if (nv == n) {
  74. continue;
  75. }
  76. _toggle_visible(nv);
  77. }
  78. }
  79. undo_redo->commit_action();
  80. } else if (p_id == BUTTON_LOCK) {
  81. undo_redo->create_action(TTR("Unlock Node"));
  82. if (n->is_class("CanvasItem") || n->is_class("Node3D")) {
  83. undo_redo->add_do_method(n, "remove_meta", "_edit_lock_");
  84. undo_redo->add_undo_method(n, "set_meta", "_edit_lock_", true);
  85. undo_redo->add_do_method(this, "_update_tree", Variant());
  86. undo_redo->add_undo_method(this, "_update_tree", Variant());
  87. undo_redo->add_do_method(this, "emit_signal", "node_changed");
  88. undo_redo->add_undo_method(this, "emit_signal", "node_changed");
  89. }
  90. undo_redo->commit_action();
  91. } else if (p_id == BUTTON_PIN) {
  92. if (n->is_class("AnimationPlayer")) {
  93. AnimationPlayerEditor::singleton->unpin();
  94. _update_tree();
  95. }
  96. } else if (p_id == BUTTON_GROUP) {
  97. undo_redo->create_action(TTR("Button Group"));
  98. if (n->is_class("CanvasItem") || n->is_class("Node3D")) {
  99. undo_redo->add_do_method(n, "remove_meta", "_edit_group_");
  100. undo_redo->add_undo_method(n, "set_meta", "_edit_group_", true);
  101. undo_redo->add_do_method(this, "_update_tree", Variant());
  102. undo_redo->add_undo_method(this, "_update_tree", Variant());
  103. undo_redo->add_do_method(this, "emit_signal", "node_changed");
  104. undo_redo->add_undo_method(this, "emit_signal", "node_changed");
  105. }
  106. undo_redo->commit_action();
  107. } else if (p_id == BUTTON_WARNING) {
  108. String config_err = n->get_configuration_warning();
  109. if (config_err == String())
  110. return;
  111. config_err = config_err.word_wrap(80);
  112. warning->set_text(config_err);
  113. warning->popup_centered();
  114. } else if (p_id == BUTTON_SIGNALS) {
  115. editor_selection->clear();
  116. editor_selection->add_node(n);
  117. set_selected(n);
  118. NodeDock::singleton->get_parent()->call("set_current_tab", NodeDock::singleton->get_index());
  119. NodeDock::singleton->show_connections();
  120. } else if (p_id == BUTTON_GROUPS) {
  121. editor_selection->clear();
  122. editor_selection->add_node(n);
  123. set_selected(n);
  124. NodeDock::singleton->get_parent()->call("set_current_tab", NodeDock::singleton->get_index());
  125. NodeDock::singleton->show_groups();
  126. }
  127. }
  128. void SceneTreeEditor::_toggle_visible(Node *p_node) {
  129. if (p_node->has_method("is_visible") && p_node->has_method("set_visible")) {
  130. bool v = bool(p_node->call("is_visible"));
  131. undo_redo->add_do_method(p_node, "set_visible", !v);
  132. undo_redo->add_undo_method(p_node, "set_visible", v);
  133. }
  134. }
  135. bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) {
  136. if (!p_node)
  137. return false;
  138. // only owned nodes are editable, since nodes can create their own (manually owned) child nodes,
  139. // which the editor needs not to know about.
  140. bool part_of_subscene = false;
  141. if (!display_foreign && p_node->get_owner() != get_scene_node() && p_node != get_scene_node()) {
  142. if ((show_enabled_subscene || can_open_instance) && p_node->get_owner() && (get_scene_node()->is_editable_instance(p_node->get_owner()))) {
  143. part_of_subscene = true;
  144. //allow
  145. } else {
  146. return false;
  147. }
  148. } else {
  149. 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;
  150. }
  151. TreeItem *item = tree->create_item(p_parent);
  152. item->set_text(0, p_node->get_name());
  153. if (can_rename && !part_of_subscene)
  154. item->set_editable(0, true);
  155. item->set_selectable(0, true);
  156. if (can_rename) {
  157. bool collapsed = p_node->is_displayed_folded();
  158. if (collapsed)
  159. item->set_collapsed(true);
  160. }
  161. Ref<Texture2D> icon = EditorNode::get_singleton()->get_object_icon(p_node, "Node");
  162. item->set_icon(0, icon);
  163. item->set_metadata(0, p_node->get_path());
  164. if (connect_to_script_mode) {
  165. Color accent = get_theme_color("accent_color", "Editor");
  166. Ref<Script> script = p_node->get_script();
  167. if (!script.is_null() && EditorNode::get_singleton()->get_object_custom_type_base(p_node) != script) {
  168. //has script
  169. item->add_button(0, get_theme_icon("Script", "EditorIcons"), BUTTON_SCRIPT);
  170. } else {
  171. //has no script (or script is a custom type)
  172. item->set_custom_color(0, get_theme_color("disabled_font_color", "Editor"));
  173. item->set_selectable(0, false);
  174. if (!script.is_null()) { // make sure to mark the script if a custom type
  175. item->add_button(0, get_theme_icon("Script", "EditorIcons"), BUTTON_SCRIPT);
  176. item->set_button_disabled(0, item->get_button_count(0) - 1, true);
  177. }
  178. accent.a *= 0.7;
  179. }
  180. if (marked.has(p_node)) {
  181. String node_name = p_node->get_name();
  182. if (connecting_signal) {
  183. node_name += " " + TTR("(Connecting From)");
  184. }
  185. item->set_text(0, node_name);
  186. item->set_custom_color(0, accent);
  187. }
  188. } else if (part_of_subscene) {
  189. if (valid_types.size() == 0) {
  190. item->set_custom_color(0, get_theme_color("disabled_font_color", "Editor"));
  191. }
  192. } else if (marked.has(p_node)) {
  193. String node_name = p_node->get_name();
  194. if (connecting_signal) {
  195. node_name += " " + TTR("(Connecting From)");
  196. }
  197. item->set_text(0, node_name);
  198. item->set_selectable(0, marked_selectable);
  199. item->set_custom_color(0, get_theme_color("accent_color", "Editor"));
  200. } else if (!marked_selectable && !marked_children_selectable) {
  201. Node *node = p_node;
  202. while (node) {
  203. if (marked.has(node)) {
  204. item->set_selectable(0, false);
  205. item->set_custom_color(0, get_theme_color("error_color", "Editor"));
  206. break;
  207. }
  208. node = node->get_parent();
  209. }
  210. }
  211. if (can_rename) { //should be can edit..
  212. String warning = p_node->get_configuration_warning();
  213. if (warning != String()) {
  214. item->add_button(0, get_theme_icon("NodeWarning", "EditorIcons"), BUTTON_WARNING, false, TTR("Node configuration warning:") + "\n" + p_node->get_configuration_warning());
  215. }
  216. int num_connections = p_node->get_persistent_signal_connection_count();
  217. int num_groups = p_node->get_persistent_group_count();
  218. if (num_connections >= 1 && num_groups >= 1) {
  219. item->add_button(
  220. 0,
  221. get_theme_icon("SignalsAndGroups", "EditorIcons"),
  222. BUTTON_SIGNALS,
  223. false,
  224. vformat(TTR("Node has %s connection(s) and %s group(s).\nClick to show signals dock."), num_connections, num_groups));
  225. } else if (num_connections >= 1) {
  226. item->add_button(
  227. 0,
  228. get_theme_icon("Signals", "EditorIcons"),
  229. BUTTON_SIGNALS,
  230. false,
  231. vformat(TTR("Node has %s connection(s).\nClick to show signals dock."), num_connections));
  232. } else if (num_groups >= 1) {
  233. item->add_button(
  234. 0,
  235. get_theme_icon("Groups", "EditorIcons"),
  236. BUTTON_GROUPS,
  237. false,
  238. vformat(TTR("Node is in %s group(s).\nClick to show groups dock."), num_groups));
  239. }
  240. }
  241. if (p_node == get_scene_node() && p_node->get_scene_inherited_state().is_valid()) {
  242. item->add_button(0, get_theme_icon("InstanceOptions", "EditorIcons"), BUTTON_SUBSCENE, false, TTR("Open in Editor"));
  243. String tooltip = TTR("Inherits:") + " " + p_node->get_scene_inherited_state()->get_path() + "\n" + TTR("Type:") + " " + p_node->get_class();
  244. if (p_node->get_editor_description() != String()) {
  245. tooltip += "\n\n" + p_node->get_editor_description();
  246. }
  247. item->set_tooltip(0, tooltip);
  248. } else if (p_node != get_scene_node() && p_node->get_filename() != "" && can_open_instance) {
  249. item->add_button(0, get_theme_icon("InstanceOptions", "EditorIcons"), BUTTON_SUBSCENE, false, TTR("Open in Editor"));
  250. String tooltip = TTR("Instance:") + " " + p_node->get_filename() + "\n" + TTR("Type:") + " " + p_node->get_class();
  251. if (p_node->get_editor_description() != String()) {
  252. tooltip += "\n\n" + p_node->get_editor_description();
  253. }
  254. item->set_tooltip(0, tooltip);
  255. } else {
  256. StringName type = EditorNode::get_singleton()->get_object_custom_type_name(p_node);
  257. if (type == StringName()) {
  258. type = p_node->get_class();
  259. }
  260. String tooltip = TTR("Type:") + " " + type;
  261. if (p_node->get_editor_description() != String()) {
  262. tooltip += "\n\n" + p_node->get_editor_description();
  263. }
  264. item->set_tooltip(0, tooltip);
  265. }
  266. if (can_open_instance && undo_redo) { //Show buttons only when necessary(SceneTreeDock) to avoid crashes
  267. if (!p_node->is_connected("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed)))
  268. p_node->connect("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed), varray(p_node));
  269. Ref<Script> script = p_node->get_script();
  270. if (!script.is_null()) {
  271. item->add_button(0, get_theme_icon("Script", "EditorIcons"), BUTTON_SCRIPT, false, TTR("Open Script:") + " " + script->get_path());
  272. if (EditorNode::get_singleton()->get_object_custom_type_base(p_node) == script) {
  273. item->set_button_color(0, item->get_button_count(0) - 1, Color(1, 1, 1, 0.5));
  274. }
  275. }
  276. if (p_node->is_class("CanvasItem")) {
  277. bool is_locked = p_node->has_meta("_edit_lock_"); //_edit_group_
  278. if (is_locked)
  279. item->add_button(0, get_theme_icon("Lock", "EditorIcons"), BUTTON_LOCK, false, TTR("Node is locked.\nClick to unlock it."));
  280. bool is_grouped = p_node->has_meta("_edit_group_");
  281. if (is_grouped)
  282. item->add_button(0, get_theme_icon("Group", "EditorIcons"), BUTTON_GROUP, false, TTR("Children are not selectable.\nClick to make selectable."));
  283. bool v = p_node->call("is_visible");
  284. if (v)
  285. item->add_button(0, get_theme_icon("GuiVisibilityVisible", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
  286. else
  287. item->add_button(0, get_theme_icon("GuiVisibilityHidden", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
  288. if (!p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed)))
  289. p_node->connect("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed), varray(p_node));
  290. _update_visibility_color(p_node, item);
  291. } else if (p_node->is_class("Node3D")) {
  292. bool is_locked = p_node->has_meta("_edit_lock_");
  293. if (is_locked)
  294. item->add_button(0, get_theme_icon("Lock", "EditorIcons"), BUTTON_LOCK, false, TTR("Node is locked.\nClick to unlock it."));
  295. bool is_grouped = p_node->has_meta("_edit_group_");
  296. if (is_grouped)
  297. item->add_button(0, get_theme_icon("Group", "EditorIcons"), BUTTON_GROUP, false, TTR("Children are not selectable.\nClick to make selectable."));
  298. bool v = p_node->call("is_visible");
  299. if (v)
  300. item->add_button(0, get_theme_icon("GuiVisibilityVisible", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
  301. else
  302. item->add_button(0, get_theme_icon("GuiVisibilityHidden", "EditorIcons"), BUTTON_VISIBILITY, false, TTR("Toggle Visibility"));
  303. if (!p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed)))
  304. p_node->connect("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed), varray(p_node));
  305. _update_visibility_color(p_node, item);
  306. } else if (p_node->is_class("AnimationPlayer")) {
  307. bool is_pinned = AnimationPlayerEditor::singleton->get_player() == p_node && AnimationPlayerEditor::singleton->is_pinned();
  308. if (is_pinned) {
  309. item->add_button(0, get_theme_icon("Pin", "EditorIcons"), BUTTON_PIN, false, TTR("AnimationPlayer is pinned.\nClick to unpin."));
  310. }
  311. }
  312. }
  313. if (editor_selection) {
  314. if (editor_selection->is_selected(p_node)) {
  315. item->select(0);
  316. }
  317. }
  318. if (selected == p_node) {
  319. if (!editor_selection)
  320. item->select(0);
  321. item->set_as_cursor(0);
  322. }
  323. bool keep = (filter.is_subsequence_ofi(String(p_node->get_name())));
  324. for (int i = 0; i < p_node->get_child_count(); i++) {
  325. bool child_keep = _add_nodes(p_node->get_child(i), item);
  326. keep = keep || child_keep;
  327. }
  328. if (valid_types.size()) {
  329. bool valid = false;
  330. for (int i = 0; i < valid_types.size(); i++) {
  331. if (p_node->is_class(valid_types[i])) {
  332. valid = true;
  333. break;
  334. }
  335. }
  336. if (!valid) {
  337. //item->set_selectable(0,marked_selectable);
  338. item->set_custom_color(0, get_theme_color("disabled_font_color", "Editor"));
  339. item->set_selectable(0, false);
  340. }
  341. }
  342. if (!keep) {
  343. if (editor_selection) {
  344. Node *n = get_node(item->get_metadata(0));
  345. if (n) {
  346. editor_selection->remove_node(n);
  347. }
  348. }
  349. memdelete(item);
  350. return false;
  351. } else {
  352. return true;
  353. }
  354. }
  355. void SceneTreeEditor::_node_visibility_changed(Node *p_node) {
  356. if (!p_node || (p_node != get_scene_node() && !p_node->get_owner())) {
  357. return;
  358. }
  359. TreeItem *item = _find(tree->get_root(), p_node->get_path());
  360. if (!item) {
  361. return;
  362. }
  363. int idx = item->get_button_by_id(0, BUTTON_VISIBILITY);
  364. ERR_FAIL_COND(idx == -1);
  365. bool visible = false;
  366. if (p_node->is_class("CanvasItem")) {
  367. visible = p_node->call("is_visible");
  368. CanvasItemEditor::get_singleton()->get_viewport_control()->update();
  369. } else if (p_node->is_class("Node3D")) {
  370. visible = p_node->call("is_visible");
  371. }
  372. if (visible)
  373. item->set_button(0, idx, get_theme_icon("GuiVisibilityVisible", "EditorIcons"));
  374. else
  375. item->set_button(0, idx, get_theme_icon("GuiVisibilityHidden", "EditorIcons"));
  376. _update_visibility_color(p_node, item);
  377. }
  378. void SceneTreeEditor::_update_visibility_color(Node *p_node, TreeItem *p_item) {
  379. if (p_node->is_class("CanvasItem") || p_node->is_class("Node3D")) {
  380. Color color(1, 1, 1, 1);
  381. bool visible_on_screen = p_node->call("is_visible_in_tree");
  382. if (!visible_on_screen) {
  383. color.a = 0.6;
  384. }
  385. int idx = p_item->get_button_by_id(0, BUTTON_VISIBILITY);
  386. p_item->set_button_color(0, idx, color);
  387. }
  388. }
  389. void SceneTreeEditor::_node_script_changed(Node *p_node) {
  390. if (tree_dirty)
  391. return;
  392. MessageQueue::get_singleton()->push_call(this, "_update_tree");
  393. tree_dirty = true;
  394. }
  395. void SceneTreeEditor::_node_removed(Node *p_node) {
  396. if (EditorNode::get_singleton()->is_exiting())
  397. return; //speed up exit
  398. if (p_node->is_connected("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed)))
  399. p_node->disconnect("script_changed", callable_mp(this, &SceneTreeEditor::_node_script_changed));
  400. if (p_node->is_class("Node3D") || p_node->is_class("CanvasItem")) {
  401. if (p_node->is_connected("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed)))
  402. p_node->disconnect("visibility_changed", callable_mp(this, &SceneTreeEditor::_node_visibility_changed));
  403. }
  404. if (p_node == selected) {
  405. selected = nullptr;
  406. emit_signal("node_selected");
  407. }
  408. }
  409. void SceneTreeEditor::_node_renamed(Node *p_node) {
  410. emit_signal("node_renamed");
  411. if (!tree_dirty) {
  412. MessageQueue::get_singleton()->push_call(this, "_update_tree");
  413. tree_dirty = true;
  414. }
  415. }
  416. void SceneTreeEditor::_update_tree() {
  417. if (!is_inside_tree()) {
  418. tree_dirty = false;
  419. return;
  420. }
  421. updating_tree = true;
  422. tree->clear();
  423. if (get_scene_node()) {
  424. _add_nodes(get_scene_node(), nullptr);
  425. last_hash = hash_djb2_one_64(0);
  426. _compute_hash(get_scene_node(), last_hash);
  427. }
  428. updating_tree = false;
  429. tree_dirty = false;
  430. }
  431. void SceneTreeEditor::_compute_hash(Node *p_node, uint64_t &hash) {
  432. hash = hash_djb2_one_64(p_node->get_instance_id(), hash);
  433. if (p_node->get_parent())
  434. hash = hash_djb2_one_64(p_node->get_parent()->get_instance_id(), hash); //so a reparent still produces a different hash
  435. for (int i = 0; i < p_node->get_child_count(); i++) {
  436. _compute_hash(p_node->get_child(i), hash);
  437. }
  438. }
  439. void SceneTreeEditor::_test_update_tree() {
  440. pending_test_update = false;
  441. if (!is_inside_tree())
  442. return;
  443. if (tree_dirty)
  444. return; // don't even bother
  445. uint64_t hash = hash_djb2_one_64(0);
  446. if (get_scene_node())
  447. _compute_hash(get_scene_node(), hash);
  448. //test hash
  449. if (hash == last_hash)
  450. return; // did not change
  451. MessageQueue::get_singleton()->push_call(this, "_update_tree");
  452. tree_dirty = true;
  453. }
  454. void SceneTreeEditor::_tree_changed() {
  455. if (EditorNode::get_singleton()->is_exiting())
  456. return; //speed up exit
  457. if (pending_test_update)
  458. return;
  459. if (tree_dirty)
  460. return;
  461. MessageQueue::get_singleton()->push_call(this, "_test_update_tree");
  462. pending_test_update = true;
  463. }
  464. void SceneTreeEditor::_selected_changed() {
  465. TreeItem *s = tree->get_selected();
  466. ERR_FAIL_COND(!s);
  467. NodePath np = s->get_metadata(0);
  468. Node *n = get_node(np);
  469. if (n == selected)
  470. return;
  471. selected = get_node(np);
  472. blocked++;
  473. emit_signal("node_selected");
  474. blocked--;
  475. }
  476. void SceneTreeEditor::_deselect_items() {
  477. // Clear currently elected items in scene tree dock.
  478. if (editor_selection) {
  479. editor_selection->clear();
  480. emit_signal("node_changed");
  481. }
  482. }
  483. void SceneTreeEditor::_cell_multi_selected(Object *p_object, int p_cell, bool p_selected) {
  484. TreeItem *item = Object::cast_to<TreeItem>(p_object);
  485. ERR_FAIL_COND(!item);
  486. NodePath np = item->get_metadata(0);
  487. Node *n = get_node(np);
  488. if (!n)
  489. return;
  490. if (!editor_selection)
  491. return;
  492. if (p_selected) {
  493. editor_selection->add_node(n);
  494. } else {
  495. editor_selection->remove_node(n);
  496. }
  497. emit_signal("node_changed");
  498. }
  499. void SceneTreeEditor::_notification(int p_what) {
  500. switch (p_what) {
  501. case NOTIFICATION_ENTER_TREE: {
  502. get_tree()->connect("tree_changed", callable_mp(this, &SceneTreeEditor::_tree_changed));
  503. get_tree()->connect("node_removed", callable_mp(this, &SceneTreeEditor::_node_removed));
  504. get_tree()->connect("node_renamed", callable_mp(this, &SceneTreeEditor::_node_renamed));
  505. get_tree()->connect("node_configuration_warning_changed", callable_mp(this, &SceneTreeEditor::_warning_changed));
  506. tree->connect("item_collapsed", callable_mp(this, &SceneTreeEditor::_cell_collapsed));
  507. _update_tree();
  508. } break;
  509. case NOTIFICATION_EXIT_TREE: {
  510. get_tree()->disconnect("tree_changed", callable_mp(this, &SceneTreeEditor::_tree_changed));
  511. get_tree()->disconnect("node_removed", callable_mp(this, &SceneTreeEditor::_node_removed));
  512. get_tree()->disconnect("node_renamed", callable_mp(this, &SceneTreeEditor::_node_renamed));
  513. tree->disconnect("item_collapsed", callable_mp(this, &SceneTreeEditor::_cell_collapsed));
  514. get_tree()->disconnect("node_configuration_warning_changed", callable_mp(this, &SceneTreeEditor::_warning_changed));
  515. } break;
  516. case NOTIFICATION_THEME_CHANGED: {
  517. _update_tree();
  518. } break;
  519. }
  520. }
  521. TreeItem *SceneTreeEditor::_find(TreeItem *p_node, const NodePath &p_path) {
  522. if (!p_node)
  523. return nullptr;
  524. NodePath np = p_node->get_metadata(0);
  525. if (np == p_path)
  526. return p_node;
  527. TreeItem *children = p_node->get_children();
  528. while (children) {
  529. TreeItem *n = _find(children, p_path);
  530. if (n)
  531. return n;
  532. children = children->get_next();
  533. }
  534. return nullptr;
  535. }
  536. void SceneTreeEditor::set_selected(Node *p_node, bool p_emit_selected) {
  537. ERR_FAIL_COND(blocked > 0);
  538. if (pending_test_update)
  539. _test_update_tree();
  540. if (tree_dirty)
  541. _update_tree();
  542. if (selected == p_node)
  543. return;
  544. TreeItem *item = p_node ? _find(tree->get_root(), p_node->get_path()) : nullptr;
  545. if (item) {
  546. // make visible when it's collapsed
  547. TreeItem *node = item->get_parent();
  548. while (node && node != tree->get_root()) {
  549. node->set_collapsed(false);
  550. node = node->get_parent();
  551. }
  552. item->select(0);
  553. item->set_as_cursor(0);
  554. selected = p_node;
  555. tree->ensure_cursor_is_visible();
  556. } else {
  557. if (!p_node)
  558. selected = nullptr;
  559. _update_tree();
  560. selected = p_node;
  561. }
  562. if (p_emit_selected) {
  563. emit_signal("node_selected");
  564. }
  565. }
  566. void SceneTreeEditor::_rename_node(ObjectID p_node, const String &p_name) {
  567. Object *o = ObjectDB::get_instance(p_node);
  568. ERR_FAIL_COND(!o);
  569. Node *n = Object::cast_to<Node>(o);
  570. ERR_FAIL_COND(!n);
  571. TreeItem *item = _find(tree->get_root(), n->get_path());
  572. ERR_FAIL_COND(!item);
  573. n->set_name(p_name);
  574. item->set_metadata(0, n->get_path());
  575. item->set_text(0, p_name);
  576. }
  577. void SceneTreeEditor::_renamed() {
  578. TreeItem *which = tree->get_edited();
  579. ERR_FAIL_COND(!which);
  580. NodePath np = which->get_metadata(0);
  581. Node *n = get_node(np);
  582. ERR_FAIL_COND(!n);
  583. // Empty node names are not allowed, so resets it to previous text and show warning
  584. if (which->get_text(0).strip_edges().empty()) {
  585. which->set_text(0, n->get_name());
  586. EditorNode::get_singleton()->show_warning(TTR("No name provided."));
  587. return;
  588. }
  589. String new_name = which->get_text(0);
  590. if (!Node::_validate_node_name(new_name)) {
  591. error->set_text(TTR("Invalid node name, the following characters are not allowed:") + "\n" + Node::invalid_character);
  592. error->popup_centered();
  593. if (new_name.empty()) {
  594. which->set_text(0, n->get_name());
  595. return;
  596. }
  597. which->set_text(0, new_name);
  598. }
  599. if (new_name == n->get_name())
  600. return;
  601. if (!undo_redo) {
  602. n->set_name(new_name);
  603. which->set_metadata(0, n->get_path());
  604. emit_signal("node_renamed");
  605. } else {
  606. undo_redo->create_action(TTR("Rename Node"));
  607. emit_signal("node_prerename", n, new_name);
  608. undo_redo->add_do_method(this, "_rename_node", n->get_instance_id(), new_name);
  609. undo_redo->add_undo_method(this, "_rename_node", n->get_instance_id(), n->get_name());
  610. undo_redo->commit_action();
  611. }
  612. }
  613. Node *SceneTreeEditor::get_selected() {
  614. return selected;
  615. }
  616. void SceneTreeEditor::set_marked(const Set<Node *> &p_marked, bool p_selectable, bool p_children_selectable) {
  617. if (tree_dirty)
  618. _update_tree();
  619. marked = p_marked;
  620. marked_selectable = p_selectable;
  621. marked_children_selectable = p_children_selectable;
  622. _update_tree();
  623. }
  624. void SceneTreeEditor::set_marked(Node *p_marked, bool p_selectable, bool p_children_selectable) {
  625. Set<Node *> s;
  626. if (p_marked)
  627. s.insert(p_marked);
  628. set_marked(s, p_selectable, p_children_selectable);
  629. }
  630. void SceneTreeEditor::set_filter(const String &p_filter) {
  631. filter = p_filter;
  632. _update_tree();
  633. }
  634. String SceneTreeEditor::get_filter() const {
  635. return filter;
  636. }
  637. void SceneTreeEditor::set_display_foreign_nodes(bool p_display) {
  638. display_foreign = p_display;
  639. _update_tree();
  640. }
  641. bool SceneTreeEditor::get_display_foreign_nodes() const {
  642. return display_foreign;
  643. }
  644. void SceneTreeEditor::set_valid_types(const Vector<StringName> &p_valid) {
  645. valid_types = p_valid;
  646. }
  647. void SceneTreeEditor::set_editor_selection(EditorSelection *p_selection) {
  648. editor_selection = p_selection;
  649. tree->set_select_mode(Tree::SELECT_MULTI);
  650. tree->set_cursor_can_exit_tree(false);
  651. editor_selection->connect("selection_changed", callable_mp(this, &SceneTreeEditor::_selection_changed));
  652. }
  653. void SceneTreeEditor::_update_selection(TreeItem *item) {
  654. ERR_FAIL_COND(!item);
  655. NodePath np = item->get_metadata(0);
  656. if (!has_node(np))
  657. return;
  658. Node *n = get_node(np);
  659. if (!n)
  660. return;
  661. if (editor_selection->is_selected(n))
  662. item->select(0);
  663. else
  664. item->deselect(0);
  665. TreeItem *c = item->get_children();
  666. while (c) {
  667. _update_selection(c);
  668. c = c->get_next();
  669. }
  670. }
  671. void SceneTreeEditor::_selection_changed() {
  672. if (!editor_selection)
  673. return;
  674. TreeItem *root = tree->get_root();
  675. if (!root)
  676. return;
  677. _update_selection(root);
  678. }
  679. void SceneTreeEditor::_cell_collapsed(Object *p_obj) {
  680. if (updating_tree)
  681. return;
  682. if (!can_rename)
  683. return;
  684. TreeItem *ti = Object::cast_to<TreeItem>(p_obj);
  685. if (!ti)
  686. return;
  687. bool collapsed = ti->is_collapsed();
  688. NodePath np = ti->get_metadata(0);
  689. Node *n = get_node(np);
  690. ERR_FAIL_COND(!n);
  691. n->set_display_folded(collapsed);
  692. }
  693. Variant SceneTreeEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  694. if (!can_rename)
  695. return Variant(); //not editable tree
  696. Vector<Node *> selected;
  697. Vector<Ref<Texture2D>> icons;
  698. TreeItem *next = tree->get_next_selected(nullptr);
  699. while (next) {
  700. NodePath np = next->get_metadata(0);
  701. Node *n = get_node(np);
  702. if (n) {
  703. // Only allow selection if not part of an instanced scene.
  704. if (!n->get_owner() || n->get_owner() == get_scene_node() || n->get_owner()->get_filename() == String()) {
  705. selected.push_back(n);
  706. icons.push_back(next->get_icon(0));
  707. }
  708. }
  709. next = tree->get_next_selected(next);
  710. }
  711. if (selected.empty())
  712. return Variant();
  713. VBoxContainer *vb = memnew(VBoxContainer);
  714. Array objs;
  715. int list_max = 10;
  716. float opacity_step = 1.0f / list_max;
  717. float opacity_item = 1.0f;
  718. for (int i = 0; i < selected.size(); i++) {
  719. if (i < list_max) {
  720. HBoxContainer *hb = memnew(HBoxContainer);
  721. TextureRect *tf = memnew(TextureRect);
  722. tf->set_texture(icons[i]);
  723. tf->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
  724. hb->add_child(tf);
  725. Label *label = memnew(Label(selected[i]->get_name()));
  726. hb->add_child(label);
  727. vb->add_child(hb);
  728. hb->set_modulate(Color(1, 1, 1, opacity_item));
  729. opacity_item -= opacity_step;
  730. }
  731. NodePath p = selected[i]->get_path();
  732. objs.push_back(p);
  733. }
  734. set_drag_preview(vb);
  735. Dictionary drag_data;
  736. drag_data["type"] = "nodes";
  737. drag_data["nodes"] = objs;
  738. tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN | Tree::DROP_MODE_ON_ITEM);
  739. emit_signal("nodes_dragged");
  740. return drag_data;
  741. }
  742. bool SceneTreeEditor::_is_script_type(const StringName &p_type) const {
  743. return (script_types->find(p_type));
  744. }
  745. bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  746. if (!can_rename)
  747. return false; //not editable tree
  748. if (filter != String())
  749. return false; //can't rearrange tree with filter turned on
  750. Dictionary d = p_data;
  751. if (!d.has("type"))
  752. return false;
  753. TreeItem *item = tree->get_item_at_position(p_point);
  754. if (!item)
  755. return false;
  756. int section = tree->get_drop_section_at_position(p_point);
  757. if (section < -1 || (section == -1 && !item->get_parent()))
  758. return false;
  759. if (String(d["type"]) == "files") {
  760. Vector<String> files = d["files"];
  761. if (files.size() == 0)
  762. return false; //weird
  763. if (_is_script_type(EditorFileSystem::get_singleton()->get_file_type(files[0]))) {
  764. tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
  765. return true;
  766. }
  767. for (int i = 0; i < files.size(); i++) {
  768. String file = files[i];
  769. String ftype = EditorFileSystem::get_singleton()->get_file_type(file);
  770. if (ftype != "PackedScene")
  771. return false;
  772. }
  773. tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN | Tree::DROP_MODE_ON_ITEM); //so it works..
  774. return true;
  775. }
  776. if (String(d["type"]) == "script_list_element") {
  777. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(d["script_list_element"]);
  778. if (se) {
  779. String sp = se->get_edited_resource()->get_path();
  780. if (_is_script_type(EditorFileSystem::get_singleton()->get_file_type(sp))) {
  781. tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
  782. return true;
  783. }
  784. }
  785. }
  786. return String(d["type"]) == "nodes";
  787. }
  788. void SceneTreeEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  789. if (!can_drop_data_fw(p_point, p_data, p_from))
  790. return;
  791. TreeItem *item = tree->get_item_at_position(p_point);
  792. if (!item)
  793. return;
  794. int section = tree->get_drop_section_at_position(p_point);
  795. if (section < -1)
  796. return;
  797. NodePath np = item->get_metadata(0);
  798. Node *n = get_node(np);
  799. if (!n)
  800. return;
  801. Dictionary d = p_data;
  802. if (String(d["type"]) == "nodes") {
  803. Array nodes = d["nodes"];
  804. emit_signal("nodes_rearranged", nodes, np, section);
  805. }
  806. if (String(d["type"]) == "files") {
  807. Vector<String> files = d["files"];
  808. String ftype = EditorFileSystem::get_singleton()->get_file_type(files[0]);
  809. if (_is_script_type(ftype)) {
  810. emit_signal("script_dropped", files[0], np);
  811. } else {
  812. emit_signal("files_dropped", files, np, section);
  813. }
  814. }
  815. if (String(d["type"]) == "script_list_element") {
  816. ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(d["script_list_element"]);
  817. if (se) {
  818. String sp = se->get_edited_resource()->get_path();
  819. if (_is_script_type(EditorFileSystem::get_singleton()->get_file_type(sp))) {
  820. emit_signal("script_dropped", sp, np);
  821. }
  822. }
  823. }
  824. }
  825. void SceneTreeEditor::_rmb_select(const Vector2 &p_pos) {
  826. emit_signal("rmb_pressed", tree->get_global_transform().xform(p_pos));
  827. }
  828. void SceneTreeEditor::_warning_changed(Node *p_for_node) {
  829. //should use a timer
  830. update_timer->start();
  831. }
  832. void SceneTreeEditor::set_connect_to_script_mode(bool p_enable) {
  833. connect_to_script_mode = p_enable;
  834. update_tree();
  835. }
  836. void SceneTreeEditor::set_connecting_signal(bool p_enable) {
  837. connecting_signal = p_enable;
  838. update_tree();
  839. }
  840. void SceneTreeEditor::_bind_methods() {
  841. ClassDB::bind_method("_update_tree", &SceneTreeEditor::_update_tree); // Still used by some connect_compat.
  842. ClassDB::bind_method("_rename_node", &SceneTreeEditor::_rename_node);
  843. ClassDB::bind_method("_test_update_tree", &SceneTreeEditor::_test_update_tree);
  844. ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &SceneTreeEditor::get_drag_data_fw);
  845. ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &SceneTreeEditor::can_drop_data_fw);
  846. ClassDB::bind_method(D_METHOD("drop_data_fw"), &SceneTreeEditor::drop_data_fw);
  847. ClassDB::bind_method(D_METHOD("update_tree"), &SceneTreeEditor::update_tree);
  848. ADD_SIGNAL(MethodInfo("node_selected"));
  849. ADD_SIGNAL(MethodInfo("node_renamed"));
  850. ADD_SIGNAL(MethodInfo("node_prerename"));
  851. ADD_SIGNAL(MethodInfo("node_changed"));
  852. ADD_SIGNAL(MethodInfo("nodes_dragged"));
  853. ADD_SIGNAL(MethodInfo("nodes_rearranged", PropertyInfo(Variant::ARRAY, "paths"), PropertyInfo(Variant::NODE_PATH, "to_path"), PropertyInfo(Variant::INT, "type")));
  854. ADD_SIGNAL(MethodInfo("files_dropped", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files"), PropertyInfo(Variant::NODE_PATH, "to_path"), PropertyInfo(Variant::INT, "type")));
  855. ADD_SIGNAL(MethodInfo("script_dropped", PropertyInfo(Variant::STRING, "file"), PropertyInfo(Variant::NODE_PATH, "to_path")));
  856. ADD_SIGNAL(MethodInfo("rmb_pressed", PropertyInfo(Variant::VECTOR2, "position")));
  857. ADD_SIGNAL(MethodInfo("open"));
  858. ADD_SIGNAL(MethodInfo("open_script"));
  859. }
  860. SceneTreeEditor::SceneTreeEditor(bool p_label, bool p_can_rename, bool p_can_open_instance) {
  861. connect_to_script_mode = false;
  862. connecting_signal = false;
  863. undo_redo = nullptr;
  864. tree_dirty = true;
  865. selected = nullptr;
  866. marked_selectable = false;
  867. marked_children_selectable = false;
  868. can_rename = p_can_rename;
  869. can_open_instance = p_can_open_instance;
  870. display_foreign = false;
  871. editor_selection = nullptr;
  872. if (p_label) {
  873. Label *label = memnew(Label);
  874. label->set_position(Point2(10, 0));
  875. label->set_text(TTR("Scene Tree (Nodes):"));
  876. add_child(label);
  877. }
  878. tree = memnew(Tree);
  879. tree->set_anchor(MARGIN_RIGHT, ANCHOR_END);
  880. tree->set_anchor(MARGIN_BOTTOM, ANCHOR_END);
  881. tree->set_begin(Point2(0, p_label ? 18 : 0));
  882. tree->set_end(Point2(0, 0));
  883. tree->add_theme_constant_override("button_margin", 0);
  884. add_child(tree);
  885. tree->set_drag_forwarding(this);
  886. if (p_can_rename) {
  887. tree->set_allow_rmb_select(true);
  888. tree->connect("item_rmb_selected", callable_mp(this, &SceneTreeEditor::_rmb_select));
  889. tree->connect("empty_tree_rmb_selected", callable_mp(this, &SceneTreeEditor::_rmb_select));
  890. }
  891. tree->connect("cell_selected", callable_mp(this, &SceneTreeEditor::_selected_changed));
  892. tree->connect("item_edited", callable_mp(this, &SceneTreeEditor::_renamed), varray(), CONNECT_DEFERRED);
  893. tree->connect("multi_selected", callable_mp(this, &SceneTreeEditor::_cell_multi_selected));
  894. tree->connect("button_pressed", callable_mp(this, &SceneTreeEditor::_cell_button_pressed));
  895. tree->connect("nothing_selected", callable_mp(this, &SceneTreeEditor::_deselect_items));
  896. //tree->connect("item_edited", this,"_renamed",Vector<Variant>(),true);
  897. error = memnew(AcceptDialog);
  898. add_child(error);
  899. warning = memnew(AcceptDialog);
  900. add_child(warning);
  901. warning->set_title(TTR("Node Configuration Warning!"));
  902. show_enabled_subscene = false;
  903. last_hash = 0;
  904. pending_test_update = false;
  905. updating_tree = false;
  906. blocked = 0;
  907. update_timer = memnew(Timer);
  908. update_timer->connect("timeout", callable_mp(this, &SceneTreeEditor::_update_tree));
  909. update_timer->set_one_shot(true);
  910. update_timer->set_wait_time(0.5);
  911. add_child(update_timer);
  912. script_types = memnew(List<StringName>);
  913. ClassDB::get_inheriters_from_class("Script", script_types);
  914. }
  915. SceneTreeEditor::~SceneTreeEditor() {
  916. memdelete(script_types);
  917. }
  918. /******** DIALOG *********/
  919. void SceneTreeDialog::_notification(int p_what) {
  920. switch (p_what) {
  921. case NOTIFICATION_VISIBILITY_CHANGED: {
  922. if (is_visible())
  923. tree->update_tree();
  924. } break;
  925. case NOTIFICATION_ENTER_TREE: {
  926. connect("confirmed", callable_mp(this, &SceneTreeDialog::_select));
  927. filter->set_right_icon(tree->get_theme_icon("Search", "EditorIcons"));
  928. filter->set_clear_button_enabled(true);
  929. } break;
  930. case NOTIFICATION_EXIT_TREE: {
  931. disconnect("confirmed", callable_mp(this, &SceneTreeDialog::_select));
  932. } break;
  933. }
  934. }
  935. void SceneTreeDialog::_cancel() {
  936. hide();
  937. }
  938. void SceneTreeDialog::_select() {
  939. if (tree->get_selected()) {
  940. emit_signal("selected", tree->get_selected()->get_path());
  941. hide();
  942. }
  943. }
  944. void SceneTreeDialog::_filter_changed(const String &p_filter) {
  945. tree->set_filter(p_filter);
  946. }
  947. void SceneTreeDialog::_bind_methods() {
  948. ClassDB::bind_method("_cancel", &SceneTreeDialog::_cancel);
  949. ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::NODE_PATH, "path")));
  950. }
  951. SceneTreeDialog::SceneTreeDialog() {
  952. set_title(TTR("Select a Node"));
  953. VBoxContainer *vbc = memnew(VBoxContainer);
  954. add_child(vbc);
  955. filter = memnew(LineEdit);
  956. filter->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  957. filter->set_placeholder(TTR("Filter nodes"));
  958. filter->add_theme_constant_override("minimum_spaces", 0);
  959. filter->connect("text_changed", callable_mp(this, &SceneTreeDialog::_filter_changed));
  960. vbc->add_child(filter);
  961. tree = memnew(SceneTreeEditor(false, false, true));
  962. tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  963. tree->get_scene_tree()->connect("item_activated", callable_mp(this, &SceneTreeDialog::_select));
  964. vbc->add_child(tree);
  965. }
  966. SceneTreeDialog::~SceneTreeDialog() {
  967. }