animation_blend_tree_editor_plugin.cpp 40 KB

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