animation_blend_tree_editor_plugin.cpp 40 KB

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