animation_blend_tree_editor_plugin.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113
  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_show_percentage(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> node_connections;
  227. blend_tree->get_node_connections(&node_connections);
  228. for (const AnimationNodeBlendTree::NodeConnection &E : node_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 = EDITOR_GET("editors/visual_editors/minimap_opacity");
  235. graph->set_minimap_opacity(graph_minimap_opacity);
  236. float graph_lines_curvature = EDITOR_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> ext_filters;
  251. ResourceLoader::get_recognized_extensions_for_type("AnimationNode", &ext_filters);
  252. for (const String &E : ext_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> animation_list;
  513. player->get_animation_list(&animation_list);
  514. for (const StringName &E : animation_list) {
  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(EDITOR_GET("editors/panning/simple_panning")));
  674. graph->set_warped_panning(bool(EDITOR_GET("editors/panning/warped_mouse_panning")));
  675. }
  676. void AnimationNodeBlendTreeEditor::_update_theme() {
  677. error_panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), 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. // AnimationNode's "node_changed" signal means almost update_input.
  767. void AnimationNodeBlendTreeEditor::_node_changed(const StringName &p_node_name) {
  768. // TODO:
  769. // Here is executed during the commit of EditorNode::undo_redo, it is not possible to create an undo_redo action here.
  770. // The disconnect when the number of enabled inputs decreases is done in AnimationNodeBlendTree and update_graph().
  771. // This means that there is no place to register undo_redo actions.
  772. // In order to implement undo_redo correctly, we may need to implement AnimationNodeEdit such as AnimationTrackKeyEdit
  773. // and add it to _node_selected() with EditorNode::get_singleton()->push_item(AnimationNodeEdit).
  774. update_graph();
  775. }
  776. void AnimationNodeBlendTreeEditor::_node_renamed(const String &p_text, Ref<AnimationNode> p_node) {
  777. if (blend_tree.is_null()) {
  778. return;
  779. }
  780. String prev_name = blend_tree->get_node_name(p_node);
  781. ERR_FAIL_COND(prev_name.is_empty());
  782. GraphNode *gn = Object::cast_to<GraphNode>(graph->get_node(prev_name));
  783. ERR_FAIL_COND(!gn);
  784. const String &new_name = p_text;
  785. ERR_FAIL_COND(new_name.is_empty() || new_name.contains(".") || new_name.contains("/"));
  786. if (new_name == prev_name) {
  787. return; //nothing to do
  788. }
  789. const String &base_name = new_name;
  790. int base = 1;
  791. String name = base_name;
  792. while (blend_tree->has_node(name)) {
  793. base++;
  794. name = base_name + " " + itos(base);
  795. }
  796. String base_path = AnimationTreeEditor::get_singleton()->get_base_path();
  797. updating = true;
  798. undo_redo->create_action(TTR("Node Renamed"));
  799. undo_redo->add_do_method(blend_tree.ptr(), "rename_node", prev_name, name);
  800. undo_redo->add_undo_method(blend_tree.ptr(), "rename_node", name, prev_name);
  801. undo_redo->add_do_method(AnimationTreeEditor::get_singleton()->get_tree(), "rename_parameter", base_path + prev_name, base_path + name);
  802. undo_redo->add_undo_method(AnimationTreeEditor::get_singleton()->get_tree(), "rename_parameter", base_path + name, base_path + prev_name);
  803. undo_redo->add_do_method(this, "update_graph");
  804. undo_redo->add_undo_method(this, "update_graph");
  805. undo_redo->commit_action();
  806. updating = false;
  807. gn->set_name(new_name);
  808. gn->set_size(gn->get_minimum_size());
  809. //change editors accordingly
  810. for (int i = 0; i < visible_properties.size(); i++) {
  811. String pname = visible_properties[i]->get_edited_property().operator String();
  812. if (pname.begins_with(base_path + prev_name)) {
  813. String new_name2 = pname.replace_first(base_path + prev_name, base_path + name);
  814. visible_properties[i]->set_object_and_property(visible_properties[i]->get_edited_object(), new_name2);
  815. }
  816. }
  817. //recreate connections
  818. graph->clear_connections();
  819. List<AnimationNodeBlendTree::NodeConnection> node_connections;
  820. blend_tree->get_node_connections(&node_connections);
  821. for (const AnimationNodeBlendTree::NodeConnection &E : node_connections) {
  822. StringName from = E.output_node;
  823. StringName to = E.input_node;
  824. int to_idx = E.input_index;
  825. graph->connect_node(from, 0, to, to_idx);
  826. }
  827. //update animations
  828. for (const KeyValue<StringName, ProgressBar *> &E : animations) {
  829. if (E.key == prev_name) {
  830. animations[new_name] = animations[prev_name];
  831. animations.erase(prev_name);
  832. break;
  833. }
  834. }
  835. update_graph(); // Needed to update the signal connections with the new name.
  836. }
  837. void AnimationNodeBlendTreeEditor::_node_renamed_focus_out(Node *le, Ref<AnimationNode> p_node) {
  838. if (le == nullptr) {
  839. return; // The text_submitted signal triggered the graph update and freed the LineEdit.
  840. }
  841. _node_renamed(le->call("get_text"), p_node);
  842. }
  843. bool AnimationNodeBlendTreeEditor::can_edit(const Ref<AnimationNode> &p_node) {
  844. Ref<AnimationNodeBlendTree> bt = p_node;
  845. return bt.is_valid();
  846. }
  847. void AnimationNodeBlendTreeEditor::edit(const Ref<AnimationNode> &p_node) {
  848. if (blend_tree.is_valid()) {
  849. blend_tree->disconnect("node_changed", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_changed));
  850. blend_tree->disconnect("removed_from_graph", callable_mp(this, &AnimationNodeBlendTreeEditor::_removed_from_graph));
  851. }
  852. blend_tree = p_node;
  853. read_only = false;
  854. if (blend_tree.is_null()) {
  855. hide();
  856. } else {
  857. read_only = EditorNode::get_singleton()->is_resource_read_only(blend_tree);
  858. blend_tree->connect("node_changed", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_changed));
  859. blend_tree->connect("removed_from_graph", callable_mp(this, &AnimationNodeBlendTreeEditor::_removed_from_graph));
  860. update_graph();
  861. }
  862. add_node->set_disabled(read_only);
  863. graph->set_arrange_nodes_button_hidden(read_only);
  864. }
  865. AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() {
  866. singleton = this;
  867. updating = false;
  868. use_position_from_popup_menu = false;
  869. graph = memnew(GraphEdit);
  870. add_child(graph);
  871. graph->add_valid_right_disconnect_type(0);
  872. graph->add_valid_left_disconnect_type(0);
  873. graph->set_v_size_flags(SIZE_EXPAND_FILL);
  874. graph->connect("connection_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_connection_request), CONNECT_DEFERRED);
  875. graph->connect("disconnection_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_disconnection_request), CONNECT_DEFERRED);
  876. graph->connect("node_selected", callable_mp(this, &AnimationNodeBlendTreeEditor::_node_selected));
  877. graph->connect("scroll_offset_changed", callable_mp(this, &AnimationNodeBlendTreeEditor::_scroll_changed));
  878. graph->connect("delete_nodes_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_delete_nodes_request));
  879. graph->connect("popup_request", callable_mp(this, &AnimationNodeBlendTreeEditor::_popup_request));
  880. graph->connect("connection_to_empty", callable_mp(this, &AnimationNodeBlendTreeEditor::_connection_to_empty));
  881. graph->connect("connection_from_empty", callable_mp(this, &AnimationNodeBlendTreeEditor::_connection_from_empty));
  882. float graph_minimap_opacity = EDITOR_GET("editors/visual_editors/minimap_opacity");
  883. graph->set_minimap_opacity(graph_minimap_opacity);
  884. float graph_lines_curvature = EDITOR_GET("editors/visual_editors/lines_curvature");
  885. graph->set_connection_lines_curvature(graph_lines_curvature);
  886. VSeparator *vs = memnew(VSeparator);
  887. graph->get_zoom_hbox()->add_child(vs);
  888. graph->get_zoom_hbox()->move_child(vs, 0);
  889. add_node = memnew(MenuButton);
  890. graph->get_zoom_hbox()->add_child(add_node);
  891. add_node->set_text(TTR("Add Node..."));
  892. graph->get_zoom_hbox()->move_child(add_node, 0);
  893. add_node->get_popup()->connect("id_pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_add_node));
  894. add_node->connect("about_to_popup", callable_mp(this, &AnimationNodeBlendTreeEditor::_update_options_menu).bind(false));
  895. add_node->set_disabled(read_only);
  896. add_options.push_back(AddOption("Animation", "AnimationNodeAnimation"));
  897. add_options.push_back(AddOption("OneShot", "AnimationNodeOneShot", 2));
  898. add_options.push_back(AddOption("Add2", "AnimationNodeAdd2", 2));
  899. add_options.push_back(AddOption("Add3", "AnimationNodeAdd3", 3));
  900. add_options.push_back(AddOption("Blend2", "AnimationNodeBlend2", 2));
  901. add_options.push_back(AddOption("Blend3", "AnimationNodeBlend3", 3));
  902. add_options.push_back(AddOption("Seek", "AnimationNodeTimeSeek", 1));
  903. add_options.push_back(AddOption("TimeScale", "AnimationNodeTimeScale", 1));
  904. add_options.push_back(AddOption("Transition", "AnimationNodeTransition"));
  905. add_options.push_back(AddOption("BlendTree", "AnimationNodeBlendTree"));
  906. add_options.push_back(AddOption("BlendSpace1D", "AnimationNodeBlendSpace1D"));
  907. add_options.push_back(AddOption("BlendSpace2D", "AnimationNodeBlendSpace2D"));
  908. add_options.push_back(AddOption("StateMachine", "AnimationNodeStateMachine"));
  909. _update_options_menu();
  910. error_panel = memnew(PanelContainer);
  911. add_child(error_panel);
  912. error_label = memnew(Label);
  913. error_panel->add_child(error_label);
  914. error_label->set_text("eh");
  915. filter_dialog = memnew(AcceptDialog);
  916. add_child(filter_dialog);
  917. filter_dialog->set_title(TTR("Edit Filtered Tracks:"));
  918. VBoxContainer *filter_vbox = memnew(VBoxContainer);
  919. filter_dialog->add_child(filter_vbox);
  920. filter_enabled = memnew(CheckBox);
  921. filter_enabled->set_text(TTR("Enable Filtering"));
  922. filter_enabled->connect("pressed", callable_mp(this, &AnimationNodeBlendTreeEditor::_filter_toggled));
  923. filter_vbox->add_child(filter_enabled);
  924. filters = memnew(Tree);
  925. filter_vbox->add_child(filters);
  926. filters->set_v_size_flags(SIZE_EXPAND_FILL);
  927. filters->set_hide_root(true);
  928. filters->connect("item_edited", callable_mp(this, &AnimationNodeBlendTreeEditor::_filter_edited));
  929. open_file = memnew(EditorFileDialog);
  930. add_child(open_file);
  931. open_file->set_title(TTR("Open Animation Node"));
  932. open_file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
  933. open_file->connect("file_selected", callable_mp(this, &AnimationNodeBlendTreeEditor::_file_opened));
  934. undo_redo = EditorNode::get_undo_redo();
  935. }