animation_blend_space_2d_editor.cpp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. /*************************************************************************/
  2. /* animation_blend_space_2d_editor.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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_space_2d_editor.h"
  31. #include "core/io/resource_loader.h"
  32. #include "core/math/delaunay.h"
  33. #include "core/os/input.h"
  34. #include "core/os/keyboard.h"
  35. #include "core/project_settings.h"
  36. #include "scene/animation/animation_blend_tree.h"
  37. #include "scene/animation/animation_player.h"
  38. #include "scene/gui/menu_button.h"
  39. #include "scene/gui/panel.h"
  40. #include "scene/main/viewport.h"
  41. bool AnimationNodeBlendSpace2DEditor::can_edit(const Ref<AnimationNode> &p_node) {
  42. Ref<AnimationNodeBlendSpace2D> bs2d = p_node;
  43. return bs2d.is_valid();
  44. }
  45. void AnimationNodeBlendSpace2DEditor::edit(const Ref<AnimationNode> &p_node) {
  46. blend_space = p_node;
  47. if (!blend_space.is_null()) {
  48. _update_space();
  49. }
  50. }
  51. StringName AnimationNodeBlendSpace2DEditor::get_blend_position_path() const {
  52. StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + "blend_position";
  53. return path;
  54. }
  55. void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEvent> &p_event) {
  56. Ref<InputEventKey> k = p_event;
  57. if (tool_select->is_pressed() && k.is_valid() && k->is_pressed() && k->get_scancode() == KEY_DELETE && !k->is_echo()) {
  58. if (selected_point != -1 || selected_triangle != -1) {
  59. _erase_selected();
  60. accept_event();
  61. }
  62. }
  63. Ref<InputEventMouseButton> mb = p_event;
  64. if (mb.is_valid() && mb->is_pressed() && ((tool_select->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) || (mb->get_button_index() == BUTTON_LEFT && tool_create->is_pressed()))) {
  65. menu->clear();
  66. animations_menu->clear();
  67. animations_to_add.clear();
  68. List<StringName> classes;
  69. classes.sort_custom<StringName::AlphCompare>();
  70. ClassDB::get_inheriters_from_class("AnimationRootNode", &classes);
  71. menu->add_submenu_item(TTR("Add Animation"), "animations");
  72. AnimationTree *gp = AnimationTreeEditor::get_singleton()->get_tree();
  73. ERR_FAIL_COND(!gp);
  74. if (gp && gp->has_node(gp->get_animation_player())) {
  75. AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(gp->get_node(gp->get_animation_player()));
  76. if (ap) {
  77. List<StringName> names;
  78. ap->get_animation_list(&names);
  79. for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
  80. animations_menu->add_icon_item(get_icon("Animation", "EditorIcons"), E->get());
  81. animations_to_add.push_back(E->get());
  82. }
  83. }
  84. }
  85. for (List<StringName>::Element *E = classes.front(); E; E = E->next()) {
  86. String name = String(E->get()).replace_first("AnimationNode", "");
  87. if (name == "Animation")
  88. continue; // nope
  89. int idx = menu->get_item_count();
  90. menu->add_item(vformat("Add %s", name), idx);
  91. menu->set_item_metadata(idx, E->get());
  92. }
  93. Ref<AnimationNode> clipb = EditorSettings::get_singleton()->get_resource_clipboard();
  94. if (clipb.is_valid()) {
  95. menu->add_separator();
  96. menu->add_item(TTR("Paste"), MENU_PASTE);
  97. }
  98. menu->add_separator();
  99. menu->add_item(TTR("Load.."), MENU_LOAD_FILE);
  100. menu->set_global_position(blend_space_draw->get_global_transform().xform(mb->get_position()));
  101. menu->popup();
  102. add_point_pos = (mb->get_position() / blend_space_draw->get_size());
  103. add_point_pos.y = 1.0 - add_point_pos.y;
  104. add_point_pos *= (blend_space->get_max_space() - blend_space->get_min_space());
  105. add_point_pos += blend_space->get_min_space();
  106. if (snap->is_pressed()) {
  107. add_point_pos.x = Math::stepify(add_point_pos.x, blend_space->get_snap().x);
  108. add_point_pos.y = Math::stepify(add_point_pos.y, blend_space->get_snap().y);
  109. }
  110. }
  111. if (mb.is_valid() && mb->is_pressed() && tool_select->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  112. blend_space_draw->update(); //update anyway
  113. //try to see if a point can be selected
  114. selected_point = -1;
  115. selected_triangle = -1;
  116. _update_tool_erase();
  117. for (int i = 0; i < points.size(); i++) {
  118. if (points[i].distance_to(mb->get_position()) < 10 * EDSCALE) {
  119. selected_point = i;
  120. Ref<AnimationNode> node = blend_space->get_blend_point_node(i);
  121. EditorNode::get_singleton()->push_item(node.ptr(), "", true);
  122. dragging_selected_attempt = true;
  123. drag_from = mb->get_position();
  124. _update_tool_erase();
  125. _update_edited_point_pos();
  126. return;
  127. }
  128. }
  129. //then try to see if a triangle can be selected
  130. if (!blend_space->get_auto_triangles()) { //if autotriangles use, disable this
  131. for (int i = 0; i < blend_space->get_triangle_count(); i++) {
  132. Vector<Vector2> triangle;
  133. for (int j = 0; j < 3; j++) {
  134. int idx = blend_space->get_triangle_point(i, j);
  135. ERR_FAIL_INDEX(idx, points.size());
  136. triangle.push_back(points[idx]);
  137. }
  138. if (Geometry::is_point_in_triangle(mb->get_position(), triangle[0], triangle[1], triangle[2])) {
  139. selected_triangle = i;
  140. _update_tool_erase();
  141. return;
  142. }
  143. }
  144. }
  145. }
  146. if (mb.is_valid() && mb->is_pressed() && tool_triangle->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  147. blend_space_draw->update(); //update anyway
  148. //try to see if a point can be selected
  149. selected_point = -1;
  150. for (int i = 0; i < points.size(); i++) {
  151. if (making_triangle.find(i) != -1)
  152. continue;
  153. if (points[i].distance_to(mb->get_position()) < 10 * EDSCALE) {
  154. making_triangle.push_back(i);
  155. if (making_triangle.size() == 3) {
  156. //add triangle!
  157. if (blend_space->has_triangle(making_triangle[0], making_triangle[1], making_triangle[2])) {
  158. making_triangle.clear();
  159. EditorNode::get_singleton()->show_warning(TTR("Triangle already exists"));
  160. return;
  161. }
  162. updating = true;
  163. undo_redo->create_action("Add Triangle");
  164. undo_redo->add_do_method(blend_space.ptr(), "add_triangle", making_triangle[0], making_triangle[1], making_triangle[2]);
  165. undo_redo->add_undo_method(blend_space.ptr(), "remove_triangle", blend_space->get_triangle_count());
  166. undo_redo->add_do_method(this, "_update_space");
  167. undo_redo->add_undo_method(this, "_update_space");
  168. undo_redo->commit_action();
  169. updating = false;
  170. making_triangle.clear();
  171. }
  172. return;
  173. }
  174. }
  175. }
  176. if (mb.is_valid() && !mb->is_pressed() && dragging_selected_attempt && mb->get_button_index() == BUTTON_LEFT) {
  177. if (dragging_selected) {
  178. //move
  179. Vector2 point = blend_space->get_blend_point_position(selected_point);
  180. point += drag_ofs;
  181. if (snap->is_pressed()) {
  182. point.x = Math::stepify(point.x, blend_space->get_snap().x);
  183. point.y = Math::stepify(point.y, blend_space->get_snap().y);
  184. }
  185. updating = true;
  186. undo_redo->create_action("Move Node Point");
  187. undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_position", selected_point, point);
  188. undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_position", selected_point, blend_space->get_blend_point_position(selected_point));
  189. undo_redo->add_do_method(this, "_update_space");
  190. undo_redo->add_undo_method(this, "_update_space");
  191. undo_redo->add_do_method(this, "_update_edited_point_pos");
  192. undo_redo->add_undo_method(this, "_update_edited_point_pos");
  193. undo_redo->commit_action();
  194. updating = false;
  195. _update_edited_point_pos();
  196. }
  197. dragging_selected_attempt = false;
  198. dragging_selected = false;
  199. blend_space_draw->update();
  200. }
  201. if (mb.is_valid() && mb->is_pressed() && tool_blend->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  202. Vector2 blend_pos = (mb->get_position() / blend_space_draw->get_size());
  203. blend_pos.y = 1.0 - blend_pos.y;
  204. blend_pos *= (blend_space->get_max_space() - blend_space->get_min_space());
  205. blend_pos += blend_space->get_min_space();
  206. AnimationTreeEditor::get_singleton()->get_tree()->set(get_blend_position_path(), blend_pos);
  207. blend_space_draw->update();
  208. }
  209. Ref<InputEventMouseMotion> mm = p_event;
  210. if (mm.is_valid() && !blend_space_draw->has_focus()) {
  211. blend_space_draw->grab_focus();
  212. blend_space_draw->update();
  213. }
  214. if (mm.is_valid() && dragging_selected_attempt) {
  215. dragging_selected = true;
  216. drag_ofs = ((mm->get_position() - drag_from) / blend_space_draw->get_size()) * (blend_space->get_max_space() - blend_space->get_min_space()) * Vector2(1, -1);
  217. blend_space_draw->update();
  218. _update_edited_point_pos();
  219. }
  220. if (mm.is_valid() && tool_triangle->is_pressed() && making_triangle.size()) {
  221. blend_space_draw->update();
  222. }
  223. if (mm.is_valid() && !tool_triangle->is_pressed() && making_triangle.size()) {
  224. making_triangle.clear();
  225. blend_space_draw->update();
  226. }
  227. if (mm.is_valid() && tool_blend->is_pressed() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
  228. Vector2 blend_pos = (mm->get_position() / blend_space_draw->get_size());
  229. blend_pos.y = 1.0 - blend_pos.y;
  230. blend_pos *= (blend_space->get_max_space() - blend_space->get_min_space());
  231. blend_pos += blend_space->get_min_space();
  232. AnimationTreeEditor::get_singleton()->get_tree()->set(get_blend_position_path(), blend_pos);
  233. blend_space_draw->update();
  234. }
  235. }
  236. void AnimationNodeBlendSpace2DEditor::_file_opened(const String &p_file) {
  237. file_loaded = ResourceLoader::load(p_file);
  238. if (file_loaded.is_valid()) {
  239. _add_menu_type(MENU_LOAD_FILE_CONFIRM);
  240. }
  241. }
  242. void AnimationNodeBlendSpace2DEditor::_add_menu_type(int p_index) {
  243. Ref<AnimationRootNode> node;
  244. if (p_index == MENU_LOAD_FILE) {
  245. open_file->clear_filters();
  246. List<String> filters;
  247. ResourceLoader::get_recognized_extensions_for_type("AnimationRootNode", &filters);
  248. for (List<String>::Element *E = filters.front(); E; E = E->next()) {
  249. open_file->add_filter("*." + E->get());
  250. }
  251. open_file->popup_centered_ratio();
  252. return;
  253. } else if (p_index == MENU_LOAD_FILE_CONFIRM) {
  254. node = file_loaded;
  255. file_loaded.unref();
  256. } else if (p_index == MENU_PASTE) {
  257. node = EditorSettings::get_singleton()->get_resource_clipboard();
  258. } else {
  259. String type = menu->get_item_metadata(p_index);
  260. Object *obj = ClassDB::instance(type);
  261. ERR_FAIL_COND(!obj);
  262. AnimationNode *an = Object::cast_to<AnimationNode>(obj);
  263. ERR_FAIL_COND(!an);
  264. node = Ref<AnimationNode>(an);
  265. }
  266. if (!node.is_valid()) {
  267. EditorNode::get_singleton()->show_warning(TTR("This type of node can't be used. Only root nodes are allowed."));
  268. return;
  269. }
  270. updating = true;
  271. undo_redo->create_action("Add Node Point");
  272. undo_redo->add_do_method(blend_space.ptr(), "add_blend_point", node, add_point_pos);
  273. undo_redo->add_undo_method(blend_space.ptr(), "remove_blend_point", blend_space->get_blend_point_count());
  274. undo_redo->add_do_method(this, "_update_space");
  275. undo_redo->add_undo_method(this, "_update_space");
  276. undo_redo->commit_action();
  277. updating = false;
  278. blend_space_draw->update();
  279. }
  280. void AnimationNodeBlendSpace2DEditor::_add_animation_type(int p_index) {
  281. Ref<AnimationNodeAnimation> anim;
  282. anim.instance();
  283. anim->set_animation(animations_to_add[p_index]);
  284. updating = true;
  285. undo_redo->create_action("Add Animation Point");
  286. undo_redo->add_do_method(blend_space.ptr(), "add_blend_point", anim, add_point_pos);
  287. undo_redo->add_undo_method(blend_space.ptr(), "remove_blend_point", blend_space->get_blend_point_count());
  288. undo_redo->add_do_method(this, "_update_space");
  289. undo_redo->add_undo_method(this, "_update_space");
  290. undo_redo->commit_action();
  291. updating = false;
  292. blend_space_draw->update();
  293. }
  294. void AnimationNodeBlendSpace2DEditor::_update_tool_erase() {
  295. tool_erase->set_disabled(!(selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) && !(selected_triangle >= 0 && selected_triangle < blend_space->get_triangle_count()));
  296. if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) {
  297. Ref<AnimationNode> an = blend_space->get_blend_point_node(selected_point);
  298. if (AnimationTreeEditor::get_singleton()->can_edit(an)) {
  299. open_editor->show();
  300. } else {
  301. open_editor->hide();
  302. }
  303. edit_hb->show();
  304. } else {
  305. edit_hb->hide();
  306. }
  307. }
  308. void AnimationNodeBlendSpace2DEditor::_tool_switch(int p_tool) {
  309. making_triangle.clear();
  310. if (p_tool == 2) {
  311. Vector<Vector2> points;
  312. for (int i = 0; i < blend_space->get_blend_point_count(); i++) {
  313. points.push_back(blend_space->get_blend_point_position(i));
  314. }
  315. Vector<Delaunay2D::Triangle> tr = Delaunay2D::triangulate(points);
  316. for (int i = 0; i < tr.size(); i++) {
  317. blend_space->add_triangle(tr[i].points[0], tr[i].points[1], tr[i].points[2]);
  318. }
  319. }
  320. if (p_tool == 0) {
  321. tool_erase->show();
  322. tool_erase_sep->show();
  323. } else {
  324. tool_erase->hide();
  325. tool_erase_sep->hide();
  326. }
  327. _update_tool_erase();
  328. blend_space_draw->update();
  329. }
  330. void AnimationNodeBlendSpace2DEditor::_blend_space_draw() {
  331. Color linecolor = get_color("font_color", "Label");
  332. Color linecolor_soft = linecolor;
  333. linecolor_soft.a *= 0.5;
  334. Ref<Font> font = get_font("font", "Label");
  335. Ref<Texture> icon = get_icon("KeyValue", "EditorIcons");
  336. Ref<Texture> icon_selected = get_icon("KeySelected", "EditorIcons");
  337. Size2 s = blend_space_draw->get_size();
  338. if (blend_space_draw->has_focus()) {
  339. Color color = get_color("accent_color", "Editor");
  340. blend_space_draw->draw_rect(Rect2(Point2(), s), color, false);
  341. }
  342. blend_space_draw->draw_line(Point2(1, 0), Point2(1, s.height - 1), linecolor);
  343. blend_space_draw->draw_line(Point2(1, s.height - 1), Point2(s.width - 1, s.height - 1), linecolor);
  344. blend_space_draw->draw_line(Point2(0, 0), Point2(5 * EDSCALE, 0), linecolor);
  345. if (blend_space->get_min_space().y < 0) {
  346. int y = (blend_space->get_max_space().y / (blend_space->get_max_space().y - blend_space->get_min_space().y)) * s.height;
  347. blend_space_draw->draw_line(Point2(0, y), Point2(5 * EDSCALE, y), linecolor);
  348. blend_space_draw->draw_string(font, Point2(2 * EDSCALE, y - font->get_height() + font->get_ascent()), "0", linecolor);
  349. blend_space_draw->draw_line(Point2(5 * EDSCALE, y), Point2(s.width, y), linecolor_soft);
  350. }
  351. if (blend_space->get_min_space().x < 0) {
  352. int x = (-blend_space->get_min_space().x / (blend_space->get_max_space().x - blend_space->get_min_space().x)) * s.width;
  353. blend_space_draw->draw_line(Point2(x, s.height - 1), Point2(x, s.height - 5 * EDSCALE), linecolor);
  354. blend_space_draw->draw_string(font, Point2(x + 2 * EDSCALE, s.height - 2 * EDSCALE - font->get_height() + font->get_ascent()), "0", linecolor);
  355. blend_space_draw->draw_line(Point2(x, s.height - 5 * EDSCALE), Point2(x, 0), linecolor_soft);
  356. }
  357. if (snap->is_pressed()) {
  358. linecolor_soft.a = linecolor.a * 0.1;
  359. if (blend_space->get_snap().x > 0) {
  360. int prev_idx = 0;
  361. for (int i = 0; i < s.x; i++) {
  362. float v = blend_space->get_min_space().x + i * (blend_space->get_max_space().x - blend_space->get_min_space().x) / s.x;
  363. int idx = int(v / blend_space->get_snap().x);
  364. if (i > 0 && prev_idx != idx) {
  365. blend_space_draw->draw_line(Point2(i, 0), Point2(i, s.height), linecolor_soft);
  366. }
  367. prev_idx = idx;
  368. }
  369. }
  370. if (blend_space->get_snap().y > 0) {
  371. int prev_idx = 0;
  372. for (int i = 0; i < s.y; i++) {
  373. float v = blend_space->get_max_space().y - i * (blend_space->get_max_space().y - blend_space->get_min_space().y) / s.y;
  374. int idx = int(v / blend_space->get_snap().y);
  375. if (i > 0 && prev_idx != idx) {
  376. blend_space_draw->draw_line(Point2(0, i), Point2(s.width, i), linecolor_soft);
  377. }
  378. prev_idx = idx;
  379. }
  380. }
  381. }
  382. //triangles first
  383. for (int i = 0; i < blend_space->get_triangle_count(); i++) {
  384. Vector<Vector2> points;
  385. points.resize(3);
  386. for (int j = 0; j < 3; j++) {
  387. int point_idx = blend_space->get_triangle_point(i, j);
  388. Vector2 point = blend_space->get_blend_point_position(point_idx);
  389. if (dragging_selected && selected_point == point_idx) {
  390. point += drag_ofs;
  391. if (snap->is_pressed()) {
  392. point.x = Math::stepify(point.x, blend_space->get_snap().x);
  393. point.y = Math::stepify(point.y, blend_space->get_snap().y);
  394. }
  395. }
  396. point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
  397. point *= s;
  398. point.y = s.height - point.y;
  399. points.write[j] = point;
  400. }
  401. for (int j = 0; j < 3; j++) {
  402. blend_space_draw->draw_line(points[j], points[(j + 1) % 3], linecolor, 1, true);
  403. }
  404. Color color;
  405. if (i == selected_triangle) {
  406. color = get_color("accent_color", "Editor");
  407. color.a *= 0.5;
  408. } else {
  409. color = linecolor;
  410. color.a *= 0.2;
  411. }
  412. Vector<Color> colors;
  413. colors.push_back(color);
  414. colors.push_back(color);
  415. colors.push_back(color);
  416. blend_space_draw->draw_primitive(points, colors, Vector<Vector2>());
  417. }
  418. points.clear();
  419. for (int i = 0; i < blend_space->get_blend_point_count(); i++) {
  420. Vector2 point = blend_space->get_blend_point_position(i);
  421. if (dragging_selected && selected_point == i) {
  422. point += drag_ofs;
  423. if (snap->is_pressed()) {
  424. point.x = Math::stepify(point.x, blend_space->get_snap().x);
  425. point.y = Math::stepify(point.y, blend_space->get_snap().y);
  426. }
  427. }
  428. point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
  429. point *= s;
  430. point.y = s.height - point.y;
  431. points.push_back(point);
  432. point -= (icon->get_size() / 2);
  433. point = point.floor();
  434. if (i == selected_point) {
  435. blend_space_draw->draw_texture(icon_selected, point);
  436. } else {
  437. blend_space_draw->draw_texture(icon, point);
  438. }
  439. }
  440. if (making_triangle.size()) {
  441. Vector<Vector2> points;
  442. for (int i = 0; i < making_triangle.size(); i++) {
  443. Vector2 point = blend_space->get_blend_point_position(making_triangle[i]);
  444. point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
  445. point *= s;
  446. point.y = s.height - point.y;
  447. points.push_back(point);
  448. }
  449. for (int i = 0; i < points.size() - 1; i++) {
  450. blend_space_draw->draw_line(points[i], points[i + 1], linecolor, 2, true);
  451. }
  452. blend_space_draw->draw_line(points[points.size() - 1], blend_space_draw->get_local_mouse_position(), linecolor, 2, true);
  453. }
  454. ///draw cursor position
  455. {
  456. Color color;
  457. if (tool_blend->is_pressed()) {
  458. color = get_color("accent_color", "Editor");
  459. } else {
  460. color = linecolor;
  461. color.a *= 0.5;
  462. }
  463. Vector2 blend_pos = AnimationTreeEditor::get_singleton()->get_tree()->get(get_blend_position_path());
  464. Vector2 point = blend_pos;
  465. point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
  466. point *= s;
  467. point.y = s.height - point.y;
  468. if (blend_space->get_triangle_count()) {
  469. Vector2 closest = blend_space->get_closest_point(blend_pos);
  470. closest = (closest - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
  471. closest *= s;
  472. closest.y = s.height - closest.y;
  473. Color lcol = color;
  474. lcol.a *= 0.4;
  475. blend_space_draw->draw_line(point, closest, lcol, 2);
  476. }
  477. float mind = 5 * EDSCALE;
  478. float maxd = 15 * EDSCALE;
  479. blend_space_draw->draw_line(point + Vector2(mind, 0), point + Vector2(maxd, 0), color, 2);
  480. blend_space_draw->draw_line(point + Vector2(-mind, 0), point + Vector2(-maxd, 0), color, 2);
  481. blend_space_draw->draw_line(point + Vector2(0, mind), point + Vector2(0, maxd), color, 2);
  482. blend_space_draw->draw_line(point + Vector2(0, -mind), point + Vector2(0, -maxd), color, 2);
  483. }
  484. }
  485. void AnimationNodeBlendSpace2DEditor::_snap_toggled() {
  486. blend_space_draw->update();
  487. }
  488. void AnimationNodeBlendSpace2DEditor::_update_space() {
  489. if (updating)
  490. return;
  491. updating = true;
  492. if (blend_space->get_auto_triangles()) {
  493. tool_triangle->hide();
  494. } else {
  495. tool_triangle->show();
  496. }
  497. auto_triangles->set_pressed(blend_space->get_auto_triangles());
  498. interpolation->select(blend_space->get_blend_mode());
  499. max_x_value->set_value(blend_space->get_max_space().x);
  500. max_y_value->set_value(blend_space->get_max_space().y);
  501. min_x_value->set_value(blend_space->get_min_space().x);
  502. min_y_value->set_value(blend_space->get_min_space().y);
  503. label_x->set_text(blend_space->get_x_label());
  504. label_y->set_text(blend_space->get_y_label());
  505. snap_x->set_value(blend_space->get_snap().x);
  506. snap_y->set_value(blend_space->get_snap().y);
  507. blend_space_draw->update();
  508. updating = false;
  509. }
  510. void AnimationNodeBlendSpace2DEditor::_config_changed(double) {
  511. if (updating)
  512. return;
  513. updating = true;
  514. undo_redo->create_action("Change BlendSpace2D Limits");
  515. undo_redo->add_do_method(blend_space.ptr(), "set_max_space", Vector2(max_x_value->get_value(), max_y_value->get_value()));
  516. undo_redo->add_undo_method(blend_space.ptr(), "set_max_space", blend_space->get_max_space());
  517. undo_redo->add_do_method(blend_space.ptr(), "set_min_space", Vector2(min_x_value->get_value(), min_y_value->get_value()));
  518. undo_redo->add_undo_method(blend_space.ptr(), "set_min_space", blend_space->get_min_space());
  519. undo_redo->add_do_method(blend_space.ptr(), "set_snap", Vector2(snap_x->get_value(), snap_y->get_value()));
  520. undo_redo->add_undo_method(blend_space.ptr(), "set_snap", blend_space->get_snap());
  521. undo_redo->add_do_method(blend_space.ptr(), "set_blend_mode", interpolation->get_selected());
  522. undo_redo->add_undo_method(blend_space.ptr(), "set_blend_mode", blend_space->get_blend_mode());
  523. undo_redo->add_do_method(this, "_update_space");
  524. undo_redo->add_undo_method(this, "_update_space");
  525. undo_redo->commit_action();
  526. updating = false;
  527. blend_space_draw->update();
  528. }
  529. void AnimationNodeBlendSpace2DEditor::_labels_changed(String) {
  530. if (updating)
  531. return;
  532. updating = true;
  533. undo_redo->create_action("Change BlendSpace2D Labels", UndoRedo::MERGE_ENDS);
  534. undo_redo->add_do_method(blend_space.ptr(), "set_x_label", label_x->get_text());
  535. undo_redo->add_undo_method(blend_space.ptr(), "set_x_label", blend_space->get_x_label());
  536. undo_redo->add_do_method(blend_space.ptr(), "set_y_label", label_y->get_text());
  537. undo_redo->add_undo_method(blend_space.ptr(), "set_y_label", blend_space->get_y_label());
  538. undo_redo->add_do_method(this, "_update_space");
  539. undo_redo->add_undo_method(this, "_update_space");
  540. undo_redo->commit_action();
  541. updating = false;
  542. }
  543. void AnimationNodeBlendSpace2DEditor::_erase_selected() {
  544. if (selected_point != -1) {
  545. updating = true;
  546. undo_redo->create_action("Remove BlendSpace2D Point");
  547. undo_redo->add_do_method(blend_space.ptr(), "remove_blend_point", selected_point);
  548. undo_redo->add_undo_method(blend_space.ptr(), "add_blend_point", blend_space->get_blend_point_node(selected_point), blend_space->get_blend_point_position(selected_point), selected_point);
  549. //restore triangles using this point
  550. for (int i = 0; i < blend_space->get_triangle_count(); i++) {
  551. for (int j = 0; j < 3; j++) {
  552. if (blend_space->get_triangle_point(i, j) == selected_point) {
  553. undo_redo->add_undo_method(blend_space.ptr(), "add_triangle", blend_space->get_triangle_point(i, 0), blend_space->get_triangle_point(i, 1), blend_space->get_triangle_point(i, 2), i);
  554. break;
  555. }
  556. }
  557. }
  558. undo_redo->add_do_method(this, "_update_space");
  559. undo_redo->add_undo_method(this, "_update_space");
  560. undo_redo->commit_action();
  561. updating = false;
  562. blend_space_draw->update();
  563. } else if (selected_triangle != -1) {
  564. updating = true;
  565. undo_redo->create_action("Remove BlendSpace2D Triangle");
  566. undo_redo->add_do_method(blend_space.ptr(), "remove_triangle", selected_triangle);
  567. undo_redo->add_undo_method(blend_space.ptr(), "add_triangle", blend_space->get_triangle_point(selected_triangle, 0), blend_space->get_triangle_point(selected_triangle, 1), blend_space->get_triangle_point(selected_triangle, 2), selected_triangle);
  568. undo_redo->add_do_method(this, "_update_space");
  569. undo_redo->add_undo_method(this, "_update_space");
  570. undo_redo->commit_action();
  571. updating = false;
  572. blend_space_draw->update();
  573. }
  574. }
  575. void AnimationNodeBlendSpace2DEditor::_update_edited_point_pos() {
  576. if (updating)
  577. return;
  578. if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) {
  579. Vector2 pos = blend_space->get_blend_point_position(selected_point);
  580. if (dragging_selected) {
  581. pos += drag_ofs;
  582. if (snap->is_pressed()) {
  583. pos.x = Math::stepify(pos.x, blend_space->get_snap().x);
  584. pos.y = Math::stepify(pos.y, blend_space->get_snap().y);
  585. }
  586. }
  587. updating = true;
  588. edit_x->set_value(pos.x);
  589. edit_y->set_value(pos.y);
  590. updating = false;
  591. }
  592. }
  593. void AnimationNodeBlendSpace2DEditor::_edit_point_pos(double) {
  594. if (updating)
  595. return;
  596. updating = true;
  597. undo_redo->create_action("Move Node Point");
  598. undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_position", selected_point, Vector2(edit_x->get_value(), edit_y->get_value()));
  599. undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_position", selected_point, blend_space->get_blend_point_position(selected_point));
  600. undo_redo->add_do_method(this, "_update_space");
  601. undo_redo->add_undo_method(this, "_update_space");
  602. undo_redo->add_do_method(this, "_update_edited_point_pos");
  603. undo_redo->add_undo_method(this, "_update_edited_point_pos");
  604. undo_redo->commit_action();
  605. updating = false;
  606. blend_space_draw->update();
  607. }
  608. void AnimationNodeBlendSpace2DEditor::_notification(int p_what) {
  609. if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
  610. error_panel->add_style_override("panel", get_stylebox("bg", "Tree"));
  611. error_label->add_color_override("font_color", get_color("error_color", "Editor"));
  612. panel->add_style_override("panel", get_stylebox("bg", "Tree"));
  613. tool_blend->set_icon(get_icon("EditPivot", "EditorIcons"));
  614. tool_select->set_icon(get_icon("ToolSelect", "EditorIcons"));
  615. tool_create->set_icon(get_icon("EditKey", "EditorIcons"));
  616. tool_triangle->set_icon(get_icon("ToolTriangle", "EditorIcons"));
  617. tool_erase->set_icon(get_icon("Remove", "EditorIcons"));
  618. snap->set_icon(get_icon("SnapGrid", "EditorIcons"));
  619. open_editor->set_icon(get_icon("Edit", "EditorIcons"));
  620. auto_triangles->set_icon(get_icon("AutoTriangle", "EditorIcons"));
  621. interpolation->clear();
  622. interpolation->add_icon_item(get_icon("TrackContinuous", "EditorIcons"), "", 0);
  623. interpolation->add_icon_item(get_icon("TrackDiscrete", "EditorIcons"), "", 1);
  624. interpolation->add_icon_item(get_icon("TrackCapture", "EditorIcons"), "", 2);
  625. }
  626. if (p_what == NOTIFICATION_PROCESS) {
  627. String error;
  628. if (!AnimationTreeEditor::get_singleton()->get_tree()) {
  629. error = TTR("BlendSpace2D does not belong to an AnimationTree node.");
  630. } else if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) {
  631. error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails.");
  632. } else if (AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) {
  633. error = AnimationTreeEditor::get_singleton()->get_tree()->get_invalid_state_reason();
  634. } else if (blend_space->get_triangle_count() == 0) {
  635. error = TTR("No triangles exist, so no blending can take place.");
  636. }
  637. if (error != error_label->get_text()) {
  638. error_label->set_text(error);
  639. if (error != String()) {
  640. error_panel->show();
  641. } else {
  642. error_panel->hide();
  643. }
  644. }
  645. }
  646. if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
  647. set_process(is_visible_in_tree());
  648. }
  649. }
  650. void AnimationNodeBlendSpace2DEditor::_open_editor() {
  651. if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) {
  652. Ref<AnimationNode> an = blend_space->get_blend_point_node(selected_point);
  653. ERR_FAIL_COND(an.is_null());
  654. AnimationTreeEditor::get_singleton()->enter_editor(itos(selected_point));
  655. }
  656. }
  657. void AnimationNodeBlendSpace2DEditor::_removed_from_graph() {
  658. EditorNode::get_singleton()->edit_item(NULL);
  659. }
  660. void AnimationNodeBlendSpace2DEditor::_auto_triangles_toggled() {
  661. undo_redo->create_action("Toggle Auto Triangles");
  662. undo_redo->add_do_method(blend_space.ptr(), "set_auto_triangles", auto_triangles->is_pressed());
  663. undo_redo->add_undo_method(blend_space.ptr(), "set_auto_triangles", blend_space->get_auto_triangles());
  664. undo_redo->add_do_method(this, "_update_space");
  665. undo_redo->add_undo_method(this, "_update_space");
  666. undo_redo->commit_action();
  667. }
  668. void AnimationNodeBlendSpace2DEditor::_bind_methods() {
  669. ClassDB::bind_method("_blend_space_gui_input", &AnimationNodeBlendSpace2DEditor::_blend_space_gui_input);
  670. ClassDB::bind_method("_blend_space_draw", &AnimationNodeBlendSpace2DEditor::_blend_space_draw);
  671. ClassDB::bind_method("_config_changed", &AnimationNodeBlendSpace2DEditor::_config_changed);
  672. ClassDB::bind_method("_labels_changed", &AnimationNodeBlendSpace2DEditor::_labels_changed);
  673. ClassDB::bind_method("_update_space", &AnimationNodeBlendSpace2DEditor::_update_space);
  674. ClassDB::bind_method("_snap_toggled", &AnimationNodeBlendSpace2DEditor::_snap_toggled);
  675. ClassDB::bind_method("_tool_switch", &AnimationNodeBlendSpace2DEditor::_tool_switch);
  676. ClassDB::bind_method("_erase_selected", &AnimationNodeBlendSpace2DEditor::_erase_selected);
  677. ClassDB::bind_method("_update_tool_erase", &AnimationNodeBlendSpace2DEditor::_update_tool_erase);
  678. ClassDB::bind_method("_edit_point_pos", &AnimationNodeBlendSpace2DEditor::_edit_point_pos);
  679. ClassDB::bind_method("_add_menu_type", &AnimationNodeBlendSpace2DEditor::_add_menu_type);
  680. ClassDB::bind_method("_add_animation_type", &AnimationNodeBlendSpace2DEditor::_add_animation_type);
  681. ClassDB::bind_method("_update_edited_point_pos", &AnimationNodeBlendSpace2DEditor::_update_edited_point_pos);
  682. ClassDB::bind_method("_open_editor", &AnimationNodeBlendSpace2DEditor::_open_editor);
  683. ClassDB::bind_method("_removed_from_graph", &AnimationNodeBlendSpace2DEditor::_removed_from_graph);
  684. ClassDB::bind_method("_auto_triangles_toggled", &AnimationNodeBlendSpace2DEditor::_auto_triangles_toggled);
  685. ClassDB::bind_method("_file_opened", &AnimationNodeBlendSpace2DEditor::_file_opened);
  686. }
  687. AnimationNodeBlendSpace2DEditor *AnimationNodeBlendSpace2DEditor::singleton = NULL;
  688. AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() {
  689. singleton = this;
  690. updating = false;
  691. HBoxContainer *top_hb = memnew(HBoxContainer);
  692. add_child(top_hb);
  693. Ref<ButtonGroup> bg;
  694. bg.instance();
  695. tool_blend = memnew(ToolButton);
  696. tool_blend->set_toggle_mode(true);
  697. tool_blend->set_button_group(bg);
  698. top_hb->add_child(tool_blend);
  699. tool_blend->set_pressed(true);
  700. tool_blend->set_tooltip(TTR("Set the blending position within the space"));
  701. tool_blend->connect("pressed", this, "_tool_switch", varray(3));
  702. tool_select = memnew(ToolButton);
  703. tool_select->set_toggle_mode(true);
  704. tool_select->set_button_group(bg);
  705. top_hb->add_child(tool_select);
  706. tool_select->set_tooltip(TTR("Select and move points, create points with RMB."));
  707. tool_select->connect("pressed", this, "_tool_switch", varray(0));
  708. tool_create = memnew(ToolButton);
  709. tool_create->set_toggle_mode(true);
  710. tool_create->set_button_group(bg);
  711. top_hb->add_child(tool_create);
  712. tool_create->set_tooltip(TTR("Create points."));
  713. tool_create->connect("pressed", this, "_tool_switch", varray(1));
  714. tool_triangle = memnew(ToolButton);
  715. tool_triangle->set_toggle_mode(true);
  716. tool_triangle->set_button_group(bg);
  717. top_hb->add_child(tool_triangle);
  718. tool_triangle->set_tooltip(TTR("Create triangles by connecting points."));
  719. tool_triangle->connect("pressed", this, "_tool_switch", varray(2));
  720. tool_erase_sep = memnew(VSeparator);
  721. top_hb->add_child(tool_erase_sep);
  722. tool_erase = memnew(ToolButton);
  723. top_hb->add_child(tool_erase);
  724. tool_erase->set_tooltip(TTR("Erase points and triangles."));
  725. tool_erase->connect("pressed", this, "_erase_selected");
  726. tool_erase->set_disabled(true);
  727. top_hb->add_child(memnew(VSeparator));
  728. auto_triangles = memnew(ToolButton);
  729. top_hb->add_child(auto_triangles);
  730. auto_triangles->connect("pressed", this, "_auto_triangles_toggled");
  731. auto_triangles->set_toggle_mode(true);
  732. auto_triangles->set_tooltip(TTR("Generate blend triangles automatically (instead of manually)"));
  733. top_hb->add_child(memnew(VSeparator));
  734. snap = memnew(ToolButton);
  735. snap->set_toggle_mode(true);
  736. top_hb->add_child(snap);
  737. snap->set_pressed(true);
  738. snap->set_tooltip(TTR("Enable snap and show grid."));
  739. snap->connect("pressed", this, "_snap_toggled");
  740. snap_x = memnew(SpinBox);
  741. top_hb->add_child(snap_x);
  742. snap_x->set_prefix("x:");
  743. snap_x->set_min(0.01);
  744. snap_x->set_step(0.01);
  745. snap_x->set_max(1000);
  746. snap_y = memnew(SpinBox);
  747. top_hb->add_child(snap_y);
  748. snap_y->set_prefix("y:");
  749. snap_y->set_min(0.01);
  750. snap_y->set_step(0.01);
  751. snap_y->set_max(1000);
  752. top_hb->add_child(memnew(VSeparator));
  753. top_hb->add_child(memnew(Label(TTR("Blend:"))));
  754. interpolation = memnew(OptionButton);
  755. top_hb->add_child(interpolation);
  756. interpolation->connect("item_selected", this, "_config_changed");
  757. edit_hb = memnew(HBoxContainer);
  758. top_hb->add_child(edit_hb);
  759. edit_hb->add_child(memnew(VSeparator));
  760. edit_hb->add_child(memnew(Label(TTR("Point"))));
  761. edit_x = memnew(SpinBox);
  762. edit_hb->add_child(edit_x);
  763. edit_x->set_min(-1000);
  764. edit_x->set_step(0.01);
  765. edit_x->set_max(1000);
  766. edit_x->connect("value_changed", this, "_edit_point_pos");
  767. edit_y = memnew(SpinBox);
  768. edit_hb->add_child(edit_y);
  769. edit_y->set_min(-1000);
  770. edit_y->set_step(0.01);
  771. edit_y->set_max(1000);
  772. edit_y->connect("value_changed", this, "_edit_point_pos");
  773. open_editor = memnew(Button);
  774. edit_hb->add_child(open_editor);
  775. open_editor->set_text(TTR("Open Editor"));
  776. open_editor->connect("pressed", this, "_open_editor", varray(), CONNECT_DEFERRED);
  777. edit_hb->hide();
  778. open_editor->hide();
  779. HBoxContainer *main_hb = memnew(HBoxContainer);
  780. add_child(main_hb);
  781. main_hb->set_v_size_flags(SIZE_EXPAND_FILL);
  782. GridContainer *main_grid = memnew(GridContainer);
  783. main_grid->set_columns(2);
  784. main_hb->add_child(main_grid);
  785. main_grid->set_h_size_flags(SIZE_EXPAND_FILL);
  786. {
  787. VBoxContainer *left_vbox = memnew(VBoxContainer);
  788. main_grid->add_child(left_vbox);
  789. left_vbox->set_v_size_flags(SIZE_EXPAND_FILL);
  790. max_y_value = memnew(SpinBox);
  791. left_vbox->add_child(max_y_value);
  792. left_vbox->add_spacer();
  793. label_y = memnew(LineEdit);
  794. left_vbox->add_child(label_y);
  795. label_y->set_expand_to_text_length(true);
  796. left_vbox->add_spacer();
  797. min_y_value = memnew(SpinBox);
  798. left_vbox->add_child(min_y_value);
  799. max_y_value->set_max(10000);
  800. max_y_value->set_min(0.01);
  801. max_y_value->set_step(0.01);
  802. min_y_value->set_min(-10000);
  803. min_y_value->set_max(0);
  804. min_y_value->set_step(0.01);
  805. }
  806. panel = memnew(PanelContainer);
  807. panel->set_clip_contents(true);
  808. main_grid->add_child(panel);
  809. panel->set_h_size_flags(SIZE_EXPAND_FILL);
  810. blend_space_draw = memnew(Control);
  811. blend_space_draw->connect("gui_input", this, "_blend_space_gui_input");
  812. blend_space_draw->connect("draw", this, "_blend_space_draw");
  813. blend_space_draw->set_focus_mode(FOCUS_ALL);
  814. panel->add_child(blend_space_draw);
  815. main_grid->add_child(memnew(Control)); //empty bottom left
  816. {
  817. HBoxContainer *bottom_vbox = memnew(HBoxContainer);
  818. main_grid->add_child(bottom_vbox);
  819. bottom_vbox->set_h_size_flags(SIZE_EXPAND_FILL);
  820. min_x_value = memnew(SpinBox);
  821. bottom_vbox->add_child(min_x_value);
  822. bottom_vbox->add_spacer();
  823. label_x = memnew(LineEdit);
  824. bottom_vbox->add_child(label_x);
  825. label_x->set_expand_to_text_length(true);
  826. bottom_vbox->add_spacer();
  827. max_x_value = memnew(SpinBox);
  828. bottom_vbox->add_child(max_x_value);
  829. max_x_value->set_max(10000);
  830. max_x_value->set_min(0.01);
  831. max_x_value->set_step(0.01);
  832. min_x_value->set_min(-10000);
  833. min_x_value->set_max(0);
  834. min_x_value->set_step(0.01);
  835. }
  836. snap_x->connect("value_changed", this, "_config_changed");
  837. snap_y->connect("value_changed", this, "_config_changed");
  838. max_x_value->connect("value_changed", this, "_config_changed");
  839. min_x_value->connect("value_changed", this, "_config_changed");
  840. max_y_value->connect("value_changed", this, "_config_changed");
  841. min_y_value->connect("value_changed", this, "_config_changed");
  842. label_x->connect("text_changed", this, "_labels_changed");
  843. label_y->connect("text_changed", this, "_labels_changed");
  844. error_panel = memnew(PanelContainer);
  845. add_child(error_panel);
  846. error_label = memnew(Label);
  847. error_panel->add_child(error_label);
  848. error_label->set_text("eh");
  849. undo_redo = EditorNode::get_singleton()->get_undo_redo();
  850. set_custom_minimum_size(Size2(0, 300 * EDSCALE));
  851. menu = memnew(PopupMenu);
  852. add_child(menu);
  853. menu->connect("id_pressed", this, "_add_menu_type");
  854. animations_menu = memnew(PopupMenu);
  855. menu->add_child(animations_menu);
  856. animations_menu->set_name("animations");
  857. animations_menu->connect("index_pressed", this, "_add_animation_type");
  858. open_file = memnew(EditorFileDialog);
  859. add_child(open_file);
  860. open_file->set_title(TTR("Open Animation Node"));
  861. open_file->set_mode(EditorFileDialog::MODE_OPEN_FILE);
  862. open_file->connect("file_selected", this, "_file_opened");
  863. undo_redo = EditorNode::get_singleton()->get_undo_redo();
  864. selected_point = -1;
  865. selected_triangle = -1;
  866. dragging_selected = false;
  867. dragging_selected_attempt = false;
  868. }