animation_blend_tree_editor_plugin.cpp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096
  1. /*************************************************************************/
  2. /* animation_blend_tree_editor_plugin.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 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 "animation_blend_tree_editor_plugin.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/input/input.h"
  33. #include "core/io/resource_loader.h"
  34. #include "core/os/keyboard.h"
  35. #include "editor/editor_file_dialog.h"
  36. #include "editor/editor_inspector.h"
  37. #include "editor/editor_node.h"
  38. #include "editor/editor_scale.h"
  39. #include "editor/editor_settings.h"
  40. #include "editor/editor_undo_redo_manager.h"
  41. #include "scene/animation/animation_player.h"
  42. #include "scene/gui/menu_button.h"
  43. #include "scene/gui/panel.h"
  44. #include "scene/gui/progress_bar.h"
  45. #include "scene/gui/view_panner.h"
  46. #include "scene/main/window.h"
  47. void AnimationNodeBlendTreeEditor::add_custom_type(const String &p_name, const Ref<Script> &p_script) {
  48. for (int i = 0; i < add_options.size(); i++) {
  49. ERR_FAIL_COND(add_options[i].script == p_script);
  50. }
  51. AddOption ao;
  52. ao.name = p_name;
  53. ao.script = p_script;
  54. add_options.push_back(ao);
  55. _update_options_menu();
  56. }
  57. void AnimationNodeBlendTreeEditor::remove_custom_type(const Ref<Script> &p_script) {
  58. for (int i = 0; i < add_options.size(); i++) {
  59. if (add_options[i].script == p_script) {
  60. add_options.remove_at(i);
  61. return;
  62. }
  63. }
  64. _update_options_menu();
  65. }
  66. void AnimationNodeBlendTreeEditor::_update_options_menu(bool p_has_input_ports) {
  67. add_node->get_popup()->clear();
  68. add_node->get_popup()->reset_size();
  69. for (int i = 0; i < add_options.size(); i++) {
  70. if (p_has_input_ports && add_options[i].input_port_count == 0) {
  71. continue;
  72. }
  73. add_node->get_popup()->add_item(add_options[i].name, i);
  74. }
  75. Ref<AnimationNode> clipb = EditorSettings::get_singleton()->get_resource_clipboard();
  76. if (clipb.is_valid()) {
  77. add_node->get_popup()->add_separator();
  78. add_node->get_popup()->add_item(TTR("Paste"), MENU_PASTE);
  79. }
  80. add_node->get_popup()->add_separator();
  81. add_node->get_popup()->add_item(TTR("Load..."), MENU_LOAD_FILE);
  82. use_position_from_popup_menu = false;
  83. }
  84. Size2 AnimationNodeBlendTreeEditor::get_minimum_size() const {
  85. return Size2(10, 200);
  86. }
  87. void AnimationNodeBlendTreeEditor::_property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) {
  88. AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_tree();
  89. updating = true;
  90. undo_redo->create_action(TTR("Parameter Changed:") + " " + String(p_property), UndoRedo::MERGE_ENDS);
  91. undo_redo->add_do_property(tree, p_property, p_value);
  92. undo_redo->add_undo_property(tree, p_property, tree->get(p_property));
  93. undo_redo->add_do_method(this, "_update_graph");
  94. undo_redo->add_undo_method(this, "_update_graph");
  95. undo_redo->commit_action();
  96. updating = false;
  97. }
  98. void AnimationNodeBlendTreeEditor::_update_graph() {
  99. if (updating || blend_tree.is_null()) {
  100. return;
  101. }
  102. visible_properties.clear();
  103. graph->set_scroll_ofs(blend_tree->get_graph_offset() * EDSCALE);
  104. graph->clear_connections();
  105. //erase all nodes
  106. for (int i = 0; i < graph->get_child_count(); i++) {
  107. if (Object::cast_to<GraphNode>(graph->get_child(i))) {
  108. memdelete(graph->get_child(i));
  109. i--;
  110. }
  111. }
  112. animations.clear();
  113. List<StringName> nodes;
  114. blend_tree->get_node_list(&nodes);
  115. for (const StringName &E : nodes) {
  116. GraphNode *node = memnew(GraphNode);
  117. graph->add_child(node);
  118. node->set_draggable(!read_only);
  119. Ref<AnimationNode> agnode = blend_tree->get_node(E);
  120. ERR_CONTINUE(!agnode.is_valid());
  121. node->set_position_offset(blend_tree->get_node_position(E) * EDSCALE);
  122. node->set_title(agnode->get_caption());
  123. node->set_name(E);
  124. int base = 0;
  125. if (String(E) != "output") {
  126. LineEdit *name = memnew(LineEdit);
  127. name->set_text(E);
  128. name->set_editable(!read_only);
  129. name->set_expand_to_text_length_enabled(true);
  130. node->add_child(name);
  131. node->set_slot(0, false, 0, Color(), true, read_only ? -1 : 0, get_theme_color(SNAME("font_color"), SNAME("Label")));
  132. name->connect("text_submitted", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_renamed).bind(agnode), CONNECT_DEFERRED);
  133. name->connect("focus_exited", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_renamed_focus_out).bind(name, agnode), CONNECT_DEFERRED);
  134. base = 1;
  135. node->set_show_close_button(true);
  136. node->connect("close_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_delete_request).bind(E), CONNECT_DEFERRED);
  137. }
  138. for (int i = 0; i < agnode->get_input_count(); i++) {
  139. Label *in_name = memnew(Label);
  140. node->add_child(in_name);
  141. in_name->set_text(agnode->get_input_name(i));
  142. node->set_slot(base + i, true, read_only ? -1 : 0, get_theme_color(SNAME("font_color"), SNAME("Label")), false, 0, Color());
  143. }
  144. List<PropertyInfo> pinfo;
  145. agnode->get_parameter_list(&pinfo);
  146. for (const PropertyInfo &F : pinfo) {
  147. if (!(F.usage & PROPERTY_USAGE_EDITOR)) {
  148. continue;
  149. }
  150. String base_path = AnimationTreeEditor::get_singleton()->get_base_path() + String(E) + "/" + F.name;
  151. EditorProperty *prop = EditorInspector::instantiate_property_editor(AnimationTreeEditor::get_singleton()->get_tree(), F.type, base_path, F.hint, F.hint_string, F.usage);
  152. if (prop) {
  153. prop->set_read_only(read_only);
  154. prop->set_object_and_property(AnimationTreeEditor::get_singleton()->get_tree(), base_path);
  155. prop->update_property();
  156. prop->set_name_split_ratio(0);
  157. prop->connect("property_changed", callable_mp(this, &AnimationNodeBlendTreeEditor::_property_changed));
  158. node->add_child(prop);
  159. visible_properties.push_back(prop);
  160. }
  161. }
  162. node->connect("dragged", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_dragged).bind(E));
  163. if (AnimationTreeEditor::get_singleton()->can_edit(agnode)) {
  164. node->add_child(memnew(HSeparator));
  165. Button *open_in_editor = memnew(Button);
  166. open_in_editor->set_text(TTR("Open Editor"));
  167. open_in_editor->set_icon(get_theme_icon(SNAME("Edit"), SNAME("EditorIcons")));
  168. node->add_child(open_in_editor);
  169. open_in_editor->connect("pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_open_in_editor).bind(E), CONNECT_DEFERRED);
  170. open_in_editor->set_h_size_flags(SIZE_SHRINK_CENTER);
  171. }
  172. if (agnode->has_filter()) {
  173. node->add_child(memnew(HSeparator));
  174. Button *inspect_filters = memnew(Button);
  175. if (read_only) {
  176. inspect_filters->set_text(TTR("Inspect Filters"));
  177. } else {
  178. inspect_filters->set_text(TTR("Edit Filters"));
  179. }
  180. inspect_filters->set_icon(get_theme_icon(SNAME("AnimationFilter"), SNAME("EditorIcons")));
  181. node->add_child(inspect_filters);
  182. inspect_filters->connect("pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_inspect_filters).bind(E), CONNECT_DEFERRED);
  183. inspect_filters->set_h_size_flags(SIZE_SHRINK_CENTER);
  184. }
  185. Ref<AnimationNodeAnimation> anim = agnode;
  186. if (anim.is_valid()) {
  187. MenuButton *mb = memnew(MenuButton);
  188. mb->set_text(anim->get_animation());
  189. mb->set_icon(get_theme_icon(SNAME("Animation"), SNAME("EditorIcons")));
  190. mb->set_disabled(read_only);
  191. Array options;
  192. node->add_child(memnew(HSeparator));
  193. node->add_child(mb);
  194. ProgressBar *pb = memnew(ProgressBar);
  195. AnimationTree *player = AnimationTreeEditor::get_singleton()->get_tree();
  196. if (player->has_node(player->get_animation_player())) {
  197. AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(player->get_node(player->get_animation_player()));
  198. if (ap) {
  199. List<StringName> anims;
  200. ap->get_animation_list(&anims);
  201. for (const StringName &F : anims) {
  202. mb->get_popup()->add_item(F);
  203. options.push_back(F);
  204. }
  205. if (ap->has_animation(anim->get_animation())) {
  206. pb->set_max(ap->get_animation(anim->get_animation())->get_length());
  207. }
  208. }
  209. }
  210. pb->set_percent_visible(false);
  211. pb->set_custom_minimum_size(Vector2(0, 14) * EDSCALE);
  212. animations[E] = pb;
  213. node->add_child(pb);
  214. mb->get_popup()->connect("index_pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_anim_selected).bind(options, E), CONNECT_DEFERRED);
  215. }
  216. Ref<StyleBoxFlat> sb = node->get_theme_stylebox(SNAME("frame"), SNAME("GraphNode"));
  217. Color c = sb->get_border_color();
  218. Color mono_color = ((c.r + c.g + c.b) / 3) < 0.7 ? Color(1.0, 1.0, 1.0) : Color(0.0, 0.0, 0.0);
  219. mono_color.a = 0.85;
  220. c = mono_color;
  221. node->add_theme_color_override("title_color", c);
  222. c.a = 0.7;
  223. node->add_theme_color_override("close_color", c);
  224. node->add_theme_color_override("resizer_color", c);
  225. }
  226. List<AnimationNodeBlendTree::NodeConnection> connections;
  227. blend_tree->get_node_connections(&connections);
  228. for (const AnimationNodeBlendTree::NodeConnection &E : connections) {
  229. StringName from = E.output_node;
  230. StringName to = E.input_node;
  231. int to_idx = E.input_index;
  232. graph->connect_node(from, 0, to, to_idx);
  233. }
  234. float graph_minimap_opacity = EditorSettings::get_singleton()->get("editors/visual_editors/minimap_opacity");
  235. graph->set_minimap_opacity(graph_minimap_opacity);
  236. float graph_lines_curvature = EditorSettings::get_singleton()->get("editors/visual_editors/lines_curvature");
  237. graph->set_connection_lines_curvature(graph_lines_curvature);
  238. }
  239. void AnimationNodeBlendTreeEditor::_file_opened(const String &p_file) {
  240. file_loaded = ResourceLoader::load(p_file);
  241. if (file_loaded.is_valid()) {
  242. _add_node(MENU_LOAD_FILE_CONFIRM);
  243. }
  244. }
  245. void AnimationNodeBlendTreeEditor::_add_node(int p_idx) {
  246. Ref<AnimationNode> anode;
  247. String base_name;
  248. if (p_idx == MENU_LOAD_FILE) {
  249. open_file->clear_filters();
  250. List<String> filters;
  251. ResourceLoader::get_recognized_extensions_for_type("AnimationNode", &filters);
  252. for (const String &E : filters) {
  253. open_file->add_filter("*." + E);
  254. }
  255. open_file->popup_file_dialog();
  256. return;
  257. } else if (p_idx == MENU_LOAD_FILE_CONFIRM) {
  258. anode = file_loaded;
  259. file_loaded.unref();
  260. base_name = anode->get_class();
  261. } else if (p_idx == MENU_PASTE) {
  262. anode = EditorSettings::get_singleton()->get_resource_clipboard();
  263. ERR_FAIL_COND(!anode.is_valid());
  264. base_name = anode->get_class();
  265. } else if (!add_options[p_idx].type.is_empty()) {
  266. AnimationNode *an = Object::cast_to<AnimationNode>(ClassDB::instantiate(add_options[p_idx].type));
  267. ERR_FAIL_COND(!an);
  268. anode = Ref<AnimationNode>(an);
  269. base_name = add_options[p_idx].name;
  270. } else {
  271. ERR_FAIL_COND(add_options[p_idx].script.is_null());
  272. StringName base_type = add_options[p_idx].script->get_instance_base_type();
  273. AnimationNode *an = Object::cast_to<AnimationNode>(ClassDB::instantiate(base_type));
  274. ERR_FAIL_COND(!an);
  275. anode = Ref<AnimationNode>(an);
  276. anode->set_script(add_options[p_idx].script);
  277. base_name = add_options[p_idx].name;
  278. }
  279. Ref<AnimationNodeOutput> out = anode;
  280. if (out.is_valid()) {
  281. EditorNode::get_singleton()->show_warning(TTR("Output node can't be added to the blend tree."));
  282. return;
  283. }
  284. if (!from_node.is_empty() && anode->get_input_count() == 0) {
  285. from_node = "";
  286. return;
  287. }
  288. Point2 instance_pos = graph->get_scroll_ofs();
  289. if (use_position_from_popup_menu) {
  290. instance_pos += position_from_popup_menu;
  291. } else {
  292. instance_pos += graph->get_size() * 0.5;
  293. }
  294. instance_pos /= graph->get_zoom();
  295. int base = 1;
  296. String name = base_name;
  297. while (blend_tree->has_node(name)) {
  298. base++;
  299. name = base_name + " " + itos(base);
  300. }
  301. undo_redo->create_action(TTR("Add Node to BlendTree"));
  302. undo_redo->add_do_method(blend_tree.ptr(), "add_node", name, anode, instance_pos / EDSCALE);
  303. undo_redo->add_undo_method(blend_tree.ptr(), "remove_node", name);
  304. if (!from_node.is_empty()) {
  305. undo_redo->add_do_method(blend_tree.ptr(), "connect_node", name, 0, from_node);
  306. from_node = "";
  307. }
  308. if (!to_node.is_empty() && to_slot != -1) {
  309. undo_redo->add_do_method(blend_tree.ptr(), "connect_node", to_node, to_slot, name);
  310. to_node = "";
  311. to_slot = -1;
  312. }
  313. undo_redo->add_do_method(this, "_update_graph");
  314. undo_redo->add_undo_method(this, "_update_graph");
  315. undo_redo->commit_action();
  316. }
  317. void AnimationNodeBlendTreeEditor::_popup(bool p_has_input_ports, const Vector2 &p_popup_position, const Vector2 &p_node_position) {
  318. _update_options_menu(p_has_input_ports);
  319. use_position_from_popup_menu = true;
  320. position_from_popup_menu = p_node_position;
  321. add_node->get_popup()->set_position(p_popup_position);
  322. add_node->get_popup()->reset_size();
  323. add_node->get_popup()->popup();
  324. }
  325. void AnimationNodeBlendTreeEditor::_popup_request(const Vector2 &p_position) {
  326. if (read_only) {
  327. return;
  328. }
  329. _popup(false, graph->get_screen_position() + graph->get_local_mouse_position(), p_position);
  330. }
  331. void AnimationNodeBlendTreeEditor::_connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position) {
  332. if (read_only) {
  333. return;
  334. }
  335. Ref<AnimationNode> node = blend_tree->get_node(p_from);
  336. if (node.is_valid()) {
  337. from_node = p_from;
  338. _popup(true, p_release_position, graph->get_global_mouse_position());
  339. }
  340. }
  341. void AnimationNodeBlendTreeEditor::_connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position) {
  342. if (read_only) {
  343. return;
  344. }
  345. Ref<AnimationNode> node = blend_tree->get_node(p_to);
  346. if (node.is_valid()) {
  347. to_node = p_to;
  348. to_slot = p_to_slot;
  349. _popup(false, p_release_position, graph->get_global_mouse_position());
  350. }
  351. }
  352. void AnimationNodeBlendTreeEditor::_node_dragged(const Vector2 &p_from, const Vector2 &p_to, const StringName &p_which) {
  353. updating = true;
  354. undo_redo->create_action(TTR("Node Moved"));
  355. undo_redo->add_do_method(blend_tree.ptr(), "set_node_position", p_which, p_to / EDSCALE);
  356. undo_redo->add_undo_method(blend_tree.ptr(), "set_node_position", p_which, p_from / EDSCALE);
  357. undo_redo->add_do_method(this, "_update_graph");
  358. undo_redo->add_undo_method(this, "_update_graph");
  359. undo_redo->commit_action();
  360. updating = false;
  361. }
  362. void AnimationNodeBlendTreeEditor::_connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) {
  363. if (read_only) {
  364. return;
  365. }
  366. AnimationNodeBlendTree::ConnectionError err = blend_tree->can_connect_node(p_to, p_to_index, p_from);
  367. if (err != AnimationNodeBlendTree::CONNECTION_OK) {
  368. EditorNode::get_singleton()->show_warning(TTR("Unable to connect, port may be in use or connection may be invalid."));
  369. return;
  370. }
  371. undo_redo->create_action(TTR("Nodes Connected"));
  372. undo_redo->add_do_method(blend_tree.ptr(), "connect_node", p_to, p_to_index, p_from);
  373. undo_redo->add_undo_method(blend_tree.ptr(), "disconnect_node", p_to, p_to_index);
  374. undo_redo->add_do_method(this, "_update_graph");
  375. undo_redo->add_undo_method(this, "_update_graph");
  376. undo_redo->commit_action();
  377. }
  378. void AnimationNodeBlendTreeEditor::_disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index) {
  379. if (read_only) {
  380. return;
  381. }
  382. graph->disconnect_node(p_from, p_from_index, p_to, p_to_index);
  383. updating = true;
  384. undo_redo->create_action(TTR("Nodes Disconnected"));
  385. undo_redo->add_do_method(blend_tree.ptr(), "disconnect_node", p_to, p_to_index);
  386. undo_redo->add_undo_method(blend_tree.ptr(), "connect_node", p_to, p_to_index, p_from);
  387. undo_redo->add_do_method(this, "_update_graph");
  388. undo_redo->add_undo_method(this, "_update_graph");
  389. undo_redo->commit_action();
  390. updating = false;
  391. }
  392. void AnimationNodeBlendTreeEditor::_anim_selected(int p_index, Array p_options, const String &p_node) {
  393. String option = p_options[p_index];
  394. Ref<AnimationNodeAnimation> anim = blend_tree->get_node(p_node);
  395. ERR_FAIL_COND(!anim.is_valid());
  396. undo_redo->create_action(TTR("Set Animation"));
  397. undo_redo->add_do_method(anim.ptr(), "set_animation", option);
  398. undo_redo->add_undo_method(anim.ptr(), "set_animation", anim->get_animation());
  399. undo_redo->add_do_method(this, "_update_graph");
  400. undo_redo->add_undo_method(this, "_update_graph");
  401. undo_redo->commit_action();
  402. }
  403. void AnimationNodeBlendTreeEditor::_delete_request(const String &p_which) {
  404. if (read_only) {
  405. return;
  406. }
  407. undo_redo->create_action(TTR("Delete Node"));
  408. undo_redo->add_do_method(blend_tree.ptr(), "remove_node", p_which);
  409. undo_redo->add_undo_method(blend_tree.ptr(), "add_node", p_which, blend_tree->get_node(p_which), blend_tree.ptr()->get_node_position(p_which));
  410. List<AnimationNodeBlendTree::NodeConnection> conns;
  411. blend_tree->get_node_connections(&conns);
  412. for (const AnimationNodeBlendTree::NodeConnection &E : conns) {
  413. if (E.output_node == p_which || E.input_node == p_which) {
  414. undo_redo->add_undo_method(blend_tree.ptr(), "connect_node", E.input_node, E.input_index, E.output_node);
  415. }
  416. }
  417. undo_redo->add_do_method(this, "_update_graph");
  418. undo_redo->add_undo_method(this, "_update_graph");
  419. undo_redo->commit_action();
  420. }
  421. void AnimationNodeBlendTreeEditor::_delete_nodes_request(const TypedArray<StringName> &p_nodes) {
  422. if (read_only) {
  423. return;
  424. }
  425. List<StringName> to_erase;
  426. if (p_nodes.is_empty()) {
  427. for (int i = 0; i < graph->get_child_count(); i++) {
  428. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
  429. if (gn) {
  430. if (gn->is_selected() && gn->is_close_button_visible()) {
  431. to_erase.push_back(gn->get_name());
  432. }
  433. }
  434. }
  435. } else {
  436. for (int i = 0; i < p_nodes.size(); i++) {
  437. to_erase.push_back(p_nodes[i]);
  438. }
  439. }
  440. if (to_erase.is_empty()) {
  441. return;
  442. }
  443. undo_redo->create_action(TTR("Delete Node(s)"));
  444. for (const StringName &F : to_erase) {
  445. _delete_request(F);
  446. }
  447. undo_redo->commit_action();
  448. }
  449. void AnimationNodeBlendTreeEditor::_node_selected(Object *p_node) {
  450. if (read_only) {
  451. return;
  452. }
  453. GraphNode *gn = Object::cast_to<GraphNode>(p_node);
  454. ERR_FAIL_COND(!gn);
  455. String name = gn->get_name();
  456. Ref<AnimationNode> anode = blend_tree->get_node(name);
  457. ERR_FAIL_COND(!anode.is_valid());
  458. EditorNode::get_singleton()->push_item(anode.ptr(), "", true);
  459. }
  460. void AnimationNodeBlendTreeEditor::_open_in_editor(const String &p_which) {
  461. Ref<AnimationNode> an = blend_tree->get_node(p_which);
  462. ERR_FAIL_COND(!an.is_valid());
  463. AnimationTreeEditor::get_singleton()->enter_editor(p_which);
  464. }
  465. void AnimationNodeBlendTreeEditor::_filter_toggled() {
  466. updating = true;
  467. undo_redo->create_action(TTR("Toggle Filter On/Off"));
  468. undo_redo->add_do_method(_filter_edit.ptr(), "set_filter_enabled", filter_enabled->is_pressed());
  469. undo_redo->add_undo_method(_filter_edit.ptr(), "set_filter_enabled", _filter_edit->is_filter_enabled());
  470. undo_redo->add_do_method(this, "_update_filters", _filter_edit);
  471. undo_redo->add_undo_method(this, "_update_filters", _filter_edit);
  472. undo_redo->commit_action();
  473. updating = false;
  474. }
  475. void AnimationNodeBlendTreeEditor::_filter_edited() {
  476. TreeItem *edited = filters->get_edited();
  477. ERR_FAIL_COND(!edited);
  478. NodePath edited_path = edited->get_metadata(0);
  479. bool filtered = edited->is_checked(0);
  480. updating = true;
  481. undo_redo->create_action(TTR("Change Filter"));
  482. undo_redo->add_do_method(_filter_edit.ptr(), "set_filter_path", edited_path, filtered);
  483. undo_redo->add_undo_method(_filter_edit.ptr(), "set_filter_path", edited_path, _filter_edit->is_path_filtered(edited_path));
  484. undo_redo->add_do_method(this, "_update_filters", _filter_edit);
  485. undo_redo->add_undo_method(this, "_update_filters", _filter_edit);
  486. undo_redo->commit_action();
  487. updating = false;
  488. }
  489. bool AnimationNodeBlendTreeEditor::_update_filters(const Ref<AnimationNode> &anode) {
  490. if (updating || _filter_edit != anode) {
  491. return false;
  492. }
  493. NodePath player_path = AnimationTreeEditor::get_singleton()->get_tree()->get_animation_player();
  494. if (!AnimationTreeEditor::get_singleton()->get_tree()->has_node(player_path)) {
  495. EditorNode::get_singleton()->show_warning(TTR("No animation player set, so unable to retrieve track names."));
  496. return false;
  497. }
  498. AnimationPlayer *player = Object::cast_to<AnimationPlayer>(AnimationTreeEditor::get_singleton()->get_tree()->get_node(player_path));
  499. if (!player) {
  500. EditorNode::get_singleton()->show_warning(TTR("Player path set is invalid, so unable to retrieve track names."));
  501. return false;
  502. }
  503. Node *base = player->get_node(player->get_root());
  504. if (!base) {
  505. EditorNode::get_singleton()->show_warning(TTR("Animation player has no valid root node path, so unable to retrieve track names."));
  506. return false;
  507. }
  508. updating = true;
  509. HashSet<String> paths;
  510. HashMap<String, RBSet<String>> types;
  511. {
  512. List<StringName> animations;
  513. player->get_animation_list(&animations);
  514. for (const StringName &E : animations) {
  515. Ref<Animation> anim = player->get_animation(E);
  516. for (int i = 0; i < anim->get_track_count(); i++) {
  517. String track_path = anim->track_get_path(i);
  518. paths.insert(track_path);
  519. String track_type_name;
  520. Animation::TrackType track_type = anim->track_get_type(i);
  521. switch (track_type) {
  522. case Animation::TrackType::TYPE_ANIMATION: {
  523. track_type_name = TTR("Anim Clips");
  524. } break;
  525. case Animation::TrackType::TYPE_AUDIO: {
  526. track_type_name = TTR("Audio Clips");
  527. } break;
  528. case Animation::TrackType::TYPE_METHOD: {
  529. track_type_name = TTR("Functions");
  530. } break;
  531. default: {
  532. } break;
  533. }
  534. if (!track_type_name.is_empty()) {
  535. types[track_path].insert(track_type_name);
  536. }
  537. }
  538. }
  539. }
  540. filter_enabled->set_pressed(anode->is_filter_enabled());
  541. filters->clear();
  542. TreeItem *root = filters->create_item();
  543. HashMap<String, TreeItem *> parenthood;
  544. for (const String &E : paths) {
  545. NodePath path = E;
  546. TreeItem *ti = nullptr;
  547. String accum;
  548. for (int i = 0; i < path.get_name_count(); i++) {
  549. String name = path.get_name(i);
  550. if (!accum.is_empty()) {
  551. accum += "/";
  552. }
  553. accum += name;
  554. if (!parenthood.has(accum)) {
  555. if (ti) {
  556. ti = filters->create_item(ti);
  557. } else {
  558. ti = filters->create_item(root);
  559. }
  560. parenthood[accum] = ti;
  561. ti->set_text(0, name);
  562. ti->set_selectable(0, false);
  563. ti->set_editable(0, false);
  564. if (base->has_node(accum)) {
  565. Node *node = base->get_node(accum);
  566. ti->set_icon(0, EditorNode::get_singleton()->get_object_icon(node, "Node"));
  567. }
  568. } else {
  569. ti = parenthood[accum];
  570. }
  571. }
  572. Node *node = nullptr;
  573. if (base->has_node(accum)) {
  574. node = base->get_node(accum);
  575. }
  576. if (!node) {
  577. continue; //no node, can't edit
  578. }
  579. if (path.get_subname_count()) {
  580. String concat = path.get_concatenated_subnames();
  581. Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(node);
  582. if (skeleton && skeleton->find_bone(concat) != -1) {
  583. //path in skeleton
  584. const String &bone = concat;
  585. int idx = skeleton->find_bone(bone);
  586. List<String> bone_path;
  587. while (idx != -1) {
  588. bone_path.push_front(skeleton->get_bone_name(idx));
  589. idx = skeleton->get_bone_parent(idx);
  590. }
  591. accum += ":";
  592. for (List<String>::Element *F = bone_path.front(); F; F = F->next()) {
  593. if (F != bone_path.front()) {
  594. accum += "/";
  595. }
  596. accum += F->get();
  597. if (!parenthood.has(accum)) {
  598. ti = filters->create_item(ti);
  599. parenthood[accum] = ti;
  600. ti->set_text(0, F->get());
  601. ti->set_selectable(0, false);
  602. ti->set_editable(0, false);
  603. ti->set_icon(0, get_theme_icon(SNAME("BoneAttachment3D"), SNAME("EditorIcons")));
  604. } else {
  605. ti = parenthood[accum];
  606. }
  607. }
  608. ti->set_editable(0, !read_only);
  609. ti->set_selectable(0, true);
  610. ti->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  611. ti->set_text(0, concat);
  612. ti->set_checked(0, anode->is_path_filtered(path));
  613. ti->set_icon(0, get_theme_icon(SNAME("BoneAttachment3D"), SNAME("EditorIcons")));
  614. ti->set_metadata(0, path);
  615. } else {
  616. //just a property
  617. ti = filters->create_item(ti);
  618. ti->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  619. ti->set_text(0, concat);
  620. ti->set_editable(0, !read_only);
  621. ti->set_selectable(0, true);
  622. ti->set_checked(0, anode->is_path_filtered(path));
  623. ti->set_metadata(0, path);
  624. }
  625. } else {
  626. if (ti) {
  627. //just a node, not a property track
  628. String types_text = "[";
  629. if (types.has(path)) {
  630. RBSet<String>::Iterator F = types[path].begin();
  631. types_text += *F;
  632. while (F) {
  633. types_text += " / " + *F;
  634. ;
  635. ++F;
  636. }
  637. }
  638. types_text += "]";
  639. ti = filters->create_item(ti);
  640. ti->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  641. ti->set_text(0, types_text);
  642. ti->set_editable(0, !read_only);
  643. ti->set_selectable(0, true);
  644. ti->set_checked(0, anode->is_path_filtered(path));
  645. ti->set_metadata(0, path);
  646. }
  647. }
  648. }
  649. updating = false;
  650. return true;
  651. }
  652. void AnimationNodeBlendTreeEditor::_inspect_filters(const String &p_which) {
  653. if (read_only) {
  654. filter_dialog->set_title(TTR("Inspect Filtered Tracks:"));
  655. } else {
  656. filter_dialog->set_title(TTR("Edit Filtered Tracks:"));
  657. }
  658. filter_enabled->set_disabled(read_only);
  659. Ref<AnimationNode> anode = blend_tree->get_node(p_which);
  660. ERR_FAIL_COND(!anode.is_valid());
  661. _filter_edit = anode;
  662. if (!_update_filters(anode)) {
  663. return;
  664. }
  665. filter_dialog->popup_centered(Size2(500, 500) * EDSCALE);
  666. }
  667. void AnimationNodeBlendTreeEditor::_removed_from_graph() {
  668. if (is_visible()) {
  669. EditorNode::get_singleton()->edit_item(nullptr);
  670. }
  671. }
  672. void AnimationNodeBlendTreeEditor::_update_editor_settings() {
  673. graph->get_panner()->setup((ViewPanner::ControlScheme)EDITOR_GET("editors/panning/sub_editors_panning_scheme").operator int(), ED_GET_SHORTCUT("canvas_item_editor/pan_view"), bool(EditorSettings::get_singleton()->get("editors/panning/simple_panning")));
  674. graph->set_warped_panning(bool(EditorSettings::get_singleton()->get("editors/panning/warped_mouse_panning")));
  675. }
  676. void AnimationNodeBlendTreeEditor::_update_theme() {
  677. error_panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("Tree")));
  678. error_label->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), SNAME("Editor")));
  679. }
  680. void AnimationNodeBlendTreeEditor::_notification(int p_what) {
  681. switch (p_what) {
  682. case NOTIFICATION_ENTER_TREE: {
  683. _update_editor_settings();
  684. _update_theme();
  685. } break;
  686. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  687. _update_editor_settings();
  688. } break;
  689. case NOTIFICATION_THEME_CHANGED: {
  690. _update_theme();
  691. if (is_visible_in_tree()) {
  692. _update_graph();
  693. }
  694. } break;
  695. case NOTIFICATION_PROCESS: {
  696. String error;
  697. if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) {
  698. error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails.");
  699. } else if (AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) {
  700. error = AnimationTreeEditor::get_singleton()->get_tree()->get_invalid_state_reason();
  701. }
  702. if (error != error_label->get_text()) {
  703. error_label->set_text(error);
  704. if (!error.is_empty()) {
  705. error_panel->show();
  706. } else {
  707. error_panel->hide();
  708. }
  709. }
  710. List<AnimationNodeBlendTree::NodeConnection> conns;
  711. blend_tree->get_node_connections(&conns);
  712. for (const AnimationNodeBlendTree::NodeConnection &E : conns) {
  713. float activity = 0;
  714. StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + E.input_node;
  715. if (AnimationTreeEditor::get_singleton()->get_tree() && !AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) {
  716. activity = AnimationTreeEditor::get_singleton()->get_tree()->get_connection_activity(path, E.input_index);
  717. }
  718. graph->set_connection_activity(E.output_node, 0, E.input_node, E.input_index, activity);
  719. }
  720. AnimationTree *graph_player = AnimationTreeEditor::get_singleton()->get_tree();
  721. AnimationPlayer *player = nullptr;
  722. if (graph_player->has_node(graph_player->get_animation_player())) {
  723. player = Object::cast_to<AnimationPlayer>(graph_player->get_node(graph_player->get_animation_player()));
  724. }
  725. if (player) {
  726. for (const KeyValue<StringName, ProgressBar *> &E : animations) {
  727. Ref<AnimationNodeAnimation> an = blend_tree->get_node(E.key);
  728. if (an.is_valid()) {
  729. if (player->has_animation(an->get_animation())) {
  730. Ref<Animation> anim = player->get_animation(an->get_animation());
  731. if (anim.is_valid()) {
  732. E.value->set_max(anim->get_length());
  733. //StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + E.input_node;
  734. StringName time_path = AnimationTreeEditor::get_singleton()->get_base_path() + String(E.key) + "/time";
  735. E.value->set_value(AnimationTreeEditor::get_singleton()->get_tree()->get(time_path));
  736. }
  737. }
  738. }
  739. }
  740. }
  741. for (int i = 0; i < visible_properties.size(); i++) {
  742. visible_properties[i]->update_property();
  743. }
  744. } break;
  745. case NOTIFICATION_VISIBILITY_CHANGED: {
  746. set_process(is_visible_in_tree());
  747. } break;
  748. }
  749. }
  750. void AnimationNodeBlendTreeEditor::_scroll_changed(const Vector2 &p_scroll) {
  751. if (read_only) {
  752. return;
  753. }
  754. if (updating) {
  755. return;
  756. }
  757. updating = true;
  758. blend_tree->set_graph_offset(p_scroll / EDSCALE);
  759. updating = false;
  760. }
  761. void AnimationNodeBlendTreeEditor::_bind_methods() {
  762. ClassDB::bind_method("_update_graph", &AnimationNodeBlendTreeEditor::_update_graph);
  763. ClassDB::bind_method("_update_filters", &AnimationNodeBlendTreeEditor::_update_filters);
  764. }
  765. AnimationNodeBlendTreeEditor *AnimationNodeBlendTreeEditor::singleton = nullptr;
  766. void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<AnimationNode> p_node) {
  767. String prev_name = blend_tree->get_node_name(p_node);
  768. ERR_FAIL_COND(prev_name.is_empty());
  769. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_node(prev_name));
  770. ERR_FAIL_COND(!gn);
  771. const String &new_name = p_text;
  772. ERR_FAIL_COND(new_name.is_empty() || new_name.contains(".") || new_name.contains("/"));
  773. if (new_name == prev_name) {
  774. return; //nothing to do
  775. }
  776. const String &base_name = new_name;
  777. int base = 1;
  778. String name = base_name;
  779. while (blend_tree->has_node(name)) {
  780. base++;
  781. name = base_name + " " + itos(base);
  782. }
  783. String base_path = AnimationTreeEditor::get_singleton()->get_base_path();
  784. updating = true;
  785. undo_redo->create_action(TTR("Node Renamed"));
  786. undo_redo->add_do_method(blend_tree.ptr(), "rename_node", prev_name, name);
  787. undo_redo->add_undo_method(blend_tree.ptr(), "rename_node", name, prev_name);
  788. undo_redo->add_do_method(AnimationTreeEditor::get_singleton()->get_tree(), "rename_parameter", base_path + prev_name, base_path + name);
  789. undo_redo->add_undo_method(AnimationTreeEditor::get_singleton()->get_tree(), "rename_parameter", base_path + name, base_path + prev_name);
  790. undo_redo->add_do_method(this, "_update_graph");
  791. undo_redo->add_undo_method(this, "_update_graph");
  792. undo_redo->commit_action();
  793. updating = false;
  794. gn->set_name(new_name);
  795. gn->set_size(gn->get_minimum_size());
  796. //change editors accordingly
  797. for (int i = 0; i < visible_properties.size(); i++) {
  798. String pname = visible_properties[i]->get_edited_property().operator String();
  799. if (pname.begins_with(base_path + prev_name)) {
  800. String new_name2 = pname.replace_first(base_path + prev_name, base_path + name);
  801. visible_properties[i]->set_object_and_property(visible_properties[i]->get_edited_object(), new_name2);
  802. }
  803. }
  804. //recreate connections
  805. graph->clear_connections();
  806. List<AnimationNodeBlendTree::NodeConnection> connections;
  807. blend_tree->get_node_connections(&connections);
  808. for (const AnimationNodeBlendTree::NodeConnection &E : connections) {
  809. StringName from = E.output_node;
  810. StringName to = E.input_node;
  811. int to_idx = E.input_index;
  812. graph->connect_node(from, 0, to, to_idx);
  813. }
  814. //update animations
  815. for (const KeyValue<StringName, ProgressBar *> &E : animations) {
  816. if (E.key == prev_name) {
  817. animations[new_name] = animations[prev_name];
  818. animations.erase(prev_name);
  819. break;
  820. }
  821. }
  822. _update_graph(); // Needed to update the signal connections with the new name.
  823. }
  824. void AnimationNodeBlendTreeEditor::_node_renamed_focus_out(Node *le, Ref<AnimationNode> p_node) {
  825. if (le == nullptr) {
  826. return; // The text_submitted signal triggered the graph update and freed the LineEdit.
  827. }
  828. _node_renamed(le->call("get_text"), p_node);
  829. }
  830. bool AnimationNodeBlendTreeEditor::can_edit(const Ref<AnimationNode> &p_node) {
  831. Ref<AnimationNodeBlendTree> bt = p_node;
  832. return bt.is_valid();
  833. }
  834. void AnimationNodeBlendTreeEditor::edit(const Ref<AnimationNode> &p_node) {
  835. if (blend_tree.is_valid()) {
  836. blend_tree->disconnect("removed_from_graph", callable_mp(this, &AnimationNodeBlendTreeEditor::_removed_from_graph));
  837. }
  838. blend_tree = p_node;
  839. read_only = false;
  840. if (blend_tree.is_null()) {
  841. hide();
  842. } else {
  843. read_only = EditorNode::get_singleton()->is_resource_read_only(blend_tree);
  844. blend_tree->connect("removed_from_graph", callable_mp(this, &AnimationNodeBlendTreeEditor::_removed_from_graph));
  845. _update_graph();
  846. }
  847. add_node->set_disabled(read_only);
  848. graph->set_arrange_nodes_button_hidden(read_only);
  849. }
  850. AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() {
  851. singleton = this;
  852. updating = false;
  853. use_position_from_popup_menu = false;
  854. graph = memnew(GraphEdit);
  855. add_child(graph);
  856. graph->add_valid_right_disconnect_type(0);
  857. graph->add_valid_left_disconnect_type(0);
  858. graph->set_v_size_flags(SIZE_EXPAND_FILL);
  859. graph->connect("connection_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_connection_request), CONNECT_DEFERRED);
  860. graph->connect("disconnection_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_disconnection_request), CONNECT_DEFERRED);
  861. graph->connect("node_selected", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_selected));
  862. graph->connect("scroll_offset_changed", callable_mp(this, &AnimationNodeBlendTreeEditor::_scroll_changed));
  863. graph->connect("delete_nodes_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_delete_nodes_request));
  864. graph->connect("popup_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_popup_request));
  865. graph->connect("connection_to_empty", callable_mp(this, &AnimationNodeBlendTreeEditor::_connection_to_empty));
  866. graph->connect("connection_from_empty", callable_mp(this, &AnimationNodeBlendTreeEditor::_connection_from_empty));
  867. float graph_minimap_opacity = EditorSettings::get_singleton()->get("editors/visual_editors/minimap_opacity");
  868. graph->set_minimap_opacity(graph_minimap_opacity);
  869. float graph_lines_curvature = EditorSettings::get_singleton()->get("editors/visual_editors/lines_curvature");
  870. graph->set_connection_lines_curvature(graph_lines_curvature);
  871. VSeparator *vs = memnew(VSeparator);
  872. graph->get_zoom_hbox()->add_child(vs);
  873. graph->get_zoom_hbox()->move_child(vs, 0);
  874. add_node = memnew(MenuButton);
  875. graph->get_zoom_hbox()->add_child(add_node);
  876. add_node->set_text(TTR("Add Node..."));
  877. graph->get_zoom_hbox()->move_child(add_node, 0);
  878. add_node->get_popup()->connect("id_pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_add_node));
  879. add_node->connect("about_to_popup", callable_mp(this, &AnimationNodeBlendTreeEditor::_update_options_menu).bind(false));
  880. add_node->set_disabled(read_only);
  881. add_options.push_back(AddOption("Animation", "AnimationNodeAnimation"));
  882. add_options.push_back(AddOption("OneShot", "AnimationNodeOneShot", 2));
  883. add_options.push_back(AddOption("Add2", "AnimationNodeAdd2", 2));
  884. add_options.push_back(AddOption("Add3", "AnimationNodeAdd3", 3));
  885. add_options.push_back(AddOption("Blend2", "AnimationNodeBlend2", 2));
  886. add_options.push_back(AddOption("Blend3", "AnimationNodeBlend3", 3));
  887. add_options.push_back(AddOption("Seek", "AnimationNodeTimeSeek", 1));
  888. add_options.push_back(AddOption("TimeScale", "AnimationNodeTimeScale", 1));
  889. add_options.push_back(AddOption("Transition", "AnimationNodeTransition"));
  890. add_options.push_back(AddOption("BlendTree", "AnimationNodeBlendTree"));
  891. add_options.push_back(AddOption("BlendSpace1D", "AnimationNodeBlendSpace1D"));
  892. add_options.push_back(AddOption("BlendSpace2D", "AnimationNodeBlendSpace2D"));
  893. add_options.push_back(AddOption("StateMachine", "AnimationNodeStateMachine"));
  894. _update_options_menu();
  895. error_panel = memnew(PanelContainer);
  896. add_child(error_panel);
  897. error_label = memnew(Label);
  898. error_panel->add_child(error_label);
  899. error_label->set_text("eh");
  900. filter_dialog = memnew(AcceptDialog);
  901. add_child(filter_dialog);
  902. filter_dialog->set_title(TTR("Edit Filtered Tracks:"));
  903. VBoxContainer *filter_vbox = memnew(VBoxContainer);
  904. filter_dialog->add_child(filter_vbox);
  905. filter_enabled = memnew(CheckBox);
  906. filter_enabled->set_text(TTR("Enable Filtering"));
  907. filter_enabled->connect("pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_filter_toggled));
  908. filter_vbox->add_child(filter_enabled);
  909. filters = memnew(Tree);
  910. filter_vbox->add_child(filters);
  911. filters->set_v_size_flags(SIZE_EXPAND_FILL);
  912. filters->set_hide_root(true);
  913. filters->connect("item_edited", callable_mp(this, &AnimationNodeBlendTreeEditor::_filter_edited));
  914. open_file = memnew(EditorFileDialog);
  915. add_child(open_file);
  916. open_file->set_title(TTR("Open Animation Node"));
  917. open_file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
  918. open_file->connect("file_selected", callable_mp(this, &AnimationNodeBlendTreeEditor::_file_opened));
  919. undo_redo = EditorNode::get_undo_redo();
  920. }